* Fix some warnings in gettext.c and function.c
[make.git] / tests / test_driver.pl
blob18dcc4be3e00afac35ccd0bcf7f08acbd2864661
1 #!/usr/local/bin/perl
2 # -*-perl-*-
4 # Modification history:
5 # Written 91-12-02 through 92-01-01 by Stephen McGee.
6 # Modified 92-02-11 through 92-02-22 by Chris Arthur to further generalize.
7 # End of modification history
9 # Test driver routines used by a number of test suites, including
10 # those for SCS, make, roll_dir, and scan_deps (?).
12 # this routine controls the whole mess; each test suite sets up a few
13 # variables and then calls &toplevel, which does all the real work.
15 sub toplevel
17 # Get a clean environment
19 %makeENV = ();
21 # Pull in benign variables from the user's environment
23 foreach (# UNIX-specific things
24 'TZ', 'LANG', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',
25 # Purify things
26 'PURIFYOPTIONS',
27 # Windows NT-specific stuff
28 'Path', 'SystemRoot',
29 # DJGPP-specific stuff
30 'DJDIR', 'DJGPP', 'SHELL', 'COMSPEC', 'HOSTNAME', 'LFN',
31 'FNCASE', '387', 'EMU387', 'GROUP'
32 ) {
33 $makeENV{$_} = $ENV{$_} if $ENV{$_};
36 # Replace the environment with the new one
38 %origENV = %ENV;
40 # We used to say "%ENV = ();" but this doesn't work in Perl 5.000
41 # through Perl 5.004. It was fixed in Perl 5.004_01, but we don't
42 # want to require that here, so just delete each one individually.
44 foreach $v (keys %ENV) {
45 delete $ENV{$v};
48 %ENV = %makeENV;
50 $| = 1; # unbuffered output
52 $debug = 0; # debug flag
53 $profile = 0; # profiling flag
54 $verbose = 0; # verbose mode flag
55 $detail = 0; # detailed verbosity
56 $keep = 0; # keep temp files around
57 $workdir = "work"; # The directory where the test will start running
58 $scriptdir = "scripts"; # The directory where we find the test scripts
59 $tmpfilesuffix = "t"; # the suffix used on tmpfiles
60 $default_output_stack_level = 0; # used by attach_default_output, etc.
61 $default_input_stack_level = 0; # used by attach_default_input, etc.
62 $cwd = "."; # don't we wish we knew
63 $cwdslash = ""; # $cwd . $pathsep, but "" rather than "./"
65 &get_osname; # sets $osname, $vos, $pathsep, and $short_filenames
67 &set_defaults; # suite-defined
69 &parse_command_line (@ARGV);
71 print "OS name = `$osname'\n" if $debug;
73 $workpath = "$cwdslash$workdir";
74 $scriptpath = "$cwdslash$scriptdir";
76 &set_more_defaults; # suite-defined
78 &print_banner;
80 if (-d $workpath)
82 print "Clearing $workpath...\n";
83 &remove_directory_tree("$workpath/")
84 || &error ("Couldn't wipe out $workpath\n");
86 else
88 mkdir ($workpath, 0777) || &error ("Couldn't mkdir $workpath: $!\n");
91 if (!-d $scriptpath)
93 &error ("Failed to find $scriptpath containing perl test scripts.\n");
96 if (@TESTS)
98 print "Making work dirs...\n";
99 foreach $test (@TESTS)
101 if ($test =~ /^([^\/]+)\//)
103 $dir = $1;
104 push (@rmdirs, $dir);
105 -d "$workpath/$dir"
106 || mkdir ("$workpath/$dir", 0777)
107 || &error ("Couldn't mkdir $workpath/$dir: $!\n");
111 else
113 print "Finding tests...\n";
114 opendir (SCRIPTDIR, $scriptpath)
115 || &error ("Couldn't opendir $scriptpath: $!\n");
116 @dirs = readdir (SCRIPTDIR);
117 closedir (SCRIPTDIR);
118 foreach $dir (@dirs)
120 next if ($dir =~ /^\.\.?$/ || $dir eq 'CVS' || $dir eq 'RCS'
121 || ! -d "$scriptpath/$dir");
122 push (@rmdirs, $dir);
123 mkdir ("$workpath/$dir", 0777)
124 || &error ("Couldn't mkdir $workpath/$dir: $!\n");
125 opendir (SCRIPTDIR, "$scriptpath/$dir")
126 || &error ("Couldn't opendir $scriptpath/$dir: $!\n");
127 @files = readdir (SCRIPTDIR);
128 closedir (SCRIPTDIR);
129 foreach $test (@files)
131 next if $test =~ /~$/ || -d $test;
132 push (@TESTS, "$dir/$test");
137 if (@TESTS == 0)
139 &error ("\nNo tests in $scriptpath, and none were specified.\n");
142 print "\n";
144 &run_each_test;
146 foreach $dir (@rmdirs)
148 rmdir ("$workpath/$dir");
151 $| = 1;
153 if ($num_failed)
155 print "\n$num_failed Test";
156 print "s" unless $num_failed == 1;
157 print " Failed (See .$diffext files in $workdir dir for details) :-(\n\n";
158 return 0;
160 else
162 print "\n$counter Test";
163 print "s" unless $counter == 1;
164 print " Complete ... No Failures :-)\n\n";
165 return 1;
169 sub get_osname
171 # Set up an initial value. In perl5 we can do it the easy way.
173 $osname = defined($^O) ? $^O : '';
175 # See if the filesystem supports long file names with multiple
176 # dots. DOS doesn't.
177 $short_filenames = 0;
178 (open (TOUCHFD, "> fancy.file.name") && close (TOUCHFD))
179 || ($short_filenames = 1);
180 unlink ("fancy.file.name") || ($short_filenames = 1);
182 if (! $short_filenames) {
183 # Thanks go to meyering@cs.utexas.edu (Jim Meyering) for suggesting a
184 # better way of doing this. (We used to test for existence of a /mnt
185 # dir, but that apparently fails on an SGI Indigo (whatever that is).)
186 # Because perl on VOS translates /'s to >'s, we need to test for
187 # VOSness rather than testing for Unixness (ie, try > instead of /).
189 mkdir (".ostest", 0777) || &error ("Couldn't create .ostest: $!\n", 1);
190 open (TOUCHFD, "> .ostest>ick") && close (TOUCHFD);
191 chdir (".ostest") || &error ("Couldn't chdir to .ostest: $!\n", 1);
194 if (! $short_filenames && -f "ick")
196 $osname = "vos";
197 $vos = 1;
198 $pathsep = ">";
200 else
202 # the following is regrettably knarly, but it seems to be the only way
203 # to not get ugly error messages if uname can't be found.
204 # Hmmm, BSD/OS 2.0's uname -a is excessively verbose. Let's try it
205 # with switches first.
206 eval "chop (\$osname = `sh -c 'uname -nmsr 2>&1'`)";
207 if ($osname =~ /not found/i)
209 $osname = "(something unixy with no uname)";
211 elsif ($@ ne "" || $?)
213 eval "chop (\$osname = `sh -c 'uname -a 2>&1'`)";
214 if ($@ ne "" || $?)
216 $osname = "(something unixy)";
219 $vos = 0;
220 $pathsep = "/";
223 if (! $short_filenames) {
224 chdir ("..") || &error ("Couldn't chdir to ..: $!\n", 1);
225 unlink (".ostest>ick");
226 rmdir (".ostest") || &error ("Couldn't rmdir .ostest: $!\n", 1);
230 sub parse_command_line
232 @argv = @_;
234 # use @ARGV if no args were passed in
236 if (@argv == 0)
238 @argv = @ARGV;
241 # look at each option; if we don't recognize it, maybe the suite-specific
242 # command line parsing code will...
244 while (@argv)
246 $option = shift @argv;
247 if ($option =~ /^-debug$/i)
249 print "\nDEBUG ON\n";
250 $debug = 1;
252 elsif ($option =~ /^-usage$/i)
254 &print_usage;
255 exit 0;
257 elsif ($option =~ /^-(h|help)$/i)
259 &print_help;
260 exit 0;
262 elsif ($option =~ /^-profile$/i)
264 $profile = 1;
266 elsif ($option =~ /^-verbose$/i)
268 $verbose = 1;
270 elsif ($option =~ /^-detail$/i)
272 $detail = 1;
273 $verbose = 1;
275 elsif ($option =~ /^-keep$/i)
277 $keep = 1;
279 elsif (&valid_option($option))
281 # The suite-defined subroutine takes care of the option
283 elsif ($option =~ /^-/)
285 print "Invalid option: $option\n";
286 &print_usage;
287 exit 0;
289 else # must be the name of a test
291 $option =~ s/\.pl$//;
292 push(@TESTS,$option);
297 sub max
299 local($num) = shift @_;
300 local($newnum);
302 while (@_)
304 $newnum = shift @_;
305 if ($newnum > $num)
307 $num = $newnum;
311 return $num;
314 sub print_centered
316 local($width, $string) = @_;
317 local($pad);
319 if (length ($string))
321 $pad = " " x ( ($width - length ($string) + 1) / 2);
322 print "$pad$string";
326 sub print_banner
328 local($info);
329 local($line);
330 local($len);
332 $info = "Running tests for $testee on $osname\n"; # $testee is suite-defined
333 $len = &max (length ($line), length ($testee_version),
334 length ($banner_info), 73) + 5;
335 $line = ("-" x $len) . "\n";
336 if ($len < 78)
338 $len = 78;
341 &print_centered ($len, $line);
342 &print_centered ($len, $info);
343 &print_centered ($len, $testee_version); # suite-defined
344 &print_centered ($len, $banner_info); # suite-defined
345 &print_centered ($len, $line);
346 print "\n";
349 sub run_each_test
351 $counter = 0;
353 foreach $testname (sort @TESTS)
355 $counter++;
356 $test_passed = 1; # reset by test on failure
357 $num_of_logfiles = 0;
358 $num_of_tmpfiles = 0;
359 $description = "";
360 $details = "";
361 $testname =~ s/^$scriptpath$pathsep//;
362 $perl_testname = "$scriptpath$pathsep$testname";
363 $testname =~ s/(\.pl|\.perl)$//;
364 $testpath = "$workpath$pathsep$testname";
365 # Leave enough space in the extensions to append a number, even
366 # though it needs to fit into 8+3 limits.
367 if ($short_filenames) {
368 $logext = 'l';
369 $diffext = 'd';
370 $baseext = 'b';
371 $extext = '';
373 else {
374 $logext = 'log';
375 $diffext = 'diff';
376 $baseext = 'base';
377 $extext = '.';
379 $log_filename = "$testpath.$logext";
380 $diff_filename = "$testpath.$diffext";
381 $base_filename = "$testpath.$baseext";
382 $tmp_filename = "$testpath.$tmpfilesuffix";
384 &setup_for_test; # suite-defined
386 $output = "........................................................ ";
388 substr($output,0,length($testname)) = "$testname ";
390 print $output;
392 # Run the actual test!
394 $code = do $perl_testname;
395 if (!defined($code))
397 $test_passed = 0;
398 if (length ($@))
400 warn "\n*** Test died ($testname): $@\n";
402 else
404 warn "\n*** Couldn't run $perl_testname\n";
407 elsif ($code == -1) {
408 $test_passed = 0;
410 elsif ($code != 1 && $code != -1) {
411 $test_passed = 0;
412 warn "\n*** Test returned $code\n";
415 if ($test_passed) {
416 $status = "ok";
417 for ($i = $num_of_tmpfiles; $i; $i--)
419 &delete ($tmp_filename . &num_suffix ($i) );
422 for ($i = $num_of_logfiles ? $num_of_logfiles : 1; $i; $i--)
424 &delete ($log_filename . &num_suffix ($i) );
425 &delete ($base_filename . &num_suffix ($i) );
428 elsif ($code > 0) {
429 $status = "FAILED";
430 $num_failed++;
432 elsif ($code < 0) {
433 $status = "N/A";
434 --$counter;
437 # If the verbose option has been specified, then a short description
438 # of each test is printed before displaying the results of each test
439 # describing WHAT is being tested.
441 if ($verbose)
443 if ($detail)
445 print "\nWHAT IS BEING TESTED\n";
446 print "--------------------";
448 print "\n\n$description\n\n";
451 # If the detail option has been specified, then the details of HOW
452 # the test is testing what it says it is testing in the verbose output
453 # will be displayed here before the results of the test are displayed.
455 if ($detail)
457 print "\nHOW IT IS TESTED\n";
458 print "----------------";
459 print "\n\n$details\n\n";
462 print "$status\n";
466 # If the keep flag is not set, this subroutine deletes all filenames that
467 # are sent to it.
469 sub delete
471 local(@files) = @_;
473 if (!$keep)
475 return (unlink @files);
478 return 1;
481 sub print_standard_usage
483 local($plname,@moreusage) = @_;
484 local($line);
486 print "Usage: perl $plname [testname] [-verbose] [-detail] [-keep]\n";
487 print " [-profile] [-usage] [-help] "
488 . "[-debug]\n";
489 foreach $line (@moreusage)
491 print " $line\n";
495 sub print_standard_help
497 local(@morehelp) = @_;
498 local($line);
499 local($tline);
500 local($t) = " ";
502 $line = "Test Driver For $testee";
503 print "$line\n";
504 $line = "=" x length ($line);
505 print "$line\n";
507 &print_usage;
509 print "\ntestname\n"
510 . "${t}You may, if you wish, run only ONE test if you know the name\n"
511 . "${t}of that test and specify this name anywhere on the command\n"
512 . "${t}line. Otherwise ALL existing tests in the scripts directory\n"
513 . "${t}will be run.\n"
514 . "-verbose\n"
515 . "${t}If this option is given, a description of every test is\n"
516 . "${t}displayed before the test is run. (Not all tests may have\n"
517 . "${t}descriptions at this time)\n"
518 . "-detail\n"
519 . "${t}If this option is given, a detailed description of every\n"
520 . "${t}test is displayed before the test is run. (Not all tests\n"
521 . "${t}have descriptions at this time)\n"
522 . "-profile\n"
523 . "${t}If this option is given, then the profile file\n"
524 . "${t}is added to other profiles every time $testee is run.\n"
525 . "${t}This option only works on VOS at this time.\n"
526 . "-keep\n"
527 . "${t}You may give this option if you DO NOT want ANY\n"
528 . "${t}of the files generated by the tests to be deleted. \n"
529 . "${t}Without this option, all files generated by the test will\n"
530 . "${t}be deleted IF THE TEST PASSES.\n"
531 . "-debug\n"
532 . "${t}Use this option if you would like to see all of the system\n"
533 . "${t}calls issued and their return status while running the tests\n"
534 . "${t}This can be helpful if you're having a problem adding a test\n"
535 . "${t}to the suite, or if the test fails!\n";
537 foreach $line (@morehelp)
539 $tline = $line;
540 if (substr ($tline, 0, 1) eq "\t")
542 substr ($tline, 0, 1) = $t;
544 print "$tline\n";
548 #######################################################################
549 ########### Generic Test Driver Subroutines ###########
550 #######################################################################
552 sub get_caller
554 local($depth);
555 local($package);
556 local($filename);
557 local($linenum);
559 $depth = defined ($_[0]) ? $_[0] : 1;
560 ($package, $filename, $linenum) = caller ($depth + 1);
561 return "$filename: $linenum";
564 sub error
566 local($message) = $_[0];
567 local($caller) = &get_caller (1);
569 if (defined ($_[1]))
571 $caller = &get_caller ($_[1] + 1) . " -> $caller";
574 die "$caller: $message";
577 sub compare_output
579 local($answer,$logfile) = @_;
580 local($slurp);
582 if ($debug)
584 print "Comparing Output ........ ";
587 $slurp = &read_file_into_string ($logfile);
589 # For make, get rid of any time skew error before comparing--too bad this
590 # has to go into the "generic" driver code :-/
591 $slurp =~ s/^.*modification time in the future.*\n//g;
592 $slurp =~ s/\n.*modification time in the future.*//g;
593 $slurp =~ s/^.*Clock skew detected.*\n//g;
594 $slurp =~ s/\n.*Clock skew detected.*//g;
596 if ($slurp eq $answer)
598 if ($debug)
600 print "ok\n";
602 return 1;
604 else
606 if ($debug)
608 print "DIFFERENT OUTPUT\n";
610 $test_passed = 0;
611 &create_file (&get_basefile, $answer);
613 if ($debug)
615 print "\nCreating Difference File ...\n";
617 # Create the difference file
618 local($command) = "diff -c " . &get_basefile . " " . $logfile;
619 &run_command_with_output(&get_difffile,$command);
621 return 0;
625 sub read_file_into_string
627 local($filename) = @_;
628 local($oldslash) = $/;
630 undef $/;
632 open (RFISFILE, $filename) || return "";
633 local ($slurp) = <RFISFILE>;
634 close (RFISFILE);
636 $/ = $oldslash;
638 return $slurp;
641 sub attach_default_output
643 local ($filename) = @_;
644 local ($code);
646 if ($vos)
648 $code = system "++attach_default_output_hack $filename";
649 $code == -2 || &error ("adoh death\n", 1);
650 return 1;
653 open ("SAVEDOS" . $default_output_stack_level . "out", ">&STDOUT")
654 || &error ("ado: $! duping STDOUT\n", 1);
655 open ("SAVEDOS" . $default_output_stack_level . "err", ">&STDERR")
656 || &error ("ado: $! duping STDERR\n", 1);
658 open (STDOUT, "> " . $filename)
659 || &error ("ado: $filename: $!\n", 1);
660 open (STDERR, ">&STDOUT")
661 || &error ("ado: $filename: $!\n", 1);
663 $default_output_stack_level++;
666 # close the current stdout/stderr, and restore the previous ones from
667 # the "stack."
669 sub detach_default_output
671 local ($code);
673 if ($vos)
675 $code = system "++detach_default_output_hack";
676 $code == -2 || &error ("ddoh death\n", 1);
677 return 1;
680 if (--$default_output_stack_level < 0)
682 &error ("default output stack has flown under!\n", 1);
685 close (STDOUT);
686 close (STDERR);
688 open (STDOUT, ">&SAVEDOS" . $default_output_stack_level . "out")
689 || &error ("ddo: $! duping STDOUT\n", 1);
690 open (STDERR, ">&SAVEDOS" . $default_output_stack_level . "err")
691 || &error ("ddo: $! duping STDERR\n", 1);
693 close ("SAVEDOS" . $default_output_stack_level . "out")
694 || &error ("ddo: $! closing SCSDOSout\n", 1);
695 close ("SAVEDOS" . $default_output_stack_level . "err")
696 || &error ("ddo: $! closing SAVEDOSerr\n", 1);
699 # run one command (passed as a list of arg 0 - n), returning 0 on success
700 # and nonzero on failure.
702 sub run_command
704 local ($code);
706 if ($debug)
708 print "\nrun_command: @_\n";
709 $code = system @_;
710 print "run_command: \"@_\" returned $code.\n";
711 return $code;
714 return system @_;
717 # run one command (passed as a list of arg 0 - n, with arg 0 being the
718 # second arg to this routine), returning 0 on success and non-zero on failure.
719 # The first arg to this routine is a filename to connect to the stdout
720 # & stderr of the child process.
722 sub run_command_with_output
724 local ($filename) = shift;
725 local ($code);
727 &attach_default_output ($filename);
728 $code = system @_;
729 &detach_default_output;
730 if ($debug)
732 print "run_command_with_output: \"@_\" returned $code.\n";
735 return $code;
738 # performs the equivalent of an "rm -rf" on the first argument. Like
739 # rm, if the path ends in /, leaves the (now empty) directory; otherwise
740 # deletes it, too.
742 sub remove_directory_tree
744 local ($targetdir) = @_;
745 local ($nuketop) = 1;
746 local ($ch);
748 $ch = substr ($targetdir, length ($targetdir) - 1);
749 if ($ch eq "/" || $ch eq $pathsep)
751 $targetdir = substr ($targetdir, 0, length ($targetdir) - 1);
752 $nuketop = 0;
755 if (! -e $targetdir)
757 return 1;
760 &remove_directory_tree_inner ("RDT00", $targetdir) || return 0;
761 if ($nuketop)
763 rmdir $targetdir || return 0;
766 return 1;
769 sub remove_directory_tree_inner
771 local ($dirhandle, $targetdir) = @_;
772 local ($object);
773 local ($subdirhandle);
775 opendir ($dirhandle, $targetdir) || return 0;
776 $subdirhandle = $dirhandle;
777 $subdirhandle++;
778 while ($object = readdir ($dirhandle))
780 if ($object eq "." || $object eq "..")
782 next;
785 $object = "$targetdir$pathsep$object";
786 lstat ($object);
788 if (-d _ && &remove_directory_tree_inner ($subdirhandle, $object))
790 rmdir $object || return 0;
792 else
794 unlink $object || return 0;
797 closedir ($dirhandle);
798 return 1;
801 # We used to use this behavior for this function:
803 #sub touch
805 # local (@filenames) = @_;
806 # local ($now) = time;
807 # local ($file);
809 # foreach $file (@filenames)
811 # utime ($now, $now, $file)
812 # || (open (TOUCHFD, ">> $file") && close (TOUCHFD))
813 # || &error ("Couldn't touch $file: $!\n", 1);
815 # return 1;
818 # But this behaves badly on networked filesystems where the time is
819 # skewed, because it sets the time of the file based on the _local_
820 # host. Normally when you modify a file, it's the _remote_ host that
821 # determines the modtime, based on _its_ clock. So, instead, now we open
822 # the file and write something into it to force the remote host to set
823 # the modtime correctly according to its clock.
826 sub touch
828 local (@filenames) = @_;
829 local ($file);
831 foreach $file (@filenames) {
832 (open(T, ">> $file") && print(T "\n") && close(T))
833 || &error("Couldn't touch $file: $!\n", 1);
837 # open a file, write some stuff to it, and close it.
839 sub create_file
841 local ($filename, @lines) = @_;
843 open (CF, "> $filename") || &error ("Couldn't open $filename: $!\n", 1);
844 foreach $line (@lines)
846 print CF $line;
848 close (CF);
851 # create a directory tree described by an associative array, wherein each
852 # key is a relative pathname (using slashes) and its associated value is
853 # one of:
854 # DIR indicates a directory
855 # FILE:contents indicates a file, which should contain contents +\n
856 # LINK:target indicates a symlink, pointing to $basedir/target
857 # The first argument is the dir under which the structure will be created
858 # (the dir will be made and/or cleaned if necessary); the second argument
859 # is the associative array.
861 sub create_dir_tree
863 local ($basedir, %dirtree) = @_;
864 local ($path);
866 &remove_directory_tree ("$basedir");
867 mkdir ($basedir, 0777) || &error ("Couldn't mkdir $basedir: $!\n", 1);
869 foreach $path (sort keys (%dirtree))
871 if ($dirtree {$path} =~ /^DIR$/)
873 mkdir ("$basedir/$path", 0777)
874 || &error ("Couldn't mkdir $basedir/$path: $!\n", 1);
876 elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
878 &create_file ("$basedir/$path", $1 . "\n");
880 elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
882 symlink ("$basedir/$1", "$basedir/$path")
883 || &error ("Couldn't symlink $basedir/$path -> $basedir/$1: $!\n", 1);
885 else
887 &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
890 if ($just_setup_tree)
892 die "Tree is setup...\n";
896 # compare a directory tree with an associative array in the format used
897 # by create_dir_tree, above.
898 # The first argument is the dir under which the structure should be found;
899 # the second argument is the associative array.
901 sub compare_dir_tree
903 local ($basedir, %dirtree) = @_;
904 local ($path);
905 local ($i);
906 local ($bogus) = 0;
907 local ($contents);
908 local ($target);
909 local ($fulltarget);
910 local ($found);
911 local (@files);
912 local (@allfiles);
914 opendir (DIR, $basedir) || &error ("Couldn't open $basedir: $!\n", 1);
915 @allfiles = grep (!/^\.\.?$/, readdir (DIR) );
916 closedir (DIR);
917 if ($debug)
919 print "dirtree: (%dirtree)\n$basedir: (@allfiles)\n";
922 foreach $path (sort keys (%dirtree))
924 if ($debug)
926 print "Checking $path ($dirtree{$path}).\n";
929 $found = 0;
930 foreach $i (0 .. $#allfiles)
932 if ($allfiles[$i] eq $path)
934 splice (@allfiles, $i, 1); # delete it
935 if ($debug)
937 print " Zapped $path; files now (@allfiles).\n";
939 lstat ("$basedir/$path");
940 $found = 1;
941 last;
945 if (!$found)
947 print "compare_dir_tree: $path does not exist.\n";
948 $bogus = 1;
949 next;
952 if ($dirtree {$path} =~ /^DIR$/)
954 if (-d _ && opendir (DIR, "$basedir/$path") )
956 @files = readdir (DIR);
957 closedir (DIR);
958 @files = grep (!/^\.\.?$/ && ($_ = "$path/$_"), @files);
959 push (@allfiles, @files);
960 if ($debug)
962 print " Read in $path; new files (@files).\n";
965 else
967 print "compare_dir_tree: $path is not a dir.\n";
968 $bogus = 1;
971 elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
973 if (-l _ || !-f _)
975 print "compare_dir_tree: $path is not a file.\n";
976 $bogus = 1;
977 next;
980 if ($1 ne "*")
982 $contents = &read_file_into_string ("$basedir/$path");
983 if ($contents ne "$1\n")
985 print "compare_dir_tree: $path contains wrong stuff."
986 . " Is:\n$contentsShould be:\n$1\n";
987 $bogus = 1;
991 elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
993 $target = $1;
994 if (!-l _)
996 print "compare_dir_tree: $path is not a link.\n";
997 $bogus = 1;
998 next;
1001 $contents = readlink ("$basedir/$path");
1002 $contents =~ tr/>/\//;
1003 $fulltarget = "$basedir/$target";
1004 $fulltarget =~ tr/>/\//;
1005 if (!($contents =~ /$fulltarget$/))
1007 if ($debug)
1009 $target = $fulltarget;
1011 print "compare_dir_tree: $path should be link to $target, "
1012 . "not $contents.\n";
1013 $bogus = 1;
1016 else
1018 &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
1022 if ($debug)
1024 print "leftovers: (@allfiles).\n";
1027 foreach $file (@allfiles)
1029 print "compare_dir_tree: $file should not exist.\n";
1030 $bogus = 1;
1033 return !$bogus;
1036 # this subroutine generates the numeric suffix used to keep tmp filenames,
1037 # log filenames, etc., unique. If the number passed in is 1, then a null
1038 # string is returned; otherwise, we return ".n", where n + 1 is the number
1039 # we were given.
1041 sub num_suffix
1043 local($num) = @_;
1045 if (--$num > 0) {
1046 return "$extext$num";
1049 return "";
1052 # This subroutine returns a log filename with a number appended to
1053 # the end corresponding to how many logfiles have been created in the
1054 # current running test. An optional parameter may be passed (0 or 1).
1055 # If a 1 is passed, then it does NOT increment the logfile counter
1056 # and returns the name of the latest logfile. If either no parameter
1057 # is passed at all or a 0 is passed, then the logfile counter is
1058 # incremented and the new name is returned.
1060 sub get_logfile
1062 local($no_increment) = @_;
1064 $num_of_logfiles += !$no_increment;
1066 return ($log_filename . &num_suffix ($num_of_logfiles));
1069 # This subroutine returns a base (answer) filename with a number
1070 # appended to the end corresponding to how many logfiles (and thus
1071 # base files) have been created in the current running test.
1072 # NO PARAMETERS ARE PASSED TO THIS SUBROUTINE.
1074 sub get_basefile
1076 return ($base_filename . &num_suffix ($num_of_logfiles));
1079 # This subroutine returns a difference filename with a number appended
1080 # to the end corresponding to how many logfiles (and thus diff files)
1081 # have been created in the current running test.
1083 sub get_difffile
1085 return ($diff_filename . &num_suffix ($num_of_logfiles));
1088 # just like logfile, only a generic tmp filename for use by the test.
1089 # they are automatically cleaned up unless -keep was used, or the test fails.
1090 # Pass an argument of 1 to return the same filename as the previous call.
1092 sub get_tmpfile
1094 local($no_increment) = @_;
1096 $num_of_tmpfiles += !$no_increment;
1098 return ($tmp_filename . &num_suffix ($num_of_tmpfiles));