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.
8 # Copyright (C) 1991-2012 Free Software Foundation, Inc.
9 # This file is part of GNU Make.
11 # GNU Make is free software; you can redistribute it and/or modify it under
12 # the terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 3 of the License, or (at your option) any later
16 # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 # You should have received a copy of the GNU General Public License along with
22 # this program. If not, see <http://www.gnu.org/licenses/>.
25 # Test driver routines used by a number of test suites, including
26 # those for SCS, make, roll_dir, and scan_deps (?).
28 # this routine controls the whole mess; each test suite sets up a few
29 # variables and then calls &toplevel, which does all the real work.
31 # $Id: test_driver.pl,v 1.34 2012/03/05 14:10:47 psmith Exp $
34 # The number of test categories we've run
36 # The number of test categroies that have passed
37 $categories_passed = 0;
38 # The total number of individual tests that have been run
40 # The total number of individual tests that have passed
41 $total_tests_passed = 0;
42 # The number of tests in this category that have been run
44 # The number of tests in this category that have passed
48 # Yeesh. This whole test environment is such a hack!
52 # Timeout in seconds. If the test takes longer than this we'll fail it.
58 # %makeENV is the cleaned-out environment.
61 # %extraENV are any extra environment variables the tests might want to set.
62 # These are RESET AFTER EVERY TEST!
65 # %origENV is the caller's original environment
70 # We used to say "%ENV = ();" but this doesn't work in Perl 5.000
71 # through Perl 5.004. It was fixed in Perl 5.004_01, but we don't
72 # want to require that here, so just delete each one individually.
73 foreach $v (keys %ENV) {
78 foreach $v (keys %extraENV) {
79 $ENV{$v} = $extraENV{$v};
86 # Pull in benign variables from the user's environment
88 foreach (# UNIX-specific things
89 'TZ', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',
93 # Windows NT-specific stuff
95 # DJGPP-specific stuff
96 'DJDIR', 'DJGPP', 'SHELL', 'COMSPEC', 'HOSTNAME', 'LFN',
97 'FNCASE', '387', 'EMU387', 'GROUP'
99 $makeENV{$_} = $ENV{$_} if $ENV{$_};
102 # Make sure our compares are not foiled by locale differences
104 $makeENV{LC_ALL
} = 'C';
106 # Replace the environment with the new one
112 $| = 1; # unbuffered output
114 $debug = 0; # debug flag
115 $profile = 0; # profiling flag
116 $verbose = 0; # verbose mode flag
117 $detail = 0; # detailed verbosity
118 $keep = 0; # keep temp files around
119 $workdir = "work"; # The directory where the test will start running
120 $scriptdir = "scripts"; # The directory where we find the test scripts
121 $tmpfilesuffix = "t"; # the suffix used on tmpfiles
122 $default_output_stack_level = 0; # used by attach_default_output, etc.
123 $default_input_stack_level = 0; # used by attach_default_input, etc.
124 $cwd = "."; # don't we wish we knew
125 $cwdslash = ""; # $cwd . $pathsep, but "" rather than "./"
127 &get_osname
; # sets $osname, $vos, $pathsep, and $short_filenames
129 &set_defaults
; # suite-defined
131 &parse_command_line
(@ARGV);
133 print "OS name = '$osname'\n" if $debug;
135 $workpath = "$cwdslash$workdir";
136 $scriptpath = "$cwdslash$scriptdir";
138 &set_more_defaults
; # suite-defined
144 print "Clearing $workpath...\n";
145 &remove_directory_tree
("$workpath/")
146 || &error
("Couldn't wipe out $workpath\n");
150 mkdir ($workpath, 0777) || &error
("Couldn't mkdir $workpath: $!\n");
155 &error
("Failed to find $scriptpath containing perl test scripts.\n");
160 print "Making work dirs...\n";
161 foreach $test (@TESTS)
163 if ($test =~ /^([^\/]+)\
//)
166 push (@rmdirs, $dir);
168 || mkdir ("$workpath/$dir", 0777)
169 || &error
("Couldn't mkdir $workpath/$dir: $!\n");
175 print "Finding tests...\n";
176 opendir (SCRIPTDIR
, $scriptpath)
177 || &error
("Couldn't opendir $scriptpath: $!\n");
178 @dirs = grep (!/^(\..*|CVS|RCS)$/, readdir (SCRIPTDIR
) );
179 closedir (SCRIPTDIR
);
182 next if ($dir =~ /^(\..*|CVS|RCS)$/ || ! -d
"$scriptpath/$dir");
183 push (@rmdirs, $dir);
184 mkdir ("$workpath/$dir", 0777)
185 || &error
("Couldn't mkdir $workpath/$dir: $!\n");
186 opendir (SCRIPTDIR
, "$scriptpath/$dir")
187 || &error
("Couldn't opendir $scriptpath/$dir: $!\n");
188 @files = grep (!/^(\..*|CVS|RCS|.*~)$/, readdir (SCRIPTDIR
) );
189 closedir (SCRIPTDIR
);
190 foreach $test (@files)
193 push (@TESTS, "$dir/$test");
200 &error
("\nNo tests in $scriptpath, and none were specified.\n");
207 foreach $dir (@rmdirs)
209 rmdir ("$workpath/$dir");
214 $categories_failed = $categories_run - $categories_passed;
215 $total_tests_failed = $total_tests_run - $total_tests_passed;
217 if ($total_tests_failed)
219 print "\n$total_tests_failed Test";
220 print "s" unless $total_tests_failed == 1;
221 print " in $categories_failed Categor";
222 print ($categories_failed == 1 ?
"y" : "ies");
223 print " Failed (See .$diffext files in $workdir dir for details) :-(\n\n";
228 print "\n$total_tests_passed Test";
229 print "s" unless $total_tests_passed == 1;
230 print " in $categories_passed Categor";
231 print ($categories_passed == 1 ?
"y" : "ies");
232 print " Complete ... No Failures :-)\n\n";
239 # Set up an initial value. In perl5 we can do it the easy way.
240 $osname = defined($^O
) ?
$^O
: '';
242 # Find a path to Perl
244 # See if the filesystem supports long file names with multiple
246 $short_filenames = 0;
247 (open (TOUCHFD
, "> fancy.file.name") && close (TOUCHFD
))
248 || ($short_filenames = 1);
249 unlink ("fancy.file.name") || ($short_filenames = 1);
251 if (! $short_filenames) {
252 # Thanks go to meyering@cs.utexas.edu (Jim Meyering) for suggesting a
253 # better way of doing this. (We used to test for existence of a /mnt
254 # dir, but that apparently fails on an SGI Indigo (whatever that is).)
255 # Because perl on VOS translates /'s to >'s, we need to test for
256 # VOSness rather than testing for Unixness (ie, try > instead of /).
258 mkdir (".ostest", 0777) || &error
("Couldn't create .ostest: $!\n", 1);
259 open (TOUCHFD
, "> .ostest>ick") && close (TOUCHFD
);
260 chdir (".ostest") || &error
("Couldn't chdir to .ostest: $!\n", 1);
263 if (! $short_filenames && -f
"ick")
271 # the following is regrettably knarly, but it seems to be the only way
272 # to not get ugly error messages if uname can't be found.
273 # Hmmm, BSD/OS 2.0's uname -a is excessively verbose. Let's try it
274 # with switches first.
275 eval "chop (\$osname = `sh -c 'uname -nmsr 2>&1'`)";
276 if ($osname =~ /not found/i)
278 $osname = "(something posixy with no uname)";
280 elsif ($@
ne "" || $?
)
282 eval "chop (\$osname = `sh -c 'uname -a 2>&1'`)";
285 $osname = "(something posixy)";
292 if (! $short_filenames) {
293 chdir ("..") || &error
("Couldn't chdir to ..: $!\n", 1);
294 unlink (".ostest>ick");
295 rmdir (".ostest") || &error
("Couldn't rmdir .ostest: $!\n", 1);
299 sub parse_command_line
303 # use @ARGV if no args were passed in
310 # look at each option; if we don't recognize it, maybe the suite-specific
311 # command line parsing code will...
315 $option = shift @argv;
316 if ($option =~ /^-debug$/i)
318 print "\nDEBUG ON\n";
321 elsif ($option =~ /^-usage$/i)
326 elsif ($option =~ /^-(h|help)$/i)
331 elsif ($option =~ /^-profile$/i)
335 elsif ($option =~ /^-verbose$/i)
339 elsif ($option =~ /^-detail$/i)
344 elsif ($option =~ /^-keep$/i)
348 elsif (&valid_option
($option))
350 # The suite-defined subroutine takes care of the option
352 elsif ($option =~ /^-/)
354 print "Invalid option: $option\n";
358 else # must be the name of a test
360 $option =~ s/\.pl$//;
361 push(@TESTS,$option);
368 local($num) = shift @_;
385 local($width, $string) = @_;
388 if (length ($string))
390 $pad = " " x
( ($width - length ($string) + 1) / 2);
401 $info = "Running tests for $testee on $osname\n"; # $testee is suite-defined
402 $len = &max
(length ($line), length ($testee_version),
403 length ($banner_info), 73) + 5;
404 $line = ("-" x
$len) . "\n";
410 &print_centered
($len, $line);
411 &print_centered
($len, $info);
412 &print_centered
($len, $testee_version); # suite-defined
413 &print_centered
($len, $banner_info); # suite-defined
414 &print_centered
($len, $line);
422 foreach $testname (sort @TESTS)
425 $suite_passed = 1; # reset by test on failure
426 $num_of_logfiles = 0;
427 $num_of_tmpfiles = 0;
430 $old_makefile = undef;
431 $testname =~ s/^$scriptpath$pathsep//;
432 $perl_testname = "$scriptpath$pathsep$testname";
433 $testname =~ s/(\.pl|\.perl)$//;
434 $testpath = "$workpath$pathsep$testname";
435 # Leave enough space in the extensions to append a number, even
436 # though it needs to fit into 8+3 limits.
437 if ($short_filenames) {
450 $log_filename = "$testpath.$logext";
451 $diff_filename = "$testpath.$diffext";
452 $base_filename = "$testpath.$baseext";
453 $run_filename = "$testpath.$runext";
454 $tmp_filename = "$testpath.$tmpfilesuffix";
456 &setup_for_test
; # suite-defined
458 $output = "........................................................ ";
460 substr($output,0,length($testname)) = "$testname ";
464 # Run the actual test!
468 $code = do $perl_testname;
470 $total_tests_run += $tests_run;
471 $total_tests_passed += $tests_passed;
478 warn "\n*** Test died ($testname): $@\n";
480 warn "\n*** Couldn't run $perl_testname\n";
483 elsif ($code == -1) {
486 elsif ($code != 1 && $code != -1) {
488 warn "\n*** Test returned $code\n";
492 ++$categories_passed;
493 $status = "ok ($tests_passed passed)";
494 for ($i = $num_of_tmpfiles; $i; $i--)
496 &rmfiles
($tmp_filename . &num_suffix
($i) );
499 for ($i = $num_of_logfiles ?
$num_of_logfiles : 1; $i; $i--)
501 &rmfiles
($log_filename . &num_suffix
($i) );
502 &rmfiles
($base_filename . &num_suffix
($i) );
505 elsif (!defined $code || $code > 0) {
506 $status = "FAILED ($tests_passed/$tests_run passed)";
513 # If the verbose option has been specified, then a short description
514 # of each test is printed before displaying the results of each test
515 # describing WHAT is being tested.
521 print "\nWHAT IS BEING TESTED\n";
522 print "--------------------";
524 print "\n\n$description\n\n";
527 # If the detail option has been specified, then the details of HOW
528 # the test is testing what it says it is testing in the verbose output
529 # will be displayed here before the results of the test are displayed.
533 print "\nHOW IT IS TESTED\n";
534 print "----------------";
535 print "\n\n$details\n\n";
542 # If the keep flag is not set, this subroutine deletes all filenames that
551 return (unlink @files);
557 sub print_standard_usage
559 local($plname,@moreusage) = @_;
562 print "usage:\t$plname [testname] [-verbose] [-detail] [-keep]\n";
563 print "\t\t\t[-profile] [-usage] [-help] [-debug]\n";
564 foreach (@moreusage) {
569 sub print_standard_help
571 local(@morehelp) = @_;
576 $line = "Test Driver For $testee";
578 $line = "=" x
length ($line);
584 . "${t}You may, if you wish, run only ONE test if you know the name\n"
585 . "${t}of that test and specify this name anywhere on the command\n"
586 . "${t}line. Otherwise ALL existing tests in the scripts directory\n"
587 . "${t}will be run.\n"
589 . "${t}If this option is given, a description of every test is\n"
590 . "${t}displayed before the test is run. (Not all tests may have\n"
591 . "${t}descriptions at this time)\n"
593 . "${t}If this option is given, a detailed description of every\n"
594 . "${t}test is displayed before the test is run. (Not all tests\n"
595 . "${t}have descriptions at this time)\n"
597 . "${t}If this option is given, then the profile file\n"
598 . "${t}is added to other profiles every time $testee is run.\n"
599 . "${t}This option only works on VOS at this time.\n"
601 . "${t}You may give this option if you DO NOT want ANY\n"
602 . "${t}of the files generated by the tests to be deleted. \n"
603 . "${t}Without this option, all files generated by the test will\n"
604 . "${t}be deleted IF THE TEST PASSES.\n"
606 . "${t}Use this option if you would like to see all of the system\n"
607 . "${t}calls issued and their return status while running the tests\n"
608 . "${t}This can be helpful if you're having a problem adding a test\n"
609 . "${t}to the suite, or if the test fails!\n";
611 foreach $line (@morehelp)
614 if (substr ($tline, 0, 1) eq "\t")
616 substr ($tline, 0, 1) = $t;
622 #######################################################################
623 ########### Generic Test Driver Subroutines ###########
624 #######################################################################
633 $depth = defined ($_[0]) ?
$_[0] : 1;
634 ($package, $filename, $linenum) = caller ($depth + 1);
635 return "$filename: $linenum";
640 local($message) = $_[0];
641 local($caller) = &get_caller
(1);
645 $caller = &get_caller
($_[1] + 1) . " -> $caller";
648 die "$caller: $message";
653 local($answer,$logfile) = @_;
654 local($slurp, $answer_matched) = ('', 0);
656 print "Comparing Output ........ " if $debug;
658 $slurp = &read_file_into_string
($logfile);
660 # For make, get rid of any time skew error before comparing--too bad this
661 # has to go into the "generic" driver code :-/
662 $slurp =~ s/^.*modification time .*in the future.*\n//gm;
663 $slurp =~ s/^.*Clock skew detected.*\n//gm;
667 if ($slurp eq $answer) {
670 # See if it is a slash or CRLF problem
671 local ($answer_mod, $slurp_mod) = ($answer, $slurp);
673 $answer_mod =~ tr
,\\,/,;
674 $answer_mod =~ s
,\r\n,\n,gs
;
676 $slurp_mod =~ tr
,\\,/,;
677 $slurp_mod =~ s
,\r\n,\n,gs
;
679 $answer_matched = ($slurp_mod eq $answer_mod);
681 # If it still doesn't match, see if the answer might be a regex.
682 if (!$answer_matched && $answer =~ m
,^/(.+)/$,) {
683 $answer_matched = ($slurp =~ /$1/);
684 if (!$answer_matched && $answer_mod =~ m
,^/(.+)/$,) {
685 $answer_matched = ($slurp_mod =~ /$1/);
690 if ($answer_matched && $test_passed)
692 print "ok\n" if $debug;
697 if (! $answer_matched) {
698 print "DIFFERENT OUTPUT\n" if $debug;
700 &create_file
(&get_basefile
, $answer);
701 &create_file
(&get_runfile
, $command_string);
703 print "\nCreating Difference File ...\n" if $debug;
705 # Create the difference file
707 local($command) = "diff -c " . &get_basefile
. " " . $logfile;
708 &run_command_with_output
(&get_difffile
,$command);
717 sub read_file_into_string
719 local($filename) = @_;
720 local($oldslash) = $/;
724 open (RFISFILE
, $filename) || return "";
725 local ($slurp) = <RFISFILE
>;
733 sub attach_default_output
735 local ($filename) = @_;
740 $code = system "++attach_default_output_hack $filename";
741 $code == -2 || &error
("adoh death\n", 1);
745 open ("SAVEDOS" . $default_output_stack_level . "out", ">&STDOUT")
746 || &error
("ado: $! duping STDOUT\n", 1);
747 open ("SAVEDOS" . $default_output_stack_level . "err", ">&STDERR")
748 || &error
("ado: $! duping STDERR\n", 1);
750 open (STDOUT
, "> " . $filename)
751 || &error
("ado: $filename: $!\n", 1);
752 open (STDERR
, ">&STDOUT")
753 || &error
("ado: $filename: $!\n", 1);
755 $default_output_stack_level++;
758 # close the current stdout/stderr, and restore the previous ones from
761 sub detach_default_output
767 $code = system "++detach_default_output_hack";
768 $code == -2 || &error
("ddoh death\n", 1);
772 if (--$default_output_stack_level < 0)
774 &error
("default output stack has flown under!\n", 1);
780 open (STDOUT
, ">&SAVEDOS" . $default_output_stack_level . "out")
781 || &error
("ddo: $! duping STDOUT\n", 1);
782 open (STDERR
, ">&SAVEDOS" . $default_output_stack_level . "err")
783 || &error
("ddo: $! duping STDERR\n", 1);
785 close ("SAVEDOS" . $default_output_stack_level . "out")
786 || &error
("ddo: $! closing SCSDOSout\n", 1);
787 close ("SAVEDOS" . $default_output_stack_level . "err")
788 || &error
("ddo: $! closing SAVEDOSerr\n", 1);
791 # This runs a command without any debugging info.
796 # We reset this before every invocation. On Windows I think there is only
797 # one environment, not one per process, so I think that variables set in
798 # test scripts might leak into subsequent tests if this isn't reset--???
802 local $SIG{ALRM
} = sub { die "timeout\n"; };
808 # The eval failed. If it wasn't SIGALRM then die.
809 $@
eq "timeout\n" or die;
811 # Timed out. Resend the alarm to our process group to kill the children.
812 $SIG{ALRM
} = 'IGNORE';
820 # run one command (passed as a list of arg 0 - n), returning 0 on success
821 # and nonzero on failure.
825 print "\nrun_command: @_\n" if $debug;
826 my $code = _run_command
(@_);
827 print "run_command returned $code.\n" if $debug;
832 # run one command (passed as a list of arg 0 - n, with arg 0 being the
833 # second arg to this routine), returning 0 on success and non-zero on failure.
834 # The first arg to this routine is a filename to connect to the stdout
835 # & stderr of the child process.
837 sub run_command_with_output
839 my $filename = shift;
841 print "\nrun_command_with_output($filename,$runname): @_\n" if $debug;
842 &attach_default_output
($filename);
843 my $code = _run_command
(@_);
844 &detach_default_output
;
845 print "run_command_with_output returned $code.\n" if $debug;
850 # performs the equivalent of an "rm -rf" on the first argument. Like
851 # rm, if the path ends in /, leaves the (now empty) directory; otherwise
854 sub remove_directory_tree
856 local ($targetdir) = @_;
857 local ($nuketop) = 1;
860 $ch = substr ($targetdir, length ($targetdir) - 1);
861 if ($ch eq "/" || $ch eq $pathsep)
863 $targetdir = substr ($targetdir, 0, length ($targetdir) - 1);
872 &remove_directory_tree_inner
("RDT00", $targetdir) || return 0;
875 rmdir $targetdir || return 0;
881 sub remove_directory_tree_inner
883 local ($dirhandle, $targetdir) = @_;
885 local ($subdirhandle);
887 opendir ($dirhandle, $targetdir) || return 0;
888 $subdirhandle = $dirhandle;
890 while ($object = readdir ($dirhandle))
892 if ($object =~ /^(\.\.?|CVS|RCS)$/)
897 $object = "$targetdir$pathsep$object";
900 if (-d _
&& &remove_directory_tree_inner
($subdirhandle, $object))
902 rmdir $object || return 0;
906 unlink $object || return 0;
909 closedir ($dirhandle);
913 # We used to use this behavior for this function:
917 # local (@filenames) = @_;
918 # local ($now) = time;
921 # foreach $file (@filenames)
923 # utime ($now, $now, $file)
924 # || (open (TOUCHFD, ">> $file") && close (TOUCHFD))
925 # || &error ("Couldn't touch $file: $!\n", 1);
930 # But this behaves badly on networked filesystems where the time is
931 # skewed, because it sets the time of the file based on the _local_
932 # host. Normally when you modify a file, it's the _remote_ host that
933 # determines the modtime, based on _its_ clock. So, instead, now we open
934 # the file and write something into it to force the remote host to set
935 # the modtime correctly according to its clock.
943 (open(T
, ">> $file") && print(T
"\n") && close(T
))
944 || &error
("Couldn't touch $file: $!\n", 1);
948 # Touch with a time offset. To DTRT, call touch() then use stat() to get the
949 # access/mod time for each file and apply the offset.
953 local ($off) = shift;
958 local (@s) = stat($_[0]);
960 utime($s[8]+$off, $s[9]+$off, @_);
963 # open a file, write some stuff to it, and close it.
967 local ($filename, @lines) = @_;
969 open (CF
, "> $filename") || &error
("Couldn't open $filename: $!\n", 1);
970 foreach $line (@lines)
977 # create a directory tree described by an associative array, wherein each
978 # key is a relative pathname (using slashes) and its associated value is
980 # DIR indicates a directory
981 # FILE:contents indicates a file, which should contain contents +\n
982 # LINK:target indicates a symlink, pointing to $basedir/target
983 # The first argument is the dir under which the structure will be created
984 # (the dir will be made and/or cleaned if necessary); the second argument
985 # is the associative array.
989 local ($basedir, %dirtree) = @_;
992 &remove_directory_tree
("$basedir");
993 mkdir ($basedir, 0777) || &error
("Couldn't mkdir $basedir: $!\n", 1);
995 foreach $path (sort keys (%dirtree))
997 if ($dirtree {$path} =~ /^DIR$/)
999 mkdir ("$basedir/$path", 0777)
1000 || &error
("Couldn't mkdir $basedir/$path: $!\n", 1);
1002 elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
1004 &create_file
("$basedir/$path", $1 . "\n");
1006 elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
1008 symlink ("$basedir/$1", "$basedir/$path")
1009 || &error
("Couldn't symlink $basedir/$path -> $basedir/$1: $!\n", 1);
1013 &error
("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
1016 if ($just_setup_tree)
1018 die "Tree is setup...\n";
1022 # compare a directory tree with an associative array in the format used
1023 # by create_dir_tree, above.
1024 # The first argument is the dir under which the structure should be found;
1025 # the second argument is the associative array.
1027 sub compare_dir_tree
1029 local ($basedir, %dirtree) = @_;
1035 local ($fulltarget);
1040 opendir (DIR
, $basedir) || &error
("Couldn't open $basedir: $!\n", 1);
1041 @allfiles = grep (!/^(\.\.?|CVS|RCS)$/, readdir (DIR
) );
1045 print "dirtree: (%dirtree)\n$basedir: (@allfiles)\n";
1048 foreach $path (sort keys (%dirtree))
1052 print "Checking $path ($dirtree{$path}).\n";
1056 foreach $i (0 .. $#allfiles)
1058 if ($allfiles[$i] eq $path)
1060 splice (@allfiles, $i, 1); # delete it
1063 print " Zapped $path; files now (@allfiles).\n";
1065 lstat ("$basedir/$path");
1073 print "compare_dir_tree: $path does not exist.\n";
1078 if ($dirtree {$path} =~ /^DIR$/)
1080 if (-d _
&& opendir (DIR
, "$basedir/$path") )
1082 @files = readdir (DIR
);
1084 @files = grep (!/^(\.\.?|CVS|RCS)$/ && ($_ = "$path/$_"), @files);
1085 push (@allfiles, @files);
1088 print " Read in $path; new files (@files).\n";
1093 print "compare_dir_tree: $path is not a dir.\n";
1097 elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
1101 print "compare_dir_tree: $path is not a file.\n";
1108 $contents = &read_file_into_string
("$basedir/$path");
1109 if ($contents ne "$1\n")
1111 print "compare_dir_tree: $path contains wrong stuff."
1112 . " Is:\n$contentsShould be:\n$1\n";
1117 elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
1122 print "compare_dir_tree: $path is not a link.\n";
1127 $contents = readlink ("$basedir/$path");
1128 $contents =~ tr/>/\//;
1129 $fulltarget = "$basedir/$target";
1130 $fulltarget =~ tr/>/\//;
1131 if (!($contents =~ /$fulltarget$/))
1135 $target = $fulltarget;
1137 print "compare_dir_tree: $path should be link to $target, "
1138 . "not $contents.\n";
1144 &error
("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
1150 print "leftovers: (@allfiles).\n";
1153 foreach $file (@allfiles)
1155 print "compare_dir_tree: $file should not exist.\n";
1162 # this subroutine generates the numeric suffix used to keep tmp filenames,
1163 # log filenames, etc., unique. If the number passed in is 1, then a null
1164 # string is returned; otherwise, we return ".n", where n + 1 is the number
1172 return "$extext$num";
1178 # This subroutine returns a log filename with a number appended to
1179 # the end corresponding to how many logfiles have been created in the
1180 # current running test. An optional parameter may be passed (0 or 1).
1181 # If a 1 is passed, then it does NOT increment the logfile counter
1182 # and returns the name of the latest logfile. If either no parameter
1183 # is passed at all or a 0 is passed, then the logfile counter is
1184 # incremented and the new name is returned.
1188 local($no_increment) = @_;
1190 $num_of_logfiles += !$no_increment;
1192 return ($log_filename . &num_suffix
($num_of_logfiles));
1195 # This subroutine returns a base (answer) filename with a number
1196 # appended to the end corresponding to how many logfiles (and thus
1197 # base files) have been created in the current running test.
1198 # NO PARAMETERS ARE PASSED TO THIS SUBROUTINE.
1202 return ($base_filename . &num_suffix
($num_of_logfiles));
1205 # This subroutine returns a difference filename with a number appended
1206 # to the end corresponding to how many logfiles (and thus diff files)
1207 # have been created in the current running test.
1211 return ($diff_filename . &num_suffix
($num_of_logfiles));
1214 # This subroutine returns a command filename with a number appended
1215 # to the end corresponding to how many logfiles (and thus command files)
1216 # have been created in the current running test.
1220 return ($run_filename . &num_suffix
($num_of_logfiles));
1223 # just like logfile, only a generic tmp filename for use by the test.
1224 # they are automatically cleaned up unless -keep was used, or the test fails.
1225 # Pass an argument of 1 to return the same filename as the previous call.
1229 local($no_increment) = @_;
1231 $num_of_tmpfiles += !$no_increment;
1233 return ($tmp_filename . &num_suffix
($num_of_tmpfiles));