5 =head1 NAME $RCSfile: testclearcase.pl,v $
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Tue Apr 10 13:14:15 CDT 2007
27 $Date: 2011/01/09 01:01:32 $
33 Usage: testclearcase.pl: [-us|age] [-ve|rbose]
34 [-c|onfig <file>] [-b|ase] [-uc|m]
37 -v|erbose: Display progress output
38 -d|ebug: Display debug info
39 -us|age: Display usage
41 -c|onfig <file>: Config file (Default: testclearcase.conf)
42 -[no]b|ase: Perform base Clearcase tests (Default: base)
43 -[no]uc|m: Perform UCM Clearcase tests (Default: noucm)
44 -[no]clean: Cleanup after yourself (Default: clean)
46 if -ucm is specified then the following additional parameters should be set:
48 -username: Username to connect to Clearquest with (Can set CQ_USERNAME)
49 -password: Password to use to connect to Clearquest (CQ_PASSWORD)
50 -weburl: Web URL to use for enabling Clearcase -> Clearquest
51 connection (CQ_WEBURL - Do not specify the trailing
53 -database: Clearquest database to enable (CQ_DATABASE)
54 -dbset: Clearquest DBSet (CQ_DBSET)
55 -provider: Name of provider (Default: CQPROV)
59 Clearcase smoke tests. Perform simple Clearcase operations to validate that
60 Clearcase minimally works.
62 If -ucm is specified then additional UCM related tests are performed.
74 use lib "$FindBin::Bin/../lib";
77 use Clearcase::Element;
84 use Clearcase::UCM::Activity;
85 use Clearcase::UCM::Baseline;
86 use Clearcase::UCM::Component;
87 use Clearcase::UCM::Folder;
88 use Clearcase::UCM::Project;
89 use Clearcase::UCM::Pvob;
90 use Clearcase::UCM::Stream;
118 my (%default_opts, %opts);
120 my ($script) = ($FindBin::Script =~ /^(.*)\.pl/);
122 my $log = Logger->new;
124 # LogOpts: Log the %opts has to the log file so we can tell the options used for
128 "$script v$VERSION run at "
130 . ' with the following options:'
133 for (sort keys %opts) {
134 next if /help/ || /usage/ || /password/;
136 if (ref $opts{$_} eq 'ARRAY') {
140 $log->msg("$name:\t$_") if $_;
144 $log->msg("$_:\t$opts{$_}");
146 $log->msg("$_:\t<undef>");
157 my $vobname = Clearcase::vobname $tag;
159 $log->msg ("Creating vob $tag");
161 my $newvob = Clearcase::Vob->new($tag);
163 my ($status, @output) = $newvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs");
165 $log->log($_) for @output;
167 return ($status, $newvob);
173 my $vobname = Clearcase::vobname $tag;
175 my $pvob = Clearcase::UCM::Pvob->new($tag);
177 #my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs", 'A test Pvob');
178 my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs");
180 $log->log($_) for @output;
182 return ($status, $pvob);
188 $log->msg('Mounting vob ' . $vob->tag);
190 # Create mount directory
191 my ($status, @output);
193 ($status, @output) = Execute 'mkdir -p ' . $vob->tag . ' 2>&1' unless -d $vob->tag;
195 $log->log($_) for @output;
197 ($status, @output) = $vob->mount;
199 $log->log($_) for @output;
207 my ($status, @output);
209 ($status, @output) = $Clearcase::CC->execute('cd');
211 $log->err('Unable to perform cd command', 1) if $status;
213 $log->msg('Unmounting vob ' . $vob->tag);
215 ($status, @output) = $vob->umount;
218 $log->err('Unable to unmount vob ' . $vob->tag);
220 $log->msg('Umounted vob ' . $vob->tag);
223 $log->msg('Removing vob ' . $vob->tag);
225 ($status, @output) = $vob->remove;
228 $log->err("Failed to execute command " .
229 $Clearcase::CC->lastcmd . "\n" .
230 join "\t\n", @output);
233 $log->log($_) for @output;
241 $log->msg("Creating view $tag");
243 my $view = Clearcase::View->new($tag);
245 my ($status, @output) = $view->create($opts{viewhost}, "$opts{viewstore}/$tag.vws");
247 $log->log($_) for @output;
249 return ($status, $view);
255 $log->msg('Setting view ' . $view->tag);
257 my ($status, @output) = $view->set;
259 $log->log($_) for @output;
267 $log->msg('Stopping view ' . $view->tag);
269 my ($status, @output) = $view->stop;
271 $log->log($_) for @output;
279 $log->msg('Removing view ' . $view->tag);
281 my ($status, @output) = $Clearcase::CC->execute('cd');
283 $log->log($_) for @output;
286 or $log->err("Unable to chdir $ENV{HOME}", 1);
288 ($status, @output) = $view->remove;
290 $log->log($_) for @output;
295 sub CreateViewPrivateFiles(@) {
298 $log->msg('Creating test files');
303 $log->msg("Creating $_");
306 or $log->err("Unable to open $_ for writing - $!", 1);
308 print $file "This is file $_\n";
314 } # CreateViewPrivateFiles
319 my ($status, @output);
321 if (ref $element eq 'ARRAY') {
323 $log->msg("Checking out $_");
325 my $newElement = Clearcase::Element->new($_);
327 ($status, @output) = $newElement->checkout;
329 $log->log($_) for @output;
331 $log->err("Unable to check out $_", $status) if $status;
334 $log->msg("Checking out $element");
336 my $newElement = Clearcase::Element->new($element);
338 ($status, @output) = $newElement->checkout;
340 $log->log($_) for @output;
342 $log->err("Unable to check out $element", $status) if $status;
351 my ($status, @output);
353 if (ref $element eq 'ARRAY') {
355 $log->msg("Checking in $_");
357 my $newElement = Clearcase::Element->new($_);
359 ($status, @output) = $newElement->checkin;
361 $log->log($_) for @output;
363 $log->err("Unable to check in $_", $status) if $status;
366 $log->msg("Checking in $element");
368 my $newElement = Clearcase::Element->new($element);
370 ($status, @output) = $newElement->checkin;
372 $log->log($_) for @output;
374 $log->err("Unable to check in $element", $status) if $status;
380 sub ComparingFiles(@) {
384 my @lines = ReadFile $_;
386 $log->err("Element $_ should contain only two lines", 2) if scalar @lines != 2;
392 sub MakeElements(@) {
396 $log->msg("Mkelem $_");
398 my $newElement = Clearcase::Element->new($_);
400 my ($status, @output) = $newElement->mkelem;
402 $log->log($_) for @output;
404 $log->err("Unable to make $_ an element", $status) if $status;
413 # . Create a few elements
421 # . $vob_tag is already created
422 # . $view_tag is already created
423 # . View is set and we are in the vob
424 # . There are no vob elements for @elements
432 $log->msg("$script: Start Base Clearcase Tests");
433 $log->msg('Removing test files');
435 unlink $_ for @elements;
437 $log->msg('Creating view private files');
439 CreateViewPrivateFiles @elements;
441 $log->msg('Making elements');
444 MakeElements @elements;
448 $log->msg('Checking out files');
452 $log->msg('Modifying files');
454 CreateViewPrivateFiles @elements;
456 $log->msg('Checking in files');
460 $log->msg('Comparing files');
462 ComparingFiles @elements;
464 $log->msg("$script: End Base Clearcase Tests");
470 my ($view, $vob) = @_;
474 $log->msg('Cleaning up');
476 if ($view && $view->exists) {
477 $status += DestroyView($view);
480 if ($vob && $vob->exists) {
481 $status += DestroyVob($vob);
488 my ($rc, $status, @output);
490 $log->msg('Removing ' . $test_activity->name);
492 ($rc, @output) = $test_activity->remove;
496 $log->log($_) for @output;
498 # Need to remove baselines from streams first using rebase (Devstream)
499 $log->msg('Rebasing ' . $test_devstream->name . ' to remove baseline');
501 $status += RebaseStream(
503 ' -dbaseline ' . $test_baseline->name . '@' . $test_baseline->pvob->tag .
504 ' -view ' . $test_devview->name . ' -complete',
507 # Change intstream to not have a recommended baseline
508 $log->msg('Changing ' . $test_intstream->name . ' to remove recommended baseline');
510 ($rc, @output) = $test_intstream->nrecommended;
514 $log->log($_) for @output;
516 $status += DestroyView($test_devview);
518 $log->msg('Removing ' . $test_baseline->name);
520 ($rc, @output) = $test_baseline->remove;
524 $log->log($_) for @output;
526 $log->msg('Rebasing ' . $test_intstream->name . ' to remove INITIAL baseline');
528 $status += RebaseStream(
530 ' -dbaseline tc.component_INITIAL' . '@' . $test_intstream->pvob->tag .
531 ' -view ' . $test_intview->name . ' -complete',
534 $log->msg('Removing ' . $test_component->name . ' from ' . $test_project->name);
536 ($rc, @output) = $test_project->change(
537 '-dmodcomp ' . $test_component->name . '@' . $test_project->pvob->tag
542 $log->log($_) for @output;
544 $log->msg('Removing ' . $test_component->name);
546 ($rc, @output) = $test_component->remove;
550 $log->log($_) for @output;
552 $status += DestroyView($test_intview);
554 $log->msg('Removing '. $test_devstream->name);
556 ($rc, @output) = $test_devstream->remove;
560 $log->log($_) for @output;
562 $log->msg('Removing ' . $test_intstream->name);
564 ($rc, @output) = $test_intstream->remove;
568 $log->log($_) for @output;
570 $log->msg('Removing ' . $test_project->name);
572 ($rc, @output) = $test_project->remove;
576 $log->log($_) for @output;
578 $log->msg('Removing ' . $test_folder->name);
580 ($rc, @output) = $test_folder->remove;
584 $log->log($_) for @output;
586 $log->msg('Removing ' . $test_pvob->name);
588 ($rc, @output) = DestroyVob($test_pvob);
590 $log->log($_) for @output;
596 my ($vob_tag, $view_tag) = @_;
598 my ($status, @output);
600 $log->msg('Setup test environment');
602 my $view = Clearcase::View->new($view_tag);
605 $log->msg('Removing old view ' . $view_tag);
607 ($status, @output) = $view->remove;
609 $log->err('Unable to remove old view ' . $view->tag, $status) if $status;
612 ($status, $test_view) = CreateView($view_tag);
614 return $status if $status != 0;
616 $status = $test_view->start;
618 my $vob = Clearcase::Vob->new($vob_tag);
621 $log->msg('Removing old vob ' . $vob_tag);
623 ($status, @output) = DestroyVob($vob);
625 $log->err('Unable to remove old vob '. $vob->tag, $status) if $status;
628 ($status, $test_vob) = CreateVob($vob_tag);
630 return $status if $status != 0;
632 $status = MountVob($test_vob);
634 return $status if $status != 0;
636 my $dir = $Clearcase::VIEWTAG_PREFIX . '/' . $test_view->tag . $test_vob->tag;
639 or $log->err("Unable to chdir to $dir", ++$status);
641 ($status, @output) = $Clearcase::CC->execute("cd $dir");
643 $log->log($_) for @output;
648 sub SetupAttributeTypes() {
649 my @CC_CMI_Types = qw(CONTEXT TASK PROVIDERS);
651 my $status = SetView($test_intview);
653 return $status if $status;
655 for (@CC_CMI_Types) {
656 my $cmd = "mkattype -nc -vtype string CC_CMI_$_";
658 my ($rc, @output) = $Clearcase::CC->execute($cmd);
662 $log->log($_) for @output;
666 } # SetupAttributeTypes
669 my $cmd = "crmregister add -database $opts{database} -connection RDE "
670 . "-url $opts{weburl} -username $opts{username} "
671 . "-password $opts{password}";
673 my ($status, @output) = Execute $cmd;
675 $log->log($_) for @output;
680 sub MakeCMProvider() {
681 my $cmd = 'mkcmprovider -vob ' . $test_pvob->tag
682 . '-type cmcq -version V1_0 -description '
683 . '"RDE CMI CQ Provider" '
684 . '-connection baseurl:' . $opts{weburl} . " $opts{provider}";
686 my ($status, @output) = $Clearcase::CC->execute($cmd);
688 $log->log($_) for @output;
696 $log->msg("Register RDE://$opts{username}\@$opts{database}");
698 $status = CRMRegister;
700 $log->err("Unable to register RDE://$opts{username}\@$opts{database} - Check logfile", $status)
703 $log->msg("Creating UCM Pvob ${Clearcase::VOBTAG_PREFIX}tc.pvob");
705 ($status, $test_pvob) = CreatePvob("${Clearcase::VOBTAG_PREFIX}tc.pvob");
712 sub CreateUCMProject() {
713 # Get the root folder to put this project into (may create folders later)
714 $test_folder = Clearcase::UCM::Folder->new('tc.folder', $test_pvob);
716 $test_project = Clearcase::UCM::Project->new('tc.project', $test_folder, $test_pvob);
718 $test_project->remove if $test_project->exists;
720 $log->msg('Creating UCM Project tc.project');
722 my ($status, @output) = $test_project->create;
724 $log->log($_) for @output;
729 sub CreateUCMIntStream() {
730 $test_intstream = Clearcase::UCM::Stream->new('tc.intstream', $test_pvob);
732 $log->msg('Creating UCM Stream tc.intstream');
734 my ($status, @output) = $test_intstream->create($test_project, '-integration');
736 $log->log($_) for @output;
739 } # CreateUCMIntStream
741 sub CreateUCMDevStream() {
742 $test_devstream = Clearcase::UCM::Stream->new('tc.devstream', $test_pvob);
744 $log->msg('Creating UCM Stream tc.devstream');
746 my ($status, @output) = $test_devstream->create($test_project);
748 $log->log($_) for @output;
751 } # CreateUCMDevStream
753 sub CreateUCMComponent() {
754 $test_component = Clearcase::UCM::Component->new('tc.component', $test_pvob);
756 $log->msg('Creating UCM Component tc.component');
758 my ($status, @output) = $test_component->create(
759 "$Clearcase::VIEWTAG_PREFIX/" . $test_intview->tag . $test_vob->tag
762 $log->log($_) for @output;
765 } # CreateUCMComponent
767 sub AddModifiableComponent() {
768 my ($status, @output) = $Clearcase::CC->execute(
769 'chproj -nc -amodcomp ' . $test_component->name . '@' . $test_pvob->tag .
770 ' ' . $test_project->name . '@' . $test_pvob->tag
773 $log->log($_) for @output;
776 } # AddModifiableCOmponent
778 sub CreateUCMIntView() {
779 $log->msg("Creating UCM Int View tc.intview");
781 $test_intview = Clearcase::View->new('tc.intview');
783 my ($status, @output) = $test_intview->create(
784 $opts{viewhost}, "$opts{viewstore}/tc.intview.vws",
785 '-stream ' . $test_intstream->name . '@' . $test_pvob->tag
788 $log->log($_) for @output;
790 $test_intview->start unless $status;
795 sub CreateUCMDevView() {
796 $log->msg("Creating UCM Dev View tc.devview");
798 $test_devview = Clearcase::View->new('tc.devview');
800 my ($status, @output) = $test_devview->create(
801 $opts{viewhost}, "$opts{viewstore}/tc.devview.vws",
802 '-stream ' . $test_devstream->name . '@' . $test_pvob->tag
805 $log->log($_) for @output;
807 $test_devview->start unless $status;
812 sub CreateUCMBaseline() {
813 $test_baseline = Clearcase::UCM::Baseline->new('tc.baseline', $test_pvob);
815 $log->msg('Creating UCM Baseline tc.baseline');
817 my ($status, @output) = $test_baseline->create($test_intview, undef, '-identical');
819 $log->log($_) for @output;
822 } # CreateUCMBaseline
824 sub CreateUCMActivity() {
825 $test_activity = Clearcase::UCM::Activity->new('tc.activity', $test_pvob);
827 $log->msg('Creating UCM Activity tc.activity');
829 my ($status, @output) = $test_activity->create($test_devstream, 'A UCM Test Activity');
831 $log->log($_) for @output;
834 } # CreateUCMActivity
836 sub RebaseStream($$) {
837 my ($stream, $opts) = @_;
839 my ($status, @output) = $stream->rebase($opts);
841 $log->log($_) for @output;
846 sub RecommendBaseline($$) {
847 my ($stream, $baseline) = @_;
849 my ($status, @output) = $stream->recommend($baseline);
851 $log->log($_) for @output;
854 } # RecommentBaseline
859 $log->msg("$script: Start UCM Clearcase Tests");
861 $status += CreateUCMProject;
862 $status += CreateUCMIntStream;
863 $status += CreateUCMDevStream;
864 $status += CreateUCMIntView;
865 $status += SetupAttributeTypes;
866 $status += CreateUCMDevView;
867 $status += CreateUCMComponent;
868 $status += AddModifiableComponent;
869 $status += RebaseStream($test_intstream, '-baseline tc.component_INITIAL -complete');
870 $status += RecommendBaseline($test_intstream, 'tc.component_INITIAL');
871 $status += CreateUCMBaseline;
872 $status += RebaseStream($test_devstream, '-baseline tc.baseline -complete');
873 $status += RecommendBaseline($test_devstream, 'tc.baseline');
874 $status += CreateUCMActivity;
876 $log->msg("$script: End UCM Clearcase Tests");
882 my $startTime = time;
883 my $conf_file = "$FindBin::Bin/$script.conf";
886 $opts{help} = sub { pod2usage };
887 $opts{usage} = sub { pod2usage (-verbose => 2)};
890 $opts{username} = $ENV{CQ_USERNAME};
891 $opts{password} = $ENV{CQ_PASSWORD};
892 $opts{weburl} = $ENV{CQ_WEBURL};
894 $opts{weburl} .= $opts{weburl} ? "/oslc" : undef;
895 $opts{database} = $ENV{CQ_DATABASE};
896 $opts{dbset} = $ENV{CQ_DBSET};
897 $opts{provider} = $ENV{CQ_PROVIDER} || 'CQPROV';
901 'verbose' => sub { set_verbose },
902 'debug' => sub { set_debug },
903 'usage' => sub { Usage },
914 # Read the config file
916 %default_opts = GetConfig $conf_file;
918 $log->err("Unable to find config file $conf_file", 1);
921 # Overlay default opts if not specified
922 for (keys %default_opts) {
923 $opts{$_} = $default_opts{$_} if !$opts{$_};
926 # Check CQ parameters
928 for ('username', 'password', 'weburl', 'database', 'dbset', 'provider') {
929 pod2usage "In UCM mode you must specify -$_" unless $opts{$_};
933 $log->msg("$script: Start");
937 # Since we are creating private vobs (to avoid complications with having to
938 # know and code the registry password when making public vobs), we'll simply
939 # change $Clearcase::VOBTAG_PREFIX
940 if ($ARCHITECTURE !~ /win/i) {
941 $Clearcase::VOBTAG_PREFIX = $ENV{TMP} . '/' || '/tmp';
945 $status = SetupTest "${Clearcase::VOBTAG_PREFIX}tc.vob", 'tc.view';
950 $log->err('Tests not run. Failure occurred in SetupTest - check logfile');
953 # Note if we are doing UCM tests then we need the view and vob here...
954 $status += Cleanup($test_view, $test_vob) if $opts{clean} && !$opts{ucm};
957 $log->err("$script: Failed (Base Clearcase)");
959 $log->msg("$script: Passed (Base Clearcase)");
964 $status = SetupUCMTest;
967 $status += RunUCMTests;
969 $log->err('UCM Tests not run. Failure occurred in SetupUCMTest - check logfile');
973 $status += CleanupUCM;
974 $status += Cleanup($test_view, $test_vob);
978 $log->err("$script: Failed (UCM Clearcase)");
980 $log->msg("$script: Passed (UCM Clearcase)");
984 display_duration $startTime, $log;
986 $log->msg("$script: End");
992 =head1 CONFIGURATION AND ENVIRONMENT
994 DEBUG: If set then $debug is set to this level.
996 VERBOSE: If set then $verbose is set to this level.
998 TRACE: If set then $trace is set to this level.
1008 L<Getopt::Long|Getopt::Long>
1010 =head2 ClearSCM Perl Modules
1032 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a><br>
1033 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Element.pm">Element</a><br>
1034 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/View.pm">View</a><br>
1035 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Views.pm">Views</a><br>
1036 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Vob.pm">Vob</a><br>
1037 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Vobs.pm">Vobs</a><br>
1038 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM.pm">UCM</a><br>
1039 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Activity.pm">Activity</a><br>
1040 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Baseline</a><br>
1041 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Component.pm">Component</a><br>
1042 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Project.pm">Project</a><br>
1043 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Pvob.pm">Pvob</a><br>
1044 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Stream.pm">Stream</a><br>
1045 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
1046 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
1047 <a href="http://clearscm.com/php/scm_man.php?file=lib/GetConfig.pm">GetConfig</a><br>
1048 <a href="http://clearscm.com/php/scm_man.php?file=lib/Logger.pm">Logger</a><br>
1049 <a href="http://clearscm.com/php/scm_man.php?file=lib/OSDep.pm">OSDep</a><br>
1050 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
1055 =head1 BUGS AND LIMITATIONS
1057 There are no known bugs in this script
1059 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
1061 =head1 LICENSE AND COPYRIGHT
1063 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.