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)
48 Clearcase smoke tests. Perform simple Clearcase operations to validate that
49 Clearcase minimally works.
51 If -ucm is specified then additional UCM related tests are performed.
61 #use Term::ANSIColor qw(:constants);
63 use lib "$FindBin::Bin/../lib";
66 use Clearcase::Element;
73 use Clearcase::UCM::Activity;
74 use Clearcase::UCM::Baseline;
75 use Clearcase::UCM::Component;
76 use Clearcase::UCM::Folder;
77 use Clearcase::UCM::Project;
78 use Clearcase::UCM::Pvob;
79 use Clearcase::UCM::Stream;
107 my (%default_opts, %opts);
109 my ($script) = ($FindBin::Script =~ /^(.*)\.pl/);
111 my $log = Logger->new;
113 # LogOpts: Log the %opts has to the log file so we can tell the options used for
117 "$script v$VERSION run at "
119 . ' with the following options:'
122 for (sort keys %opts) {
123 if (ref $opts{$_} eq 'ARRAY') {
125 $log->msg("$name:\t$_") for @{$opts{$_}};
127 $log->msg("$_:\t$opts{$_}");
137 my $vobname = Clearcase::vobname $tag;
139 $log->msg ("Creating vob $tag");
141 my $newvob = Clearcase::Vob->new($tag);
143 my ($status, @output) = $newvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs");
145 $log->log($_) for @output;
147 return ($status, $newvob);
153 my $vobname = Clearcase::vobname $tag;
155 my $pvob = Clearcase::UCM::Pvob->new($tag);
157 #my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs", 'A test Pvob');
158 my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs");
160 $log->log($_) for @output;
162 return ($status, $pvob);
168 $log->msg('Mounting vob ' . $vob->tag);
170 # Create mount directory
171 my ($status, @output);
173 ($status, @output) = Execute 'mkdir -p ' . $vob->tag . ' 2>&1' unless -d $vob->tag;
175 $log->log($_) for @output;
177 ($status, @output) = $vob->mount;
179 $log->log($_) for @output;
187 my ($status, @output);
189 ($status, @output) = $Clearcase::CC->execute('cd');
191 $log->msg('Unmounting vob ' . $vob->tag);
193 ($status, @output) = $vob->umount;
195 $log->msg('Removing vob ' . $vob->tag);
197 ($status, @output) = $vob->remove;
199 $log->log($_) for @output;
207 $log->msg("Creating view $tag");
209 my $view = Clearcase::View->new($tag);
211 my ($status, @output) = $view->create($opts{viewhost}, "$opts{viewstore}/$tag.vws");
213 $log->log($_) for @output;
215 return ($status, $view);
221 $log->msg('Setting view ' . $view->tag);
223 my ($status, @output) = $view->set;
225 $log->log($_) for @output;
233 $log->msg('Removing view ' . $view->tag);
235 my ($status, @output) = $Clearcase::CC->execute('cd');
237 $log->log($_) for @output;
240 or $log->err("Unable to chdir $ENV{HOME}", 1);
242 ($status, @output) = $view->remove;
244 $log->log($_) for @output;
249 sub CreateViewPrivateFiles(@) {
252 $log->msg('Creating test files');
257 $log->msg("Creating $_");
260 or $log->err("Unable to open $_ for writing - $!", 1);
262 print $file "This is file $_\n";
268 } # CreateViewPrivateFiles
273 my ($status, @output);
275 if (ref $element eq 'ARRAY') {
277 $log->msg("Checking out $_");
279 my $newElement = Clearcase::Element->new($_);
281 ($status, @output) = $newElement->checkout;
283 $log->log($_) for @output;
285 $log->err("Unable to check out $_", $status) if $status;
288 $log->msg("Checking out $element");
290 my $newElement = Clearcase::Element->new($element);
292 ($status, @output) = $newElement->checkout;
294 $log->log($_) for @output;
296 $log->err("Unable to check out $element", $status) if $status;
305 my ($status, @output);
307 if (ref $element eq 'ARRAY') {
309 $log->msg("Checking in $_");
311 my $newElement = Clearcase::Element->new($_);
313 ($status, @output) = $newElement->checkin;
315 $log->log($_) for @output;
317 $log->err("Unable to check in $_", $status) if $status;
320 $log->msg("Checking in $element");
322 my $newElement = Clearcase::Element->new($element);
324 ($status, @output) = $newElement->checkin;
326 $log->log($_) for @output;
328 $log->err("Unable to check in $element", $status) if $status;
334 sub ComparingFiles(@) {
338 my @lines = ReadFile $_;
340 $log->err("Element $_ should contain only two lines", 2) if scalar @lines != 2;
346 sub MakeElements(@) {
350 $log->msg("Mkelem $_");
352 my $newElement = Clearcase::Element->new($_);
354 my ($status, @output) = $newElement->mkelem;
356 $log->log($_) for @output;
358 $log->err("Unable to make $_ an element", $status) if $status;
367 # . Create a few elements
375 # . $vob_tag is already created
376 # . $view_tag is already created
377 # . View is set and we are in the vob
378 # . There are no vob elements for @elements
386 $log->msg("$script: Start Base Clearcase Tests");
387 $log->msg('Removing test files');
389 unlink $_ for @elements;
391 $log->msg('Creating view private files');
393 CreateViewPrivateFiles @elements;
395 $log->msg('Making elements');
398 MakeElements @elements;
402 $log->msg('Checking out files');
406 $log->msg('Modifying files');
408 CreateViewPrivateFiles @elements;
410 $log->msg('Checking in files');
414 $log->msg('Comparing files');
416 ComparingFiles @elements;
418 $log->msg("$script: End Base Clearcase Tests");
424 my ($view, $vob) = @_;
428 $log->msg('Cleaning up');
430 if ($view && $view->exists) {
431 $status += DestroyView($view);
434 if ($vob && $vob->exists) {
435 $status += DestroyVob($vob);
442 my ($rc, $status, @output);
444 $log->msg('Removing ' . $test_activity->name);
446 ($rc, @output) = $test_activity->remove;
450 $log->log($_) for @output;
452 # Need to remove baselines from streams first using rebase (Devstream)
453 $log->msg('Rebasing ' . $test_devstream->name . ' to remove baseline');
455 $status += RebaseStream(
457 ' -dbaseline ' . $test_baseline->name . '@' . $test_baseline->pvob->tag .
458 ' -view ' . $test_devview->name . ' -complete',
461 # Change intstream to not have a recommended baseline
462 $log->msg('Changing ' . $test_intstream->name . ' to remove recommended baseline');
464 ($rc, @output) = $test_intstream->nrecommended;
468 $log->log($_) for @output;
470 $status += DestroyView($test_devview);
472 $log->msg('Removing ' . $test_baseline->name);
474 ($rc, @output) = $test_baseline->remove;
478 $log->log($_) for @output;
480 $log->msg('Rebasing ' . $test_intstream->name . ' to remove INITIAL baseline');
482 $status += RebaseStream(
484 ' -dbaseline tc.component_INITIAL' . '@' . $test_intstream->pvob->tag .
485 ' -view ' . $test_intview->name . ' -complete',
488 $log->msg('Removing ' . $test_component->name . ' from ' . $test_project->name);
490 ($rc, @output) = $test_project->change(
491 '-dmodcomp ' . $test_component->name . '@' . $test_project->pvob->tag
496 $log->log($_) for @output;
498 $log->msg('Removing ' . $test_component->name);
500 ($rc, @output) = $test_component->remove;
504 $log->log($_) for @output;
506 $status += DestroyView($test_intview);
508 $log->msg('Removing '. $test_devstream->name);
510 ($rc, @output) = $test_devstream->remove;
514 $log->log($_) for @output;
516 $log->msg('Removing ' . $test_intstream->name);
518 ($rc, @output) = $test_intstream->remove;
522 $log->log($_) for @output;
524 $log->msg('Removing ' . $test_project->name);
526 ($rc, @output) = $test_project->remove;
530 $log->log($_) for @output;
532 $log->msg('Removing ' . $test_folder->name);
534 ($rc, @output) = $test_folder->remove;
538 $log->log($_) for @output;
540 $log->msg('Removing ' . $test_pvob->name);
542 ($rc, @output) = DestroyVob($test_pvob);
544 $log->log($_) for @output;
550 my ($vob_tag, $view_tag) = @_;
552 my ($status, @output);
554 $log->msg('Setup test environment');
556 my $view = Clearcase::View->new($view_tag);
559 $log->msg('Removing old view ' . $view_tag);
561 ($status, @output) = $view->remove;
563 $log->err('Unable to remove old view ' . $view->tag, $status) if $status;
566 ($status, $test_view) = CreateView($view_tag);
568 return $status if $status != 0;
570 $status = $test_view->start;
572 my $vob = Clearcase::Vob->new($vob_tag);
575 $log->msg('Removing old vob ' . $vob_tag);
577 ($status, @output) = DestroyVob($vob);
579 $log->err('Unable to remove old vob '. $vob->tag, $status) if $status;
582 ($status, $test_vob) = CreateVob($vob_tag);
584 return $status if $status != 0;
586 $status = MountVob($test_vob);
588 return $status if $status != 0;
590 my $dir = $Clearcase::VIEWTAG_PREFIX . '/' . $test_view->tag . $test_vob->tag;
593 or $log->err("Unable to chdir to $dir", ++$status);
595 ($status, @output) = $Clearcase::CC->execute("cd $dir");
598 $log->log($_) for @output;
607 $log->msg("Creating UCM Pvob $Clearcase::VOBTAG_PREFIX/tc.pvob");
609 ($status, $test_pvob) = CreatePvob("$Clearcase::VOBTAG_PREFIX/tc.pvob");
614 sub CreateUCMProject() {
615 # Get the root folder to put this project into (may create folders later)
616 $test_folder = Clearcase::UCM::Folder->new('tc.folder', $test_pvob);
618 $test_project = Clearcase::UCM::Project->new('tc.project', $test_folder, $test_pvob);
620 $test_project->remove if $test_project->exists;
622 $log->msg('Creating UCM Project tc.project');
624 my ($status, @output) = $test_project->create;
626 $log->log($_) for @output;
631 sub CreateUCMIntStream() {
632 $test_intstream = Clearcase::UCM::Stream->new('tc.intstream', $test_pvob);
634 $log->msg('Creating UCM Stream tc.intstream');
636 my ($status, @output) = $test_intstream->create($test_project, '-integration');
638 $log->log($_) for @output;
641 } # CreateUCMIntStream
643 sub CreateUCMDevStream() {
644 $test_devstream = Clearcase::UCM::Stream->new('tc.devstream', $test_pvob);
646 $log->msg('Creating UCM Stream tc.devstream');
648 my ($status, @output) = $test_devstream->create($test_project);
650 $log->log($_) for @output;
653 } # CreateUCMDevStream
655 sub CreateUCMComponent() {
656 $test_component = Clearcase::UCM::Component->new('tc.component', $test_pvob);
658 $log->msg('Creating UCM Component tc.component');
660 my ($status, @output) = $test_component->create(
661 "$Clearcase::VIEWTAG_PREFIX/" . $test_intview->tag . $test_vob->tag
664 $log->log($_) for @output;
667 } # CreateUCMComponent
669 sub AddModifiableComponent() {
670 my ($status, @output) = $Clearcase::CC->execute(
671 'chproj -nc -amodcomp ' . $test_component->name . '@' . $test_pvob->tag .
672 ' ' . $test_project->name . '@' . $test_pvob->tag
675 $log->log($_) for @output;
678 } # AddModifiableCOmponent
680 sub CreateUCMIntView() {
681 $log->msg("Creating UCM Int View tc.intview");
683 $test_intview = Clearcase::View->new('tc.intview');
685 my ($status, @output) = $test_intview->create(
686 $opts{viewhost}, "$opts{viewstore}/tc.intview.vws",
687 '-stream ' . $test_intstream->name . '@' . $test_pvob->tag
690 $log->log($_) for @output;
692 $test_intview->start unless $status;
697 sub CreateUCMDevView() {
698 $log->msg("Creating UCM Dev View tc.devview");
700 $test_devview = Clearcase::View->new('tc.devview');
702 my ($status, @output) = $test_devview->create(
703 $opts{viewhost}, "$opts{viewstore}/tc.devview.vws",
704 '-stream ' . $test_devstream->name . '@' . $test_pvob->tag
707 $log->log($_) for @output;
709 $test_devview->start unless $status;
714 sub CreateUCMBaseline() {
715 $test_baseline = Clearcase::UCM::Baseline->new('tc.baseline', $test_pvob);
717 $log->msg('Creating UCM Baseline tc.baseline');
719 my ($status, @output) = $test_baseline->create($test_intview, undef, '-identical');
721 $log->log($_) for @output;
724 } # CreateUCMBaseline
726 sub CreateUCMActivity() {
727 $test_activity = Clearcase::UCM::Activity->new('tc.activity', $test_pvob);
729 $log->msg('Creating UCM Activity tc.activity');
731 my ($status, @output) = $test_activity->create($test_devstream, 'A UCM Test Activity');
733 $log->log($_) for @output;
736 } # CreateUCMActivity
738 sub RebaseStream($$) {
739 my ($stream, $opts) = @_;
741 my ($status, @output) = $stream->rebase($opts);
743 $log->log($_) for @output;
748 sub RecommendBaseline($$) {
749 my ($stream, $baseline) = @_;
751 my ($status, @output) = $stream->recommend($baseline);
753 $log->log($_) for @output;
756 } # RecommentBaseline
761 $log->msg("$script: Start UCM Clearcase Tests");
763 $status += CreateUCMProject;
764 $status += CreateUCMIntStream;
765 $status += CreateUCMDevStream;
766 $status += CreateUCMIntView;
767 $status += CreateUCMDevView;
768 $status += CreateUCMComponent;
769 $status += AddModifiableComponent;
770 $status += RebaseStream($test_intstream, '-baseline tc.component_INITIAL -complete');
771 $status += RecommendBaseline($test_intstream, 'tc.component_INITIAL');
772 $status += CreateUCMBaseline;
773 $status += RebaseStream($test_devstream, '-baseline tc.baseline -complete');
774 $status += RecommendBaseline($test_devstream, 'tc.baseline');
775 $status += CreateUCMActivity;
777 $log->msg("$script: End UCM Clearcase Tests");
783 my $startTime = time;
784 my $conf_file = "$FindBin::Bin/$script.conf";
792 'verbose' => sub { set_verbose },
793 'debug' => sub { set_debug },
794 'usage' => sub { Usage },
801 # Read the config file
803 %default_opts = GetConfig $conf_file;
805 $log->err("Unable to find config file $conf_file", 1);
808 # Overlay default opts if not specified
809 for (keys %default_opts) {
810 $opts{$_} = $default_opts{$_} if !$opts{$_};
813 $log->msg("$script: Start");
817 # Since we are creating private vobs (to avoid complications with having to
818 # know and code the registry password when making public vobs), we'll simply
819 # change $Clearcase::VOBTAG_PREFIX
820 $Clearcase::VOBTAG_PREFIX = $ENV{TMP} || '/tmp';
823 $status = SetupTest "$Clearcase::VOBTAG_PREFIX/tc.vob", 'tc.view';
828 $log->err('Tests not run. Failure occurred in SetupTest - check logfile');
831 # Note if we are doing UCM tests then we need the view and vob here...
832 $status += Cleanup($test_view, $test_vob) if $opts{clean} and !$opts{ucm};
835 $log->err("$script: Failed (Base Clearcase)");
837 $log->msg("$script: Passed (Base Clearcase)");
842 $status = SetupUCMTest;
845 $status += RunUCMTests;
847 $log->err('UCM Tests not run. Failure occurred in SetupUCMTest - check logfile');
851 $status += CleanupUCM;
852 $status += Cleanup($test_view, $test_vob);
856 $log->err("$script: Failed (UCM Clearcase)");
858 $log->msg("$script: Passed (UCM Clearcase)");
862 display_duration $startTime, $log;
864 $log->msg("$script: End");
870 =head1 CONFIGURATION AND ENVIRONMENT
872 DEBUG: If set then $debug is set to this level.
874 VERBOSE: If set then $verbose is set to this level.
876 TRACE: If set then $trace is set to this level.
886 L<Getopt::Long|Getopt::Long>
888 L<Term::ANSIColor|Term::ANSIColor>
890 =head2 ClearSCM Perl Modules
912 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a><br>
913 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Element.pm">Element</a><br>
914 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/View.pm">View</a><br>
915 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Views.pm">Views</a><br>
916 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Vob.pm">Vob</a><br>
917 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Vobs.pm">Vobs</a><br>
918 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM.pm">UCM</a><br>
919 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Activity.pm">Activity</a><br>
920 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Baseline</a><br>
921 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Component.pm">Component</a><br>
922 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Project.pm">Project</a><br>
923 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Pvob.pm">Pvob</a><br>
924 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Stream.pm">Stream</a><br>
925 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
926 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
927 <a href="http://clearscm.com/php/scm_man.php?file=lib/GetConfig.pm">GetConfig</a><br>
928 <a href="http://clearscm.com/php/scm_man.php?file=lib/Logger.pm">Logger</a><br>
929 <a href="http://clearscm.com/php/scm_man.php?file=lib/OSDep.pm">OSDep</a><br>
930 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
935 =head1 BUGS AND LIMITATIONS
937 There are no known bugs in this script
939 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
941 =head1 LICENSE AND COPYRIGHT
943 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.