5 =head1 NAME $RCSfile: testcc.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 testcc.pl: [-u|sage] [-ve|rbose] [-d|ebug]
34 [-c|onfig <file>] [-vi|ewstore <viewstore>]
35 [-vo|bstore <vobstore>]
38 -u|sage: Displays usage
41 -d|ebug: Output debug messages
43 -c|onfig <file>: Config file (Default: testcc.conf)
44 -vi|ewstore: Path to view storage area
45 -vo|bstore: Path to vob storage area
49 Clearcase smoke tests. Perform simple Clearcase operations to validate that
50 Clearcase minimally works
60 use Term::ANSIColor qw(:constants);
65 $libs = $ENV{SITE_PERLLIB} ? $ENV{SITE_PERLLIB} : "$FindBin::Bin/../lib";
67 die "Unable to find libraries\n"
74 use Clearcase::Element;
89 my ($vbs, $vws, %default_opts, %opts);
91 my $log = Logger->new;
92 my $view = $Clearcase::VIEWTAG_PREFIX;
93 my $view_tag = $FindBin::Script;
94 my $vob = $ENV{TMP} ? $ENV{TMP} : "/tmp"; # Private vob - mount to /tmp!
95 my $vob_tag = $view_tag;
97 my ($test_view, $test_vob);
99 # LogOpts: Log the %opts has to the log file so we can tell the options used for
103 "$FindBin::Script v$VERSION run at "
105 . " with the following options:"
108 foreach (sort keys %opts) {
109 if (ref $opts{$_} eq "ARRAY") {
111 $log->msg ("$name:\t$_") foreach (@{$opts{$_}});
113 $log->msg ("$_:\t$opts{$_}");
121 $log->msg ("Creating vob $vob/$vob_tag");
123 $test_vob = Clearcase::Vob->new ("$vob/$vob_tag");
125 my ($status, @output) = $test_vob->create ($opts{vobhost}, $vbs);
127 $log->log ($_) foreach (@output);
130 if ($output[0] =~ /already exists/) {
131 $log->warn ("Vob " . $test_vob->tag . " already exists");
140 $log->msg ("Mounting vob " . $test_vob->tag);
142 # Create mount directory
143 my ($status, @output) = Execute "mkdir -p " . $test_vob->tag . " 2>&1";
145 $log->log ($_) foreach (@output);
147 ($status, @output) = $test_vob->mount;
149 $log->log ($_) foreach (@output);
155 my ($status, @output);
157 ($status, @output) = $Clearcase::CC->execute ("cd");
159 $log->msg ("Unmounting vob " . $test_vob->tag);
161 ($status, @output) = $test_vob->umount;
163 $log->msg ("Removing vob " . $test_vob->tag);
165 ($status, @output) = $test_vob->remove;
167 $log->log ($_) foreach (@output);
169 ($status, @output) = Execute "rmdir " . $test_vob->tag;
178 $log->msg ("Creating view $view_tag");
180 $test_view = Clearcase::View->new ($view_tag);
182 my ($status, @output) = $test_view->create ($opts{viewhost}, $vws);
184 $log->log ($_) foreach (@output);
187 if ($output[0] =~ /already exists/) {
188 $log->warn ("View " . $test_view->tag . " already exists");
197 $log->msg ("Setting view $test_view->tag");
199 my ($status, @output) = $test_view->set;
201 $log->log ($_) foreach (@output);
207 $log->msg ("Removing view " . $test_view->tag);
209 my ($status, @output) = $Clearcase::CC->execute ("cd");
211 $log->log ($_) foreach (@output);
214 or $log->err ("Unable to chdir $ENV{HOME}", 1);
216 ($status, @output) = $test_view->remove;
218 $log->log ($_) foreach (@output);
223 sub CreateViewPrivateFiles (@) {
226 $log->msg ("Creating test files");
228 foreach (@elements) {
231 $log->msg ("Creating $_");
234 or $log->err ("Unable to open $_ for writing - $!", 1);
236 print $file "This is file $_\n";
242 } # CreateViewPrivateFiles
247 my ($status, @output);
249 if (ref $element eq "ARRAY") {
250 foreach (@{$element}) {
251 $log->msg ("Checking out $_");
253 my $newElement = Clearcase::Element->new ($_);
255 ($status, @output) = $newElement->checkout;
257 $log->log ($_) foreach (@output);
258 $log->err ("Unable to check out $_", $status) if $status;
261 $log->msg ("Checking out $element");
263 my $newElement = Clearcase::Element->new ($element);
265 ($status, @output) = $newElement->checkout;
267 $log->log ($_) foreach (@output);
268 $log->err ("Unable to check out $element", $status) if $status;
277 my ($status, @output);
279 if (ref $element eq "ARRAY") {
280 foreach (@{$element}) {
281 $log->msg ("Checking in $_");
283 my $newElement = Clearcase::Element->new ($_);
285 ($status, @output) = $newElement->checkin;
287 $log->log ($_) foreach (@output);
288 $log->err ("Unable to check in $_", $status) if $status;
291 $log->msg ("Checking in $element");
293 my $newElement = Clearcase::Element->new ($element);
295 ($status, @output) = $newElement->checkin;
297 $log->log ($_) foreach (@output);
298 $log->err ("Unable to check in $element", $status) if $status;
304 sub ComparingFiles (@) {
307 foreach (@elements) {
308 my @lines = ReadFile $_;
310 $log->err ("Element $_ should contain only two lines", 2) if scalar @lines != 2;
316 sub MakeElements (@) {
319 foreach (@elements) {
320 $log->msg ("Mkelem $_");
322 my $newElement = Clearcase::Element->new ($_);
324 my ($status, @output) = $newElement->mkelem;
326 $log->log ($_) foreach (@output);
327 $log->err ("Unable to make $_ an element", $status) if $status;
336 # . Create a few elements
344 # . $vob_tag is already created
345 # . $view_tag is already created
346 # . View is set and we are in the vob
347 # . There are no vob elements for @elements
355 $log->msg ("Removing test files");
357 unlink $_ foreach (@elements);
359 $log->msg ("Creating view private files");
361 CreateViewPrivateFiles $log, @elements;
363 $log->msg ("Making elements");
366 MakeElements @elements;
370 $log->msg ("Checking out files");
374 $log->msg ("Modifying files");
376 CreateViewPrivateFiles @elements;
378 $log->msg ("Checking in files");
382 $log->msg ("Comparing files");
384 ComparingFiles @elements;
386 $log->msg ("$FindBin::Script: End Tests");
394 $log->msg ("Cleaning up");
396 if ($test_view && $test_view->exists) {
397 $status += DestroyView;
400 if ($test_vob && $test_vob->exists) {
401 $status += DestroyVob;
408 $log->msg ("Setup test environment");
410 my $status += CreateVob;
412 return $status if $status != 0;
416 return $status if $status != 0;
418 $status += CreateView;
420 return $status if $status != 0;
422 $status += $test_view->start;
424 my $dir = $Clearcase::VIEWTAG_PREFIX . $test_view->tag . $test_vob->tag;
427 or $log->err ("Unable to chdir to $dir", $status++);
431 ($status, @output) = $Clearcase::CC->execute ("cd $dir");
434 $log->log ($_) foreach (@output);
435 $log->err ("Unable to chdir to $dir", $status);
441 my $conf_file = "$FindBin::Script.conf";
445 "v|verbose" => sub { set_verbose },
446 "u|usage" => sub { Usage },
453 # Read the config file
455 %default_opts = GetConfig $conf_file;
457 $log->err ("Unable to find config file $conf_file", 1);
460 # Overlay default opts if not specified
461 foreach (keys %default_opts) {
462 $opts{$_} = $default_opts{$_} if !$opts{$_};
465 $vws = "$opts{viewstore}/$view_tag.vws";
466 $vbs = "$opts{vobstore}/$vob_tag.vbs";
468 $log->msg ("START: $FindBin::Script (v$VERSION)");
472 my $status = SetupTest;
477 $log->err ("Tests not run. Failure occured in SetupTest - check logfile");
483 $log->err ("$FindBin::Script failed");
485 $log->msg ("$FindBin::Script passed");
488 $log->msg ("END: $FindBin::Script (v$VERSION)");
494 =head1 CONFIGURATION AND ENVIRONMENT
496 DEBUG: If set then $debug is set to this level.
498 VERBOSE: If set then $verbose is set to this level.
500 TRACE: If set then $trace is set to this level.
510 L<Getopt::Long|Getopt::Long>
512 L<Term::ANSIColor|Term::ANSIColor>
514 =head2 ClearSCM Perl Modules
536 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Clearcase.pm">Clearcase</a><br>
537 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Clearcase/Element.pm">Element</a><br>
538 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Clearcase/View.pm">View</a><br>
539 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Clearcase/Views.pm">Views</a><br>
540 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Clearcase/Vob.pm">Vob</a><br>
541 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Clearcase/Vobspm">Vobs</a><br>
542 <a href="http://clearscm.com/php/cvs_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
543 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a><br>
544 <a href="http://clearscm.com/php/cvs_man.php?file=lib/GetConfig.pm">GetConfig</a><br>
545 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Logger.pm">Logger</a><br>
546 <a href="http://clearscm.com/php/cvs_man.php?file=lib/OSDep.pm">OSDep</a><br>
547 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Utils.pm">Utils</a><br>
552 =head1 BUGS AND LIMITATIONS
554 There are no known bugs in this script
556 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
558 =head1 LICENSE AND COPYRIGHT
560 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.