Merge branch 'master' of git+ssh://github.com/adefaria/clearscm
[clearscm.git] / test / testclearcase.pl
1 #!/usr/bin/env cqperl
2
3 =pod
4
5 =head1 NAME $RCSfile: testclearcase.pl,v $
6
7 Test Clearcase
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 2.1 $
20
21 =item Created:
22
23 Tue Apr 10 13:14:15 CDT 2007
24
25 =item Modified:
26
27 $Date: 2011/01/09 01:01:32 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage: testclearcase.pl: [-us|age] [-ve|rbose]
34                           [-c|onfig <file>] [-b|ase] [-uc|m]
35
36  Where:
37    -v|erbose:       Display progress output
38    -d|ebug:         Display debug info
39    -us|age:         Display usage
40
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)
45
46 if -ucm is specified then the following additional parameters should be set:
47
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
52                     "/oslc")
53     -database:      Clearquest database to enable (CQ_DATABASE)
54     -dbset:         Clearquest DBSet (CQ_DBSET)
55     -provider:      Name of provider (Default: CQPROV)
56
57 =head1 DESCRIPTION  
58
59 Clearcase smoke tests. Perform simple Clearcase operations to validate that
60 Clearcase minimally works.
61
62 If -ucm is specified then additional UCM related tests are performed.
63
64 =cut
65
66 use strict;
67 use warnings;
68
69 use Cwd;
70 use FindBin;
71 use Getopt::Long;
72 use Pod::Usage;
73
74 use lib "$FindBin::Bin/../lib";
75
76 use Clearcase;
77 use Clearcase::Element;
78 use Clearcase::View;
79 use Clearcase::Views;
80 use Clearcase::Vob;
81 use Clearcase::Vobs;
82
83 use Clearcase::UCM;
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;
91
92 use DateUtils;
93 use Display;
94 use GetConfig;
95 use Logger;
96 use OSDep;
97 use TimeUtils;
98 use Utils;
99
100 # Globals
101 my $VERSION = '2.1';
102
103 my (
104   $test_vob,
105   $test_view,
106   $test_pvob,
107   $test_folder,
108   $test_project,
109   $test_activity,
110   $test_baseline,
111   $test_component,,
112   $test_devstream,
113   $test_intstream,
114   $test_devview,
115   $test_intview,
116 );
117
118 my (%default_opts, %opts);
119
120 my ($script) = ($FindBin::Script =~ /^(.*)\.pl/);
121
122 my $log = Logger->new;
123
124 # LogOpts: Log the %opts has to the log file so we can tell the options used for
125 # this run.
126 sub LogOpts() {
127   $log->msg(
128     "$script v$VERSION run at " 
129   . YMDHM
130   . ' with the following options:'
131   );
132
133   for (sort keys %opts) {
134     next if /help/ || /usage/ || /password/;
135
136     if (ref $opts{$_} eq 'ARRAY') {
137       my $name = $_;
138
139       for (@{$opts{$_}}) {
140         $log->msg("$name:\t$_") if $_;
141       } # for
142     } else {
143       if ($opts{$_}) {
144         $log->msg("$_:\t$opts{$_}");
145       } else {
146         $log->msg("$_:\t<undef>");
147       } # if
148     }  # if
149   } # for
150
151   return;
152 } # LogOpts
153
154 sub CreateVob($) {
155   my ($tag) = @_;
156
157   my $vobname = Clearcase::vobname $tag;
158
159   $log->msg ("Creating vob $tag");
160
161   my $newvob = Clearcase::Vob->new($tag);
162
163   my ($status, @output) = $newvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs");
164
165   $log->log($_) for @output;
166
167   return ($status, $newvob);
168 } # CreateVob
169
170 sub CreatePvob($) {
171   my ($tag) = @_;
172
173   my $vobname = Clearcase::vobname $tag;
174
175   my $pvob = Clearcase::UCM::Pvob->new($tag);
176
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");
179
180   $log->log($_) for @output;
181
182   return ($status, $pvob);
183 } # CreatePvob
184
185 sub MountVob($) {
186   my ($vob) = @_;
187
188   $log->msg('Mounting vob ' . $vob->tag);
189
190   # Create mount directory
191   my ($status, @output);
192
193   ($status, @output) = Execute 'mkdir -p ' . $vob->tag . ' 2>&1' unless -d $vob->tag;
194
195   $log->log($_) for @output;
196
197   ($status, @output) = $vob->mount;
198
199   $log->log($_) for @output;
200
201   return $status;
202 } # MountVob
203
204 sub DestroyVob($) {
205   my ($vob) = @_;
206
207   my ($status, @output);
208
209   ($status, @output) = $Clearcase::CC->execute('cd');
210
211   $log->err('Unable to perform cd command', 1) if $status;
212
213   $log->msg('Unmounting vob ' . $vob->tag);
214
215   ($status, @output) = $vob->umount;
216
217   if ($status) {
218     $log->err('Unable to unmount vob ' . $vob->tag);
219   } else {
220     $log->msg('Umounted vob ' . $vob->tag);
221   } # if
222
223   $log->msg('Removing vob ' . $vob->tag);
224
225   ($status, @output) = $vob->remove;
226
227   if ($status) {
228     $log->err("Failed to execute command " . 
229               $Clearcase::CC->lastcmd . "\n" .
230               join "\t\n", @output);
231   } # if
232
233   $log->log($_) for @output;
234
235   return $status;
236 } # DestroyVob
237
238 sub CreateView($) {
239   my ($tag) = @_;
240
241   $log->msg("Creating view $tag");
242
243   my $view = Clearcase::View->new($tag);
244
245   my ($status, @output) = $view->create($opts{viewhost}, "$opts{viewstore}/$tag.vws");
246
247   $log->log($_) for @output;
248
249   return ($status, $view);
250 } # CreateView
251
252 sub SetView($) {
253   my ($view) = @_;
254
255   $log->msg('Setting view ' . $view->tag);
256
257   my ($status, @output) = $view->set;
258
259   $log->log($_) for @output;
260
261   return $status;
262 } # SetView
263
264 sub StopView($) {
265   my ($view) = @_;
266
267   $log->msg('Stopping view ' . $view->tag);
268
269   my ($status, @output) = $view->stop;
270
271   $log->log($_) for @output;
272
273   return $status;
274 } # StopView
275
276 sub DestroyView($) {
277   my ($view) = @_;
278
279   $log->msg('Removing view ' . $view->tag);
280
281   my ($status, @output) = $Clearcase::CC->execute('cd');
282
283   $log->log($_) for @output;
284
285   chdir $ENV{HOME}
286     or $log->err("Unable to chdir $ENV{HOME}", 1);
287
288   ($status, @output) = $view->remove;
289
290   $log->log($_) for @output;
291
292   return $status;
293 } # DestroyView
294
295 sub CreateViewPrivateFiles(@) {
296   my (@elements) = @_;
297
298   $log->msg('Creating test files');
299
300   for (@elements) {
301     my $file;
302
303     $log->msg("Creating $_");
304
305     open $file, '>>', $_
306       or $log->err("Unable to open $_ for writing - $!", 1);
307
308     print $file "This is file $_\n";
309
310     close $file;
311   } # for
312
313   return;
314 } # CreateViewPrivateFiles
315
316 sub CheckOut($) {
317   my ($element) = @_;
318
319   my ($status, @output);
320
321   if (ref $element eq 'ARRAY') {
322     for (@{$element}) {
323       $log->msg("Checking out $_");
324
325       my $newElement = Clearcase::Element->new($_);
326
327       ($status, @output) = $newElement->checkout;
328
329       $log->log($_) for @output;
330
331       $log->err("Unable to check out $_", $status) if $status;
332     } # for
333   } else {
334     $log->msg("Checking out $element");
335
336     my $newElement = Clearcase::Element->new($element);
337
338     ($status, @output) = $newElement->checkout;
339
340     $log->log($_) for @output;
341
342     $log->err("Unable to check out $element", $status) if $status;
343   } # if
344
345   return;
346 } # CheckOut
347
348 sub CheckIn($) {
349   my ($element) = @_;
350
351   my ($status, @output);
352
353   if (ref $element eq 'ARRAY') {
354     for (@{$element}) {
355       $log->msg("Checking in $_");
356
357       my $newElement = Clearcase::Element->new($_);
358
359       ($status, @output) = $newElement->checkin;
360
361       $log->log($_) for @output;
362
363       $log->err("Unable to check in $_", $status) if $status;
364     } # for
365   } else {
366     $log->msg("Checking in $element");
367
368     my $newElement = Clearcase::Element->new($element);
369
370     ($status, @output) = $newElement->checkin;
371
372     $log->log($_) for @output;
373
374     $log->err("Unable to check in $element", $status) if $status;
375   } # if
376
377   return;
378 } # CheckIn
379
380 sub ComparingFiles(@) {
381   my (@elements) = @_;
382
383   for (@elements) {
384     my @lines = ReadFile $_;
385
386     $log->err("Element $_ should contain only two lines", 2) if scalar @lines != 2;
387   } # for
388
389   return;
390 } # ComparingFiles
391
392 sub MakeElements(@) {
393   my (@elements) = @_;
394
395   for (@elements) {
396     $log->msg("Mkelem $_");
397
398     my $newElement = Clearcase::Element->new($_);
399
400     my ($status, @output) = $newElement->mkelem;
401
402     $log->log($_) for @output;
403
404     $log->err("Unable to make $_ an element", $status) if $status;
405   } # for
406
407   return;
408 } # MakeElements
409
410 sub RunTests() {
411   # Simple tests:
412   #
413   #   . Create a few elements
414   #   . Check them in
415   #   . Check them out
416   #   . Modify them
417   #   . Check them in
418   #
419   # Assumptions:
420   #
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
425   my @elements = (
426     'cctest.h',
427     'ccsetup.c',
428     'cctest.c',
429     'Makefile',
430   );
431
432   $log->msg("$script: Start Base Clearcase Tests");
433   $log->msg('Removing test files');
434
435   unlink $_ for @elements;
436
437   $log->msg('Creating view private files');
438
439   CreateViewPrivateFiles @elements;
440
441   $log->msg('Making elements');
442
443   CheckOut      '.';
444   MakeElements  @elements;
445   CheckIn       \@elements;
446   CheckIn       '.';
447
448   $log->msg('Checking out files');
449
450   CheckOut \@elements;
451
452   $log->msg('Modifying files');
453
454   CreateViewPrivateFiles @elements;
455
456   $log->msg('Checking in files');
457
458   CheckIn \@elements;
459
460   $log->msg('Comparing files');
461
462   ComparingFiles @elements;
463
464   $log->msg("$script: End Base Clearcase Tests");
465
466   return 0;
467 } # RunTests
468
469 sub Cleanup(;$$$) {
470   my ($view, $vob) = @_;
471
472   my $status = 0;
473
474   $log->msg('Cleaning up');
475
476   if ($view && $view->exists) {
477     $status += DestroyView($view);
478   } # if
479
480   if ($vob && $vob->exists) {
481     $status += DestroyVob($vob);
482   } # if
483
484   return $status;
485 } # Cleanup
486
487 sub CleanupUCM() {
488   my ($rc, $status, @output);
489
490   $log->msg('Removing ' . $test_activity->name);
491
492   ($rc, @output) = $test_activity->remove;
493
494   $status += $rc;
495
496   $log->log($_) for @output;
497
498   # Need to remove baselines from streams first using rebase (Devstream)
499   $log->msg('Rebasing ' . $test_devstream->name . ' to remove baseline');
500
501   $status += RebaseStream(
502     $test_devstream,
503     ' -dbaseline ' . $test_baseline->name . '@' . $test_baseline->pvob->tag .
504     ' -view '      . $test_devview->name  . ' -complete',
505   );
506
507   # Change intstream to not have a recommended baseline
508   $log->msg('Changing ' . $test_intstream->name . ' to remove recommended baseline');
509
510   ($rc, @output) = $test_intstream->nrecommended;
511
512   $status += $rc;
513
514   $log->log($_) for @output;
515
516   $status += DestroyView($test_devview);
517
518   $log->msg('Removing ' . $test_baseline->name);
519
520   ($rc, @output) = $test_baseline->remove;
521
522   $status += $rc;
523
524   $log->log($_) for @output;
525
526   $log->msg('Rebasing ' . $test_intstream->name . ' to remove INITIAL baseline');
527
528   $status += RebaseStream(
529     $test_intstream,
530     ' -dbaseline tc.component_INITIAL' . '@' . $test_intstream->pvob->tag .
531     ' -view ' . $test_intview->name    . ' -complete',
532   );
533
534   $log->msg('Removing ' . $test_component->name . ' from ' . $test_project->name);
535
536   ($rc, @output) = $test_project->change(
537     '-dmodcomp ' . $test_component->name . '@' . $test_project->pvob->tag
538   );
539
540   $status += $rc;
541
542   $log->log($_) for @output;
543
544   $log->msg('Removing ' . $test_component->name);
545
546   ($rc, @output) = $test_component->remove;
547
548   $status += $rc;
549
550   $log->log($_) for @output;
551
552   $status += DestroyView($test_intview);
553
554   $log->msg('Removing '. $test_devstream->name);
555
556   ($rc, @output) = $test_devstream->remove;
557
558   $status += $rc;
559
560   $log->log($_) for @output;
561
562   $log->msg('Removing ' . $test_intstream->name);
563
564   ($rc, @output) = $test_intstream->remove;
565
566   $status += $rc;
567
568   $log->log($_) for @output;
569
570   $log->msg('Removing ' . $test_project->name);
571
572   ($rc, @output) = $test_project->remove;
573
574   $status += $rc;
575
576   $log->log($_) for @output;
577
578   $log->msg('Removing ' . $test_folder->name);
579
580   ($rc, @output) = $test_folder->remove;
581
582   $status += $rc;
583
584   $log->log($_) for @output;
585
586   $log->msg('Removing ' . $test_pvob->name);
587
588   ($rc, @output) = DestroyVob($test_pvob);
589
590   $log->log($_) for @output;
591
592   return $status;
593 } # CleanupUCM
594
595 sub SetupTest($$) {
596   my ($vob_tag, $view_tag) = @_;
597
598   my ($status, @output);
599
600   $log->msg('Setup test environment');
601
602   my $view = Clearcase::View->new($view_tag);
603
604   if ($view->exists) {
605     $log->msg('Removing old view ' . $view_tag);
606
607     ($status, @output) = $view->remove;
608
609     $log->err('Unable to remove old view ' . $view->tag, $status) if $status;
610   } # if
611
612   ($status, $test_view) = CreateView($view_tag);
613
614   return $status if $status != 0;
615
616   $status = $test_view->start;
617
618   my $vob = Clearcase::Vob->new($vob_tag);
619
620   if ($vob->exists) {
621     $log->msg('Removing old vob ' . $vob_tag);
622
623     ($status, @output) = DestroyVob($vob);
624
625     $log->err('Unable to remove old vob '. $vob->tag, $status) if $status;
626   } # if
627
628   ($status, $test_vob) = CreateVob($vob_tag);
629
630   return $status if $status != 0;
631
632   $status = MountVob($test_vob);
633
634   return $status if $status != 0;
635
636   my $dir = $Clearcase::VIEWTAG_PREFIX . '/' . $test_view->tag . $test_vob->tag;
637
638   chdir $dir
639     or $log->err("Unable to chdir to $dir", ++$status);
640
641   ($status, @output) = $Clearcase::CC->execute("cd $dir");
642
643   $log->log($_) for @output;
644
645   return $status;
646 } # SetupTest
647
648 sub SetupAttributeTypes() {
649   my @CC_CMI_Types = qw(CONTEXT TASK PROVIDERS);
650
651   my $status = SetView($test_intview);
652
653   return $status if $status;
654
655   for (@CC_CMI_Types) {
656     my $cmd = "mkattype -nc -vtype string CC_CMI_$_";
657
658     my ($rc, @output) = $Clearcase::CC->execute($cmd);
659
660      $status += $rc;
661
662      $log->log($_) for @output;
663   } # for
664
665   return $status;
666 } # SetupAttributeTypes
667
668 sub CRMRegister() {
669   my $cmd = "crmregister add -database $opts{database} -connection RDE "
670           . "-url $opts{weburl} -username $opts{username} "
671           . "-password $opts{password}";
672
673   my ($status, @output) = Execute $cmd;
674
675   $log->log($_) for @output;
676
677   return $status;
678 } # CRMRegister
679
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}";
685
686   my ($status, @output) = $Clearcase::CC->execute($cmd);
687
688   $log->log($_) for @output;
689
690   return $status;
691 } # MakeCMProvider
692
693 sub SetupUCMTest() {
694   my $status;
695
696   $log->msg("Register RDE://$opts{username}\@$opts{database}");
697
698   $status = CRMRegister;
699
700   $log->err("Unable to register RDE://$opts{username}\@$opts{database} - Check logfile", $status)
701     if $status;
702
703   $log->msg("Creating UCM Pvob ${Clearcase::VOBTAG_PREFIX}tc.pvob");
704
705   ($status, $test_pvob) = CreatePvob("${Clearcase::VOBTAG_PREFIX}tc.pvob"); 
706
707   MountVob $test_pvob;
708
709   return $status;
710 } # SetupUCMTest
711
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);
715
716   $test_project = Clearcase::UCM::Project->new('tc.project', $test_folder, $test_pvob);
717
718   $test_project->remove if $test_project->exists;
719
720   $log->msg('Creating UCM Project tc.project');
721
722   my ($status, @output) = $test_project->create;
723
724   $log->log($_) for @output;
725
726   return $status;
727 } # CreateUCMProject
728
729 sub CreateUCMIntStream() {
730   $test_intstream = Clearcase::UCM::Stream->new('tc.intstream', $test_pvob);
731
732   $log->msg('Creating UCM Stream tc.intstream');
733
734   my ($status, @output) = $test_intstream->create($test_project, '-integration');
735
736   $log->log($_) for @output;
737
738   return $status;
739 } # CreateUCMIntStream
740
741 sub CreateUCMDevStream() {
742   $test_devstream = Clearcase::UCM::Stream->new('tc.devstream', $test_pvob);
743
744   $log->msg('Creating UCM Stream tc.devstream');
745
746   my ($status, @output) = $test_devstream->create($test_project);
747
748   $log->log($_) for @output;
749
750   return $status;
751 } # CreateUCMDevStream
752
753 sub CreateUCMComponent() {
754   $test_component = Clearcase::UCM::Component->new('tc.component', $test_pvob);
755
756   $log->msg('Creating UCM Component tc.component');
757
758   my ($status, @output) = $test_component->create(
759     "$Clearcase::VIEWTAG_PREFIX/" . $test_intview->tag . $test_vob->tag
760   );
761
762   $log->log($_) for @output;
763
764   return $status;
765 } # CreateUCMComponent
766
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
771   );
772
773   $log->log($_) for @output;
774
775   return $status;
776 } # AddModifiableCOmponent
777
778 sub CreateUCMIntView() {
779   $log->msg("Creating UCM Int View tc.intview");
780
781   $test_intview = Clearcase::View->new('tc.intview');
782
783   my ($status, @output) = $test_intview->create(
784     $opts{viewhost}, "$opts{viewstore}/tc.intview.vws",
785     '-stream ' . $test_intstream->name . '@' . $test_pvob->tag
786   );
787
788   $log->log($_) for @output;
789
790   $test_intview->start unless $status;
791
792   return $status;
793 } # CreateUCMIntView
794
795 sub CreateUCMDevView() {
796   $log->msg("Creating UCM Dev View tc.devview");
797
798   $test_devview = Clearcase::View->new('tc.devview');
799
800   my ($status, @output) = $test_devview->create(
801     $opts{viewhost}, "$opts{viewstore}/tc.devview.vws",
802     '-stream ' . $test_devstream->name . '@' . $test_pvob->tag
803   );
804
805   $log->log($_) for @output;
806
807   $test_devview->start unless $status;
808
809   return $status;
810 } # CreateUCMDevView
811
812 sub CreateUCMBaseline() {
813   $test_baseline = Clearcase::UCM::Baseline->new('tc.baseline', $test_pvob);
814
815   $log->msg('Creating UCM Baseline tc.baseline');
816
817   my ($status, @output) = $test_baseline->create($test_intview, undef, '-identical');
818
819   $log->log($_) for @output;
820
821   return $status;
822 } # CreateUCMBaseline
823
824 sub CreateUCMActivity() {
825   $test_activity = Clearcase::UCM::Activity->new('tc.activity', $test_pvob);
826
827   $log->msg('Creating UCM Activity tc.activity');
828
829   my ($status, @output) = $test_activity->create($test_devstream, 'A UCM Test Activity');
830
831   $log->log($_) for @output;
832
833   return $status;
834 } # CreateUCMActivity
835
836 sub RebaseStream($$) {
837   my ($stream, $opts) = @_;
838
839   my ($status, @output) = $stream->rebase($opts);
840
841   $log->log($_) for @output;
842
843   return $status;
844 } # RebaseStream
845
846 sub RecommendBaseline($$) {
847   my ($stream, $baseline) = @_;
848
849   my ($status, @output) = $stream->recommend($baseline);
850
851   $log->log($_) for @output;
852
853   return $status;
854 } # RecommentBaseline
855
856 sub RunUCMTests() {
857   my $status = 0;
858
859   $log->msg("$script: Start UCM Clearcase Tests");
860
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;
875
876   $log->msg("$script: End UCM Clearcase Tests");
877
878   return $status;
879 } # RunUCMTests
880
881 ## Main
882 my $startTime = time;
883 my $conf_file = "$FindBin::Bin/$script.conf";
884 my $status    = 0;
885
886 $opts{help}     = sub { pod2usage };
887 $opts{usage}    = sub { pod2usage (-verbose => 2)};
888 $opts{base}     = 1;
889 $opts{clean}    = 1;
890 $opts{username} = $ENV{CQ_USERNAME};
891 $opts{password} = $ENV{CQ_PASSWORD};
892 $opts{weburl}   = $ENV{CQ_WEBURL};
893
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';
898
899 GetOptions(
900   \%opts,
901   'verbose' => sub { set_verbose },
902   'debug'   => sub { set_debug },
903   'usage'   => sub { Usage },
904   'config=s',
905   'base!',
906   'ucm!',
907   'clean!',
908   'username=s',
909   'database=s',
910   'dbset=s',
911   'provider',
912 ) || pod2usage;
913
914 # Read the config file
915 if (-f $conf_file) {
916   %default_opts = GetConfig $conf_file;
917 } else {
918   $log->err("Unable to find config file $conf_file", 1);
919 } # if
920
921 # Overlay default opts if not specified
922 for (keys %default_opts) {
923   $opts{$_} = $default_opts{$_} if !$opts{$_};
924 } # for
925
926 # Check CQ parameters
927 if ($opts{ucm}) {
928   for ('username', 'password', 'weburl', 'database', 'dbset', 'provider') {
929     pod2usage "In UCM mode you must specify -$_" unless $opts{$_};
930   } # for
931 } # if
932
933 $log->msg("$script: Start");
934
935 LogOpts;
936
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';
942 } # if
943
944 if ($opts{base}) {
945   $status = SetupTest "${Clearcase::VOBTAG_PREFIX}tc.vob", 'tc.view';
946
947   if ($status == 0) {
948     $status += RunTests;
949   } else {
950     $log->err('Tests not run. Failure occurred in SetupTest - check logfile');
951   } # if
952
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};
955
956   if ($status != 0) {
957     $log->err("$script: Failed (Base Clearcase)");
958   } else {
959     $log->msg("$script: Passed (Base Clearcase)");
960   } # if
961 } # if
962
963 if ($opts{ucm}) {
964   $status = SetupUCMTest;
965
966   if ($status == 0) {
967     $status += RunUCMTests;
968   } else {
969     $log->err('UCM Tests not run. Failure occurred in SetupUCMTest - check logfile');
970   } # if
971
972   if ($opts{clean}) {
973     $status += CleanupUCM;
974     $status += Cleanup($test_view, $test_vob);
975   } # if
976
977   if ($status != 0) {
978     $log->err("$script: Failed (UCM Clearcase)");
979   } else {
980     $log->msg("$script: Passed (UCM Clearcase)");
981   } # if
982 } # if
983
984 display_duration $startTime, $log;
985
986 $log->msg("$script: End");
987
988 exit $status;
989
990 =pod
991
992 =head1 CONFIGURATION AND ENVIRONMENT
993
994 DEBUG: If set then $debug is set to this level.
995
996 VERBOSE: If set then $verbose is set to this level.
997
998 TRACE: If set then $trace is set to this level.
999
1000 =head1 DEPENDENCIES
1001
1002 =head2 Perl Modules
1003
1004 L<Cwd>
1005
1006 L<FindBin>
1007
1008 L<Getopt::Long|Getopt::Long>
1009
1010 =head2 ClearSCM Perl Modules
1011
1012 =begin man
1013
1014  Clearcase
1015  Clearcase::Element
1016  Clearcase::View
1017  Clearcase::Views
1018  Clearcase::Vob
1019  Clearcase::Vobs
1020  DateUtils
1021  Display
1022  GetConfig
1023  Logger
1024  OSDep
1025  Utils
1026
1027 =end man
1028
1029 =begin html
1030
1031 <blockquote>
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>
1051 </blockquote>
1052
1053 =end html
1054
1055 =head1 BUGS AND LIMITATIONS
1056
1057 There are no known bugs in this script
1058
1059 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
1060
1061 =head1 LICENSE AND COPYRIGHT
1062
1063 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
1064
1065 =cut