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;
92 my (@ucmobjs, $order);
109 my ($vbs, $vws, %default_opts, %opts);
111 my ($script) = ($FindBin::Script =~ /^(.*)\.pl/);
113 my $log = Logger->new;
115 # LogOpts: Log the %opts has to the log file so we can tell the options used for
119 "$script v$VERSION run at "
121 . ' with the following options:'
124 for (sort keys %opts) {
125 if (ref $opts{$_} eq 'ARRAY') {
127 $log->msg("$name:\t$_") for (@{$opts{$_}});
129 $log->msg("$_:\t$opts{$_}");
139 my $vobname = Clearcase::vobname $tag;
141 $log->msg ("Creating vob $tag");
143 my $newvob = Clearcase::Vob->new($tag);
145 my ($status, @output) = $newvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs");
147 $log->log($_) for (@output);
149 return ($status, $newvob);
155 my $vobname = Clearcase::vobname $tag;
157 my $pvob = Clearcase::UCM::Pvob->new($tag);
159 #my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs", 'A test Pvob');
160 my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs");
162 $log->log($_) for (@output);
164 push @ucmobjs, $pvob unless $status;
166 return ($status, $pvob);
172 $log->msg('Mounting vob ' . $vob->tag);
174 # Create mount directory
175 my ($status, @output);
177 ($status, @output) = Execute 'mkdir -p ' . $vob->tag . ' 2>&1' unless -d $vob->tag;
179 $log->log($_) for (@output);
181 ($status, @output) = $vob->mount;
183 $log->log($_) for (@output);
191 my ($status, @output);
193 ($status, @output) = $Clearcase::CC->execute('cd');
195 $log->msg('Unmounting vob ' . $vob->tag);
197 ($status, @output) = $vob->umount;
199 $log->msg('Removing vob ' . $vob->tag);
201 ($status, @output) = $vob->remove;
203 $log->log($_) for (@output);
211 $log->msg("Creating view $tag");
213 my $view = Clearcase::View->new($tag);
215 my ($status, @output) = $view->create($opts{viewhost}, "$opts{viewstore}/$tag.vws");
217 $log->log($_) for (@output);
219 return ($status, $view);
225 $log->msg('Setting view ' . $view->tag);
227 my ($status, @output) = $view->set;
229 $log->log($_) for (@output);
237 $log->msg('Removing view ' . $view->tag);
239 my ($status, @output) = $Clearcase::CC->execute('cd');
241 $log->log($_) for (@output);
244 or $log->err("Unable to chdir $ENV{HOME}", 1);
246 ($status, @output) = $view->remove;
248 $log->log($_) for (@output);
253 sub CreateViewPrivateFiles(@) {
256 $log->msg('Creating test files');
261 $log->msg("Creating $_");
264 or $log->err("Unable to open $_ for writing - $!", 1);
266 print $file "This is file $_\n";
272 } # CreateViewPrivateFiles
277 my ($status, @output);
279 if (ref $element eq 'ARRAY') {
281 $log->msg("Checking out $_");
283 my $newElement = Clearcase::Element->new($_);
285 ($status, @output) = $newElement->checkout;
287 $log->log($_) for (@output);
289 $log->err("Unable to check out $_", $status) if $status;
292 $log->msg("Checking out $element");
294 my $newElement = Clearcase::Element->new($element);
296 ($status, @output) = $newElement->checkout;
298 $log->log($_) for (@output);
300 $log->err("Unable to check out $element", $status) if $status;
309 my ($status, @output);
311 if (ref $element eq 'ARRAY') {
313 $log->msg("Checking in $_");
315 my $newElement = Clearcase::Element->new($_);
317 ($status, @output) = $newElement->checkin;
319 $log->log($_) for (@output);
321 $log->err("Unable to check in $_", $status) if $status;
324 $log->msg("Checking in $element");
326 my $newElement = Clearcase::Element->new($element);
328 ($status, @output) = $newElement->checkin;
330 $log->log($_) for (@output);
332 $log->err("Unable to check in $element", $status) if $status;
338 sub ComparingFiles(@) {
342 my @lines = ReadFile $_;
344 $log->err("Element $_ should contain only two lines", 2) if scalar @lines != 2;
350 sub MakeElements(@) {
354 $log->msg("Mkelem $_");
356 my $newElement = Clearcase::Element->new($_);
358 my ($status, @output) = $newElement->mkelem;
360 $log->log($_) for (@output);
362 $log->err("Unable to make $_ an element", $status) if $status;
371 # . Create a few elements
379 # . $vob_tag is already created
380 # . $view_tag is already created
381 # . View is set and we are in the vob
382 # . There are no vob elements for @elements
390 $log->msg("$script: Start Base Clearcase Tests");
391 $log->msg('Removing test files');
393 unlink $_ for (@elements);
395 $log->msg('Creating view private files');
397 CreateViewPrivateFiles @elements;
399 $log->msg('Making elements');
402 MakeElements @elements;
406 $log->msg('Checking out files');
410 $log->msg('Modifying files');
412 CreateViewPrivateFiles @elements;
414 $log->msg('Checking in files');
418 $log->msg('Comparing files');
420 ComparingFiles @elements;
422 $log->msg("$script: End Base Clearcase Tests");
428 my ($view, $vob) = @_;
432 $log->msg('Cleaning up');
434 if ($view && $view->exists) {
435 $status += DestroyView($view);
438 if ($vob && $vob->exists) {
439 $status += DestroyVob($vob);
448 # Need to remove UCM objects in the opposite order in which we created them
449 for (reverse @ucmobjs) {
452 if (ref $_ eq 'Clearcase::UCM::Pvob') {
453 $log->msg('Removing Pvob ' . $_->tag);
455 $status += DestroyVob $_;
457 $log->msg('Removing ' . ref ($_) . ' ' . $_->name);
459 ($rc, @output) = $_->remove;
469 my ($vob_tag, $view_tag) = @_;
471 my ($status, @output);
473 $log->msg('Setup test environment');
475 my $view = Clearcase::View->new($view_tag);
478 $log->msg('Removing old view ' . $view_tag);
480 ($status, @output) = $view->remove;
482 $log->err('Unable to remove old view ' . $view->tag, $status) if $status;
485 ($status, $test_view) = CreateView($view_tag);
487 return $status if $status != 0;
489 $status = $test_view->start;
491 my $vob = Clearcase::Vob->new($vob_tag);
494 $log->msg('Removing old vob ' . $vob_tag);
496 ($status, @output) = DestroyVob($vob);
498 $log->err('Unable to remove old vob '. $vob->tag, $status) if $status;
501 ($status, $test_vob) = CreateVob($vob_tag);
503 return $status if $status != 0;
505 $status = MountVob($test_vob);
507 return $status if $status != 0;
509 my $dir = $Clearcase::VIEWTAG_PREFIX . '/' . $test_view->tag . $test_vob->tag;
512 or $log->err("Unable to chdir to $dir", ++$status);
514 ($status, @output) = $Clearcase::CC->execute("cd $dir");
517 $log->log($_) for (@output);
526 $log->msg("Creating UCM Pvob $Clearcase::VOBTAG_PREFIX/tc.pvob");
528 ($status, $test_pvob) = CreatePvob("$Clearcase::VOBTAG_PREFIX/tc.pvob");
533 sub CreateUCMProject() {
534 # Get the root folder to put this project into (may create folders later)
535 my $folder = Clearcase::UCM::Folder->new('tc.folder', $test_pvob);
537 $test_project = Clearcase::UCM::Project->new('tc.project', $folder, $test_pvob);
539 $log->msg('Creating UCM Project tc.project');
541 my ($status, @output) = $test_project->create();
543 $log->log($_) for (@output);
545 push @ucmobjs, $test_project unless $status;
550 sub CreateUCMIntStream() {
551 $test_intstream = Clearcase::UCM::Stream->new('tc.intstream', $test_pvob);
553 $log->msg('Creating UCM Stream tc.intstream');
555 my ($status, @output) = $test_intstream->create($test_project, '-integration');
557 $log->log($_) for (@output);
559 push @ucmobjs, $test_intstream unless $status;
562 } # CreateUCMIntStream
564 sub CreateUCMDevStream() {
565 $test_devstream = Clearcase::UCM::Stream->new('tc.devstream', $test_pvob);
567 $log->msg('Creating UCM Stream tc.devstream');
569 my ($status, @output) = $test_devstream->create($test_project);
571 $log->log($_) for (@output);
573 push @ucmobjs, $test_devstream unless $status;
576 } # CreateUCMIntStream
578 sub CreateUCMComponent() {
579 $test_component = Clearcase::UCM::Component->new('tc.component', $test_pvob);
581 $log->msg('Creating UCM Component tc.component');
583 my ($status, @output) = $test_component->create(
584 "$Clearcase::VIEWTAG_PREFIX/" . $test_intview->tag . $test_vob->tag
587 $log->log($_) for (@output);
589 push @ucmobjs, $test_component unless $status;
592 } # CreateUCMComponent
594 sub AddModifiableComponent() {
595 my ($status, @output) = $Clearcase::CC->execute(
596 'chproj -nc -amodcomp ' . $test_component->name . '@' . $test_pvob->tag .
597 ' ' . $test_project->name . '@' . $test_pvob->tag
600 $log->log($_) for (@output);
603 } # AddModifiableCOmponent
605 sub CreateUCMIntView() {
606 $log->msg("Creating UCM Int View tc.intview");
608 $test_intview = Clearcase::View->new('tc.intview');
610 my ($status, @output) = $test_intview->create(
611 $opts{viewhost}, "$opts{viewstore}/tc.intview.vws",
612 '-stream ' . $test_intstream->name . '@' . $test_pvob->tag
615 $log->log($_) for (@output);
617 push @ucmobjs, $test_intview unless $status;
619 $test_intview->start unless $status;
624 sub CreateUCMDevView() {
625 $log->msg("Creating UCM Dev View tc.devview");
627 $test_devview = Clearcase::View->new('tc.devview');
629 my ($status, @output) = $test_devview->create(
630 $opts{viewhost}, "$opts{viewstore}/tc.devview.vws",
631 '-stream ' . $test_devstream->name . '@' . $test_pvob->tag
634 $log->log($_) for (@output);
636 push @ucmobjs, $test_devview unless $status;
638 $test_devview->start unless $status;
643 sub CreateUCMBaseline() {
644 $test_baseline = Clearcase::UCM::Baseline->new('tc.baseline', $test_pvob);
646 $log->msg('Creating UCM Baseline tc.baseline');
648 my ($status, @output) = $test_baseline->create($test_intview, undef, '-identical');
650 $log->log($_) for (@output);
652 push @ucmobjs, $test_baseline unless $status;
655 } # CreateUCMBaseline
657 sub CreateUCMActivity() {
658 $test_activity = Clearcase::UCM::Activity->new('tc.activity', $test_pvob);
660 $log->msg('Creating UCM Activity tc.activity');
662 my ($status, @output) = $test_activity->create($test_devstream, 'A UCM Test Activity');
664 $log->log($_) for (@output);
666 push @ucmobjs, $test_activity unless $status;
669 } # CreateUCMActivity
671 sub RebaseStream($$;$) {
672 my ($stream, $baseline, $opts) = @_;
674 my ($status, @output) = $stream->rebase($baseline, $opts);
676 $log->log($_) for (@output);
681 sub RecommendBaseline($) {
684 my ($status, @output) = $test_intstream->recommend($baseline);
686 $log->log($_) for (@output);
689 } # RecommentBaseline
694 $log->msg("$script: Start UCM Clearcase Tests");
696 $status += CreateUCMProject;
697 $status += CreateUCMIntStream;
698 $status += CreateUCMDevStream;
699 $status += CreateUCMIntView;
700 $status += CreateUCMDevView;
701 $status += CreateUCMComponent;
702 $status += AddModifiableComponent;
703 $status += RebaseStream($test_intstream, 'tc.component_INITIAL', '-complete');
704 $status += RecommendBaseline('tc.component_INITIAL');
705 $status += CreateUCMBaseline;
706 $status += RebaseStream($test_devstream, 'tc.baseline', '-complete');
707 $status += CreateUCMActivity;
709 $log->msg("$script: End UCM Clearcase Tests");
715 my $startTime = time;
716 my $conf_file = "$FindBin::Bin/$script.conf";
724 'verbose' => sub { set_verbose },
725 'debug' => sub { set_debug },
726 'usage' => sub { Usage },
733 # Read the config file
735 %default_opts = GetConfig $conf_file;
737 $log->err("Unable to find config file $conf_file", 1);
740 # Overlay default opts if not specified
741 for (keys %default_opts) {
742 $opts{$_} = $default_opts{$_} if !$opts{$_};
745 $log->msg("$script: Start");
749 # Since we are creating private vobs (to avoid complications with having to
750 # know and code the registry password when making public vobs), we'll simply
751 # change $Clearcase::VOBTAG_PREFIX
752 $Clearcase::VOBTAG_PREFIX = $ENV{TMP} || '/tmp';
755 $status = SetupTest "$Clearcase::VOBTAG_PREFIX/tc.vob", 'tc.view';
760 $log->err('Tests not run. Failure occurred in SetupTest - check logfile');
763 # Note if we are doing UCM tests then we need the view and vob here...
764 $status += Cleanup($test_view, $test_vob) if $opts{clean} and !$opts{ucm};
767 $log->err("$script: Failed (Base Clearcase)");
769 $log->msg("$script: Passed (Base Clearcase)");
774 $status = SetupUCMTest;
777 $status += RunUCMTests;
779 $log->err('UCM Tests not run. Failure occurred in SetupUCMTest - check logfile');
783 $status += CleanupUCM;
784 $status += Cleanup($test_view, $test_vob);
788 $log->err("$script Failed (UCM Clearcase)");
790 $log->msg("$script: Passed (UCM Clearcase)");
794 display_duration $startTime, $log;
796 $log->msg("$script: End");
802 =head1 CONFIGURATION AND ENVIRONMENT
804 DEBUG: If set then $debug is set to this level.
806 VERBOSE: If set then $verbose is set to this level.
808 TRACE: If set then $trace is set to this level.
818 L<Getopt::Long|Getopt::Long>
820 L<Term::ANSIColor|Term::ANSIColor>
822 =head2 ClearSCM Perl Modules
844 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a><br>
845 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Element.pm">Element</a><br>
846 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/View.pm">View</a><br>
847 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Views.pm">Views</a><br>
848 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Vob.pm">Vob</a><br>
849 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Vobs.pm">Vobs</a><br>
850 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM.pm">UCM</a><br>
851 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Activity.pm">Activity</a><br>
852 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Baseline</a><br>
853 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Component.pm">Component</a><br>
854 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Project.pm">Project</a><br>
855 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Pvob.pm">Pvob</a><br>
856 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/UCM/Stream.pm">Stream</a><br>
857 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
858 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
859 <a href="http://clearscm.com/php/scm_man.php?file=lib/GetConfig.pm">GetConfig</a><br>
860 <a href="http://clearscm.com/php/scm_man.php?file=lib/Logger.pm">Logger</a><br>
861 <a href="http://clearscm.com/php/scm_man.php?file=lib/OSDep.pm">OSDep</a><br>
862 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
867 =head1 BUGS AND LIMITATIONS
869 There are no known bugs in this script
871 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
873 =head1 LICENSE AND COPYRIGHT
875 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.