| 1 | #!/usr/bin/perl
|
|---|
| 2 | # -*-perl-*-
|
|---|
| 3 |
|
|---|
| 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
|
|---|
| 8 |
|
|---|
| 9 | # Test driver routines used by a number of test suites, including
|
|---|
| 10 | # those for SCS, make, roll_dir, and scan_deps (?).
|
|---|
| 11 |
|
|---|
| 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.
|
|---|
| 14 |
|
|---|
| 15 | # $Id: test_driver.pl,v 1.14 2005/02/28 07:48:23 psmith Exp $
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | # The number of test categories we've run
|
|---|
| 19 | $categories_run = 0;
|
|---|
| 20 | # The number of test categroies that have passed
|
|---|
| 21 | $categories_passed = 0;
|
|---|
| 22 | # The total number of individual tests that have been run
|
|---|
| 23 | $total_tests_run = 0;
|
|---|
| 24 | # The total number of individual tests that have passed
|
|---|
| 25 | $total_tests_passed = 0;
|
|---|
| 26 | # The number of tests in this category that have been run
|
|---|
| 27 | $tests_run = 0;
|
|---|
| 28 | # The number of tests in this category that have passed
|
|---|
| 29 | $tests_passed = 0;
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | # Yeesh. This whole test environment is such a hack!
|
|---|
| 33 | $test_passed = 1;
|
|---|
| 34 |
|
|---|
| 35 | sub toplevel
|
|---|
| 36 | {
|
|---|
| 37 | # Get a clean environment
|
|---|
| 38 |
|
|---|
| 39 | %makeENV = ();
|
|---|
| 40 |
|
|---|
| 41 | # Pull in benign variables from the user's environment
|
|---|
| 42 | #
|
|---|
| 43 | foreach (# UNIX-specific things
|
|---|
| 44 | 'TZ', 'LANG', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',
|
|---|
| 45 | # Purify things
|
|---|
| 46 | 'PURIFYOPTIONS',
|
|---|
| 47 | # Windows NT-specific stuff
|
|---|
| 48 | 'Path', 'SystemRoot',
|
|---|
| 49 | # DJGPP-specific stuff
|
|---|
| 50 | 'DJDIR', 'DJGPP', 'SHELL', 'COMSPEC', 'HOSTNAME', 'LFN',
|
|---|
| 51 | 'FNCASE', '387', 'EMU387', 'GROUP'
|
|---|
| 52 | ) {
|
|---|
| 53 | $makeENV{$_} = $ENV{$_} if $ENV{$_};
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | # Replace the environment with the new one
|
|---|
| 57 | #
|
|---|
| 58 | %origENV = %ENV;
|
|---|
| 59 |
|
|---|
| 60 | # We used to say "%ENV = ();" but this doesn't work in Perl 5.000
|
|---|
| 61 | # through Perl 5.004. It was fixed in Perl 5.004_01, but we don't
|
|---|
| 62 | # want to require that here, so just delete each one individually.
|
|---|
| 63 |
|
|---|
| 64 | foreach $v (keys %ENV) {
|
|---|
| 65 | delete $ENV{$v};
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | %ENV = %makeENV;
|
|---|
| 69 |
|
|---|
| 70 | $| = 1; # unbuffered output
|
|---|
| 71 |
|
|---|
| 72 | $debug = 0; # debug flag
|
|---|
| 73 | $profile = 0; # profiling flag
|
|---|
| 74 | $verbose = 0; # verbose mode flag
|
|---|
| 75 | $detail = 0; # detailed verbosity
|
|---|
| 76 | $keep = 0; # keep temp files around
|
|---|
| 77 | $workdir = "work"; # The directory where the test will start running
|
|---|
| 78 | $scriptdir = "scripts"; # The directory where we find the test scripts
|
|---|
| 79 | $tmpfilesuffix = "t"; # the suffix used on tmpfiles
|
|---|
| 80 | $default_output_stack_level = 0; # used by attach_default_output, etc.
|
|---|
| 81 | $default_input_stack_level = 0; # used by attach_default_input, etc.
|
|---|
| 82 | $cwd = "."; # don't we wish we knew
|
|---|
| 83 | $cwdslash = ""; # $cwd . $pathsep, but "" rather than "./"
|
|---|
| 84 |
|
|---|
| 85 | &get_osname; # sets $osname, $vos, $pathsep, and $short_filenames
|
|---|
| 86 |
|
|---|
| 87 | &set_defaults; # suite-defined
|
|---|
| 88 |
|
|---|
| 89 | &parse_command_line (@ARGV);
|
|---|
| 90 |
|
|---|
| 91 | print "OS name = `$osname'\n" if $debug;
|
|---|
| 92 |
|
|---|
| 93 | $workpath = "$cwdslash$workdir";
|
|---|
| 94 | $scriptpath = "$cwdslash$scriptdir";
|
|---|
| 95 |
|
|---|
| 96 | &set_more_defaults; # suite-defined
|
|---|
| 97 |
|
|---|
| 98 | &print_banner;
|
|---|
| 99 |
|
|---|
| 100 | if (-d $workpath)
|
|---|
| 101 | {
|
|---|
| 102 | print "Clearing $workpath...\n";
|
|---|
| 103 | &remove_directory_tree("$workpath/")
|
|---|
| 104 | || &error ("Couldn't wipe out $workpath\n");
|
|---|
| 105 | }
|
|---|
| 106 | else
|
|---|
| 107 | {
|
|---|
| 108 | mkdir ($workpath, 0777) || &error ("Couldn't mkdir $workpath: $!\n");
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | if (!-d $scriptpath)
|
|---|
| 112 | {
|
|---|
| 113 | &error ("Failed to find $scriptpath containing perl test scripts.\n");
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | if (@TESTS)
|
|---|
| 117 | {
|
|---|
| 118 | print "Making work dirs...\n";
|
|---|
| 119 | foreach $test (@TESTS)
|
|---|
| 120 | {
|
|---|
| 121 | if ($test =~ /^([^\/]+)\//)
|
|---|
| 122 | {
|
|---|
| 123 | $dir = $1;
|
|---|
| 124 | push (@rmdirs, $dir);
|
|---|
| 125 | -d "$workpath/$dir"
|
|---|
| 126 | || mkdir ("$workpath/$dir", 0777)
|
|---|
| 127 | || &error ("Couldn't mkdir $workpath/$dir: $!\n");
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | else
|
|---|
| 132 | {
|
|---|
| 133 | print "Finding tests...\n";
|
|---|
| 134 | opendir (SCRIPTDIR, $scriptpath)
|
|---|
| 135 | || &error ("Couldn't opendir $scriptpath: $!\n");
|
|---|
| 136 | @dirs = grep (!/^(\.\.?|CVS|RCS)$/, readdir (SCRIPTDIR) );
|
|---|
| 137 | closedir (SCRIPTDIR);
|
|---|
| 138 | foreach $dir (@dirs)
|
|---|
| 139 | {
|
|---|
| 140 | next if ($dir =~ /^\.\.?$/ || $dir eq 'CVS' || $dir eq 'RCS'
|
|---|
| 141 | || ! -d "$scriptpath/$dir");
|
|---|
| 142 | push (@rmdirs, $dir);
|
|---|
| 143 | mkdir ("$workpath/$dir", 0777)
|
|---|
| 144 | || &error ("Couldn't mkdir $workpath/$dir: $!\n");
|
|---|
| 145 | opendir (SCRIPTDIR, "$scriptpath/$dir")
|
|---|
| 146 | || &error ("Couldn't opendir $scriptpath/$dir: $!\n");
|
|---|
| 147 | @files = grep (!/^(\.\.?|CVS|RCS)$/, readdir (SCRIPTDIR) );
|
|---|
| 148 | closedir (SCRIPTDIR);
|
|---|
| 149 | foreach $test (@files)
|
|---|
| 150 | {
|
|---|
| 151 | next if $test =~ /~$/ || -d $test;
|
|---|
| 152 | push (@TESTS, "$dir/$test");
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | if (@TESTS == 0)
|
|---|
| 158 | {
|
|---|
| 159 | &error ("\nNo tests in $scriptpath, and none were specified.\n");
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | print "\n";
|
|---|
| 163 |
|
|---|
| 164 | &run_each_test;
|
|---|
| 165 |
|
|---|
| 166 | foreach $dir (@rmdirs)
|
|---|
| 167 | {
|
|---|
| 168 | rmdir ("$workpath/$dir");
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | $| = 1;
|
|---|
| 172 |
|
|---|
| 173 | $categories_failed = $categories_run - $categories_passed;
|
|---|
| 174 | $total_tests_failed = $total_tests_run - $total_tests_passed;
|
|---|
| 175 |
|
|---|
| 176 | if ($total_tests_failed)
|
|---|
| 177 | {
|
|---|
| 178 | print "\n$total_tests_failed Test";
|
|---|
| 179 | print "s" unless $total_tests_failed == 1;
|
|---|
| 180 | print " in $categories_failed Categor";
|
|---|
| 181 | print ($categories_failed == 1 ? "y" : "ies");
|
|---|
| 182 | print " Failed (See .$diffext files in $workdir dir for details) :-(\n\n";
|
|---|
| 183 | return 0;
|
|---|
| 184 | }
|
|---|
| 185 | else
|
|---|
| 186 | {
|
|---|
| 187 | print "\n$total_tests_passed Test";
|
|---|
| 188 | print "s" unless $total_tests_passed == 1;
|
|---|
| 189 | print " in $categories_passed Categor";
|
|---|
| 190 | print ($categories_passed == 1 ? "y" : "ies");
|
|---|
| 191 | print " Complete ... No Failures :-)\n\n";
|
|---|
| 192 | return 1;
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | sub get_osname
|
|---|
| 197 | {
|
|---|
| 198 | # Set up an initial value. In perl5 we can do it the easy way.
|
|---|
| 199 | #
|
|---|
| 200 | $osname = defined($^O) ? $^O : '';
|
|---|
| 201 |
|
|---|
| 202 | # See if the filesystem supports long file names with multiple
|
|---|
| 203 | # dots. DOS doesn't.
|
|---|
| 204 | $short_filenames = 0;
|
|---|
| 205 | (open (TOUCHFD, "> fancy.file.name") && close (TOUCHFD))
|
|---|
| 206 | || ($short_filenames = 1);
|
|---|
| 207 | unlink ("fancy.file.name") || ($short_filenames = 1);
|
|---|
| 208 |
|
|---|
| 209 | if (! $short_filenames) {
|
|---|
| 210 | # Thanks go to meyering@cs.utexas.edu (Jim Meyering) for suggesting a
|
|---|
| 211 | # better way of doing this. (We used to test for existence of a /mnt
|
|---|
| 212 | # dir, but that apparently fails on an SGI Indigo (whatever that is).)
|
|---|
| 213 | # Because perl on VOS translates /'s to >'s, we need to test for
|
|---|
| 214 | # VOSness rather than testing for Unixness (ie, try > instead of /).
|
|---|
| 215 |
|
|---|
| 216 | mkdir (".ostest", 0777) || &error ("Couldn't create .ostest: $!\n", 1);
|
|---|
| 217 | open (TOUCHFD, "> .ostest>ick") && close (TOUCHFD);
|
|---|
| 218 | chdir (".ostest") || &error ("Couldn't chdir to .ostest: $!\n", 1);
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | if (! $short_filenames && -f "ick")
|
|---|
| 222 | {
|
|---|
| 223 | $osname = "vos";
|
|---|
| 224 | $vos = 1;
|
|---|
| 225 | $pathsep = ">";
|
|---|
| 226 | }
|
|---|
| 227 | else
|
|---|
| 228 | {
|
|---|
| 229 | # the following is regrettably knarly, but it seems to be the only way
|
|---|
| 230 | # to not get ugly error messages if uname can't be found.
|
|---|
| 231 | # Hmmm, BSD/OS 2.0's uname -a is excessively verbose. Let's try it
|
|---|
| 232 | # with switches first.
|
|---|
| 233 | eval "chop (\$osname = `sh -c 'uname -nmsr 2>&1'`)";
|
|---|
| 234 | if ($osname =~ /not found/i)
|
|---|
| 235 | {
|
|---|
| 236 | $osname = "(something unixy with no uname)";
|
|---|
| 237 | }
|
|---|
| 238 | elsif ($@ ne "" || $?)
|
|---|
| 239 | {
|
|---|
| 240 | eval "chop (\$osname = `sh -c 'uname -a 2>&1'`)";
|
|---|
| 241 | if ($@ ne "" || $?)
|
|---|
| 242 | {
|
|---|
| 243 | $osname = "(something unixy)";
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 | $vos = 0;
|
|---|
| 247 | $pathsep = "/";
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | if (! $short_filenames) {
|
|---|
| 251 | chdir ("..") || &error ("Couldn't chdir to ..: $!\n", 1);
|
|---|
| 252 | unlink (".ostest>ick");
|
|---|
| 253 | rmdir (".ostest") || &error ("Couldn't rmdir .ostest: $!\n", 1);
|
|---|
| 254 | }
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | sub parse_command_line
|
|---|
| 258 | {
|
|---|
| 259 | @argv = @_;
|
|---|
| 260 |
|
|---|
| 261 | # use @ARGV if no args were passed in
|
|---|
| 262 |
|
|---|
| 263 | if (@argv == 0)
|
|---|
| 264 | {
|
|---|
| 265 | @argv = @ARGV;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | # look at each option; if we don't recognize it, maybe the suite-specific
|
|---|
| 269 | # command line parsing code will...
|
|---|
| 270 |
|
|---|
| 271 | while (@argv)
|
|---|
| 272 | {
|
|---|
| 273 | $option = shift @argv;
|
|---|
| 274 | if ($option =~ /^-debug$/i)
|
|---|
| 275 | {
|
|---|
| 276 | print "\nDEBUG ON\n";
|
|---|
| 277 | $debug = 1;
|
|---|
| 278 | }
|
|---|
| 279 | elsif ($option =~ /^-usage$/i)
|
|---|
| 280 | {
|
|---|
| 281 | &print_usage;
|
|---|
| 282 | exit 0;
|
|---|
| 283 | }
|
|---|
| 284 | elsif ($option =~ /^-(h|help)$/i)
|
|---|
| 285 | {
|
|---|
| 286 | &print_help;
|
|---|
| 287 | exit 0;
|
|---|
| 288 | }
|
|---|
| 289 | elsif ($option =~ /^-profile$/i)
|
|---|
| 290 | {
|
|---|
| 291 | $profile = 1;
|
|---|
| 292 | }
|
|---|
| 293 | elsif ($option =~ /^-verbose$/i)
|
|---|
| 294 | {
|
|---|
| 295 | $verbose = 1;
|
|---|
| 296 | }
|
|---|
| 297 | elsif ($option =~ /^-detail$/i)
|
|---|
| 298 | {
|
|---|
| 299 | $detail = 1;
|
|---|
| 300 | $verbose = 1;
|
|---|
| 301 | }
|
|---|
| 302 | elsif ($option =~ /^-keep$/i)
|
|---|
| 303 | {
|
|---|
| 304 | $keep = 1;
|
|---|
| 305 | }
|
|---|
| 306 | elsif (&valid_option($option))
|
|---|
| 307 | {
|
|---|
| 308 | # The suite-defined subroutine takes care of the option
|
|---|
| 309 | }
|
|---|
| 310 | elsif ($option =~ /^-/)
|
|---|
| 311 | {
|
|---|
| 312 | print "Invalid option: $option\n";
|
|---|
| 313 | &print_usage;
|
|---|
| 314 | exit 0;
|
|---|
| 315 | }
|
|---|
| 316 | else # must be the name of a test
|
|---|
| 317 | {
|
|---|
| 318 | $option =~ s/\.pl$//;
|
|---|
| 319 | push(@TESTS,$option);
|
|---|
| 320 | }
|
|---|
| 321 | }
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | sub max
|
|---|
| 325 | {
|
|---|
| 326 | local($num) = shift @_;
|
|---|
| 327 | local($newnum);
|
|---|
| 328 |
|
|---|
| 329 | while (@_)
|
|---|
| 330 | {
|
|---|
| 331 | $newnum = shift @_;
|
|---|
| 332 | if ($newnum > $num)
|
|---|
| 333 | {
|
|---|
| 334 | $num = $newnum;
|
|---|
| 335 | }
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | return $num;
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | sub print_centered
|
|---|
| 342 | {
|
|---|
| 343 | local($width, $string) = @_;
|
|---|
| 344 | local($pad);
|
|---|
| 345 |
|
|---|
| 346 | if (length ($string))
|
|---|
| 347 | {
|
|---|
| 348 | $pad = " " x ( ($width - length ($string) + 1) / 2);
|
|---|
| 349 | print "$pad$string";
|
|---|
| 350 | }
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | sub print_banner
|
|---|
| 354 | {
|
|---|
| 355 | local($info);
|
|---|
| 356 | local($line);
|
|---|
| 357 | local($len);
|
|---|
| 358 |
|
|---|
| 359 | $info = "Running tests for $testee on $osname\n"; # $testee is suite-defined
|
|---|
| 360 | $len = &max (length ($line), length ($testee_version),
|
|---|
| 361 | length ($banner_info), 73) + 5;
|
|---|
| 362 | $line = ("-" x $len) . "\n";
|
|---|
| 363 | if ($len < 78)
|
|---|
| 364 | {
|
|---|
| 365 | $len = 78;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | &print_centered ($len, $line);
|
|---|
| 369 | &print_centered ($len, $info);
|
|---|
| 370 | &print_centered ($len, $testee_version); # suite-defined
|
|---|
| 371 | &print_centered ($len, $banner_info); # suite-defined
|
|---|
| 372 | &print_centered ($len, $line);
|
|---|
| 373 | print "\n";
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | sub run_each_test
|
|---|
| 377 | {
|
|---|
| 378 | $categories_run = 0;
|
|---|
| 379 |
|
|---|
| 380 | foreach $testname (sort @TESTS)
|
|---|
| 381 | {
|
|---|
| 382 | ++$categories_run;
|
|---|
| 383 | $suite_passed = 1; # reset by test on failure
|
|---|
| 384 | $num_of_logfiles = 0;
|
|---|
| 385 | $num_of_tmpfiles = 0;
|
|---|
| 386 | $description = "";
|
|---|
| 387 | $details = "";
|
|---|
| 388 | $old_makefile = undef;
|
|---|
| 389 | $testname =~ s/^$scriptpath$pathsep//;
|
|---|
| 390 | $perl_testname = "$scriptpath$pathsep$testname";
|
|---|
| 391 | $testname =~ s/(\.pl|\.perl)$//;
|
|---|
| 392 | $testpath = "$workpath$pathsep$testname";
|
|---|
| 393 | # Leave enough space in the extensions to append a number, even
|
|---|
| 394 | # though it needs to fit into 8+3 limits.
|
|---|
| 395 | if ($short_filenames) {
|
|---|
| 396 | $logext = 'l';
|
|---|
| 397 | $diffext = 'd';
|
|---|
| 398 | $baseext = 'b';
|
|---|
| 399 | $extext = '';
|
|---|
| 400 | }
|
|---|
| 401 | else {
|
|---|
| 402 | $logext = 'log';
|
|---|
| 403 | $diffext = 'diff';
|
|---|
| 404 | $baseext = 'base';
|
|---|
| 405 | $extext = '.';
|
|---|
| 406 | }
|
|---|
| 407 | $log_filename = "$testpath.$logext";
|
|---|
| 408 | $diff_filename = "$testpath.$diffext";
|
|---|
| 409 | $base_filename = "$testpath.$baseext";
|
|---|
| 410 | $tmp_filename = "$testpath.$tmpfilesuffix";
|
|---|
| 411 |
|
|---|
| 412 | &setup_for_test; # suite-defined
|
|---|
| 413 |
|
|---|
| 414 | $output = "........................................................ ";
|
|---|
| 415 |
|
|---|
| 416 | substr($output,0,length($testname)) = "$testname ";
|
|---|
| 417 |
|
|---|
| 418 | print $output;
|
|---|
| 419 |
|
|---|
| 420 | # Run the actual test!
|
|---|
| 421 | $tests_run = 0;
|
|---|
| 422 | $tests_passed = 0;
|
|---|
| 423 | $code = do $perl_testname;
|
|---|
| 424 |
|
|---|
| 425 | $total_tests_run += $tests_run;
|
|---|
| 426 | $total_tests_passed += $tests_passed;
|
|---|
| 427 |
|
|---|
| 428 | # How did it go?
|
|---|
| 429 | if (!defined($code))
|
|---|
| 430 | {
|
|---|
| 431 | $suite_passed = 0;
|
|---|
| 432 | if (length ($@))
|
|---|
| 433 | {
|
|---|
| 434 | warn "\n*** Test died ($testname): $@\n";
|
|---|
| 435 | }
|
|---|
| 436 | else
|
|---|
| 437 | {
|
|---|
| 438 | warn "\n*** Couldn't run $perl_testname\n";
|
|---|
| 439 | }
|
|---|
| 440 | }
|
|---|
| 441 | elsif ($code == -1) {
|
|---|
| 442 | $suite_passed = 0;
|
|---|
| 443 | }
|
|---|
| 444 | elsif ($code != 1 && $code != -1) {
|
|---|
| 445 | $suite_passed = 0;
|
|---|
| 446 | warn "\n*** Test returned $code\n";
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | if ($suite_passed) {
|
|---|
| 450 | ++$categories_passed;
|
|---|
| 451 | $status = "ok ($tests_passed passed)";
|
|---|
| 452 | for ($i = $num_of_tmpfiles; $i; $i--)
|
|---|
| 453 | {
|
|---|
| 454 | &rmfiles ($tmp_filename . &num_suffix ($i) );
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | for ($i = $num_of_logfiles ? $num_of_logfiles : 1; $i; $i--)
|
|---|
| 458 | {
|
|---|
| 459 | &rmfiles ($log_filename . &num_suffix ($i) );
|
|---|
| 460 | &rmfiles ($base_filename . &num_suffix ($i) );
|
|---|
| 461 | }
|
|---|
| 462 | }
|
|---|
| 463 | elsif ($code > 0) {
|
|---|
| 464 | $status = "FAILED ($tests_passed/$tests_run passed)";
|
|---|
| 465 | }
|
|---|
| 466 | elsif ($code < 0) {
|
|---|
| 467 | $status = "N/A";
|
|---|
| 468 | --$categories_run;
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | # If the verbose option has been specified, then a short description
|
|---|
| 472 | # of each test is printed before displaying the results of each test
|
|---|
| 473 | # describing WHAT is being tested.
|
|---|
| 474 |
|
|---|
| 475 | if ($verbose)
|
|---|
| 476 | {
|
|---|
| 477 | if ($detail)
|
|---|
| 478 | {
|
|---|
| 479 | print "\nWHAT IS BEING TESTED\n";
|
|---|
| 480 | print "--------------------";
|
|---|
| 481 | }
|
|---|
| 482 | print "\n\n$description\n\n";
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 | # If the detail option has been specified, then the details of HOW
|
|---|
| 486 | # the test is testing what it says it is testing in the verbose output
|
|---|
| 487 | # will be displayed here before the results of the test are displayed.
|
|---|
| 488 |
|
|---|
| 489 | if ($detail)
|
|---|
| 490 | {
|
|---|
| 491 | print "\nHOW IT IS TESTED\n";
|
|---|
| 492 | print "----------------";
|
|---|
| 493 | print "\n\n$details\n\n";
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | print "$status\n";
|
|---|
| 497 | }
|
|---|
| 498 | }
|
|---|
| 499 |
|
|---|
| 500 | # If the keep flag is not set, this subroutine deletes all filenames that
|
|---|
| 501 | # are sent to it.
|
|---|
| 502 |
|
|---|
| 503 | sub rmfiles
|
|---|
| 504 | {
|
|---|
| 505 | local(@files) = @_;
|
|---|
| 506 |
|
|---|
| 507 | if (!$keep)
|
|---|
| 508 | {
|
|---|
| 509 | return (unlink @files);
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | return 1;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | sub print_standard_usage
|
|---|
| 516 | {
|
|---|
| 517 | local($plname,@moreusage) = @_;
|
|---|
| 518 | local($line);
|
|---|
| 519 |
|
|---|
| 520 | print "Usage: perl $plname [testname] [-verbose] [-detail] [-keep]\n";
|
|---|
| 521 | print " [-profile] [-usage] [-help] "
|
|---|
| 522 | . "[-debug]\n";
|
|---|
| 523 | foreach $line (@moreusage)
|
|---|
| 524 | {
|
|---|
| 525 | print " $line\n";
|
|---|
| 526 | }
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | sub print_standard_help
|
|---|
| 530 | {
|
|---|
| 531 | local(@morehelp) = @_;
|
|---|
| 532 | local($line);
|
|---|
| 533 | local($tline);
|
|---|
| 534 | local($t) = " ";
|
|---|
| 535 |
|
|---|
| 536 | $line = "Test Driver For $testee";
|
|---|
| 537 | print "$line\n";
|
|---|
| 538 | $line = "=" x length ($line);
|
|---|
| 539 | print "$line\n";
|
|---|
| 540 |
|
|---|
| 541 | &print_usage;
|
|---|
| 542 |
|
|---|
| 543 | print "\ntestname\n"
|
|---|
| 544 | . "${t}You may, if you wish, run only ONE test if you know the name\n"
|
|---|
| 545 | . "${t}of that test and specify this name anywhere on the command\n"
|
|---|
| 546 | . "${t}line. Otherwise ALL existing tests in the scripts directory\n"
|
|---|
| 547 | . "${t}will be run.\n"
|
|---|
| 548 | . "-verbose\n"
|
|---|
| 549 | . "${t}If this option is given, a description of every test is\n"
|
|---|
| 550 | . "${t}displayed before the test is run. (Not all tests may have\n"
|
|---|
| 551 | . "${t}descriptions at this time)\n"
|
|---|
| 552 | . "-detail\n"
|
|---|
| 553 | . "${t}If this option is given, a detailed description of every\n"
|
|---|
| 554 | . "${t}test is displayed before the test is run. (Not all tests\n"
|
|---|
| 555 | . "${t}have descriptions at this time)\n"
|
|---|
| 556 | . "-profile\n"
|
|---|
| 557 | . "${t}If this option is given, then the profile file\n"
|
|---|
| 558 | . "${t}is added to other profiles every time $testee is run.\n"
|
|---|
| 559 | . "${t}This option only works on VOS at this time.\n"
|
|---|
| 560 | . "-keep\n"
|
|---|
| 561 | . "${t}You may give this option if you DO NOT want ANY\n"
|
|---|
| 562 | . "${t}of the files generated by the tests to be deleted. \n"
|
|---|
| 563 | . "${t}Without this option, all files generated by the test will\n"
|
|---|
| 564 | . "${t}be deleted IF THE TEST PASSES.\n"
|
|---|
| 565 | . "-debug\n"
|
|---|
| 566 | . "${t}Use this option if you would like to see all of the system\n"
|
|---|
| 567 | . "${t}calls issued and their return status while running the tests\n"
|
|---|
| 568 | . "${t}This can be helpful if you're having a problem adding a test\n"
|
|---|
| 569 | . "${t}to the suite, or if the test fails!\n";
|
|---|
| 570 |
|
|---|
| 571 | foreach $line (@morehelp)
|
|---|
| 572 | {
|
|---|
| 573 | $tline = $line;
|
|---|
| 574 | if (substr ($tline, 0, 1) eq "\t")
|
|---|
| 575 | {
|
|---|
| 576 | substr ($tline, 0, 1) = $t;
|
|---|
| 577 | }
|
|---|
| 578 | print "$tline\n";
|
|---|
| 579 | }
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | #######################################################################
|
|---|
| 583 | ########### Generic Test Driver Subroutines ###########
|
|---|
| 584 | #######################################################################
|
|---|
| 585 |
|
|---|
| 586 | sub get_caller
|
|---|
| 587 | {
|
|---|
| 588 | local($depth);
|
|---|
| 589 | local($package);
|
|---|
| 590 | local($filename);
|
|---|
| 591 | local($linenum);
|
|---|
| 592 |
|
|---|
| 593 | $depth = defined ($_[0]) ? $_[0] : 1;
|
|---|
| 594 | ($package, $filename, $linenum) = caller ($depth + 1);
|
|---|
| 595 | return "$filename: $linenum";
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| 598 | sub error
|
|---|
| 599 | {
|
|---|
| 600 | local($message) = $_[0];
|
|---|
| 601 | local($caller) = &get_caller (1);
|
|---|
| 602 |
|
|---|
| 603 | if (defined ($_[1]))
|
|---|
| 604 | {
|
|---|
| 605 | $caller = &get_caller ($_[1] + 1) . " -> $caller";
|
|---|
| 606 | }
|
|---|
| 607 |
|
|---|
| 608 | die "$caller: $message";
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | sub compare_output
|
|---|
| 612 | {
|
|---|
| 613 | local($answer,$logfile) = @_;
|
|---|
| 614 | local($slurp, $answer_matched) = ('', 0);
|
|---|
| 615 |
|
|---|
| 616 | print "Comparing Output ........ " if $debug;
|
|---|
| 617 |
|
|---|
| 618 | $slurp = &read_file_into_string ($logfile);
|
|---|
| 619 |
|
|---|
| 620 | # For make, get rid of any time skew error before comparing--too bad this
|
|---|
| 621 | # has to go into the "generic" driver code :-/
|
|---|
| 622 | $slurp =~ s/^.*modification time .*in the future.*\n//gm;
|
|---|
| 623 | $slurp =~ s/^.*Clock skew detected.*\n//gm;
|
|---|
| 624 |
|
|---|
| 625 | ++$tests_run;
|
|---|
| 626 |
|
|---|
| 627 | if ($slurp eq $answer) {
|
|---|
| 628 | $answer_matched = 1;
|
|---|
| 629 | } else {
|
|---|
| 630 | # See if it is a slash or CRLF problem
|
|---|
| 631 | local ($answer_mod) = $answer;
|
|---|
| 632 |
|
|---|
| 633 | $answer_mod =~ tr,\\,/,;
|
|---|
| 634 | $answer_mod =~ s,\r\n,\n,gs;
|
|---|
| 635 |
|
|---|
| 636 | $slurp =~ tr,\\,/,;
|
|---|
| 637 | $slurp =~ s,\r\n,\n,gs;
|
|---|
| 638 |
|
|---|
| 639 | $answer_matched = ($slurp eq $answer_mod);
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | if ($answer_matched && $test_passed)
|
|---|
| 643 | {
|
|---|
| 644 | print "ok\n" if $debug;
|
|---|
| 645 | ++$tests_passed;
|
|---|
| 646 | return 1;
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 | if (! $answer_matched) {
|
|---|
| 650 | print "DIFFERENT OUTPUT\n" if $debug;
|
|---|
| 651 |
|
|---|
| 652 | &create_file (&get_basefile, $answer);
|
|---|
| 653 |
|
|---|
| 654 | print "\nCreating Difference File ...\n" if $debug;
|
|---|
| 655 |
|
|---|
| 656 | # Create the difference file
|
|---|
| 657 |
|
|---|
| 658 | local($command) = "diff -c " . &get_basefile . " " . $logfile;
|
|---|
| 659 | &run_command_with_output(&get_difffile,$command);
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | $suite_passed = 0;
|
|---|
| 663 | return 0;
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | sub read_file_into_string
|
|---|
| 667 | {
|
|---|
| 668 | local($filename) = @_;
|
|---|
| 669 | local($oldslash) = $/;
|
|---|
| 670 |
|
|---|
| 671 | undef $/;
|
|---|
| 672 |
|
|---|
| 673 | open (RFISFILE, $filename) || return "";
|
|---|
| 674 | local ($slurp) = <RFISFILE>;
|
|---|
| 675 | close (RFISFILE);
|
|---|
| 676 |
|
|---|
| 677 | $/ = $oldslash;
|
|---|
| 678 |
|
|---|
| 679 | return $slurp;
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | sub attach_default_output
|
|---|
| 683 | {
|
|---|
| 684 | local ($filename) = @_;
|
|---|
| 685 | local ($code);
|
|---|
| 686 |
|
|---|
| 687 | if ($vos)
|
|---|
| 688 | {
|
|---|
| 689 | $code = system "++attach_default_output_hack $filename";
|
|---|
| 690 | $code == -2 || &error ("adoh death\n", 1);
|
|---|
| 691 | return 1;
|
|---|
| 692 | }
|
|---|
| 693 |
|
|---|
| 694 | open ("SAVEDOS" . $default_output_stack_level . "out", ">&STDOUT")
|
|---|
| 695 | || &error ("ado: $! duping STDOUT\n", 1);
|
|---|
| 696 | open ("SAVEDOS" . $default_output_stack_level . "err", ">&STDERR")
|
|---|
| 697 | || &error ("ado: $! duping STDERR\n", 1);
|
|---|
| 698 |
|
|---|
| 699 | open (STDOUT, "> " . $filename)
|
|---|
| 700 | || &error ("ado: $filename: $!\n", 1);
|
|---|
| 701 | open (STDERR, ">&STDOUT")
|
|---|
| 702 | || &error ("ado: $filename: $!\n", 1);
|
|---|
| 703 |
|
|---|
| 704 | $default_output_stack_level++;
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 | # close the current stdout/stderr, and restore the previous ones from
|
|---|
| 708 | # the "stack."
|
|---|
| 709 |
|
|---|
| 710 | sub detach_default_output
|
|---|
| 711 | {
|
|---|
| 712 | local ($code);
|
|---|
| 713 |
|
|---|
| 714 | if ($vos)
|
|---|
| 715 | {
|
|---|
| 716 | $code = system "++detach_default_output_hack";
|
|---|
| 717 | $code == -2 || &error ("ddoh death\n", 1);
|
|---|
| 718 | return 1;
|
|---|
| 719 | }
|
|---|
| 720 |
|
|---|
| 721 | if (--$default_output_stack_level < 0)
|
|---|
| 722 | {
|
|---|
| 723 | &error ("default output stack has flown under!\n", 1);
|
|---|
| 724 | }
|
|---|
| 725 |
|
|---|
| 726 | close (STDOUT);
|
|---|
| 727 | close (STDERR);
|
|---|
| 728 |
|
|---|
| 729 | open (STDOUT, ">&SAVEDOS" . $default_output_stack_level . "out")
|
|---|
| 730 | || &error ("ddo: $! duping STDOUT\n", 1);
|
|---|
| 731 | open (STDERR, ">&SAVEDOS" . $default_output_stack_level . "err")
|
|---|
| 732 | || &error ("ddo: $! duping STDERR\n", 1);
|
|---|
| 733 |
|
|---|
| 734 | close ("SAVEDOS" . $default_output_stack_level . "out")
|
|---|
| 735 | || &error ("ddo: $! closing SCSDOSout\n", 1);
|
|---|
| 736 | close ("SAVEDOS" . $default_output_stack_level . "err")
|
|---|
| 737 | || &error ("ddo: $! closing SAVEDOSerr\n", 1);
|
|---|
| 738 | }
|
|---|
| 739 |
|
|---|
| 740 | # run one command (passed as a list of arg 0 - n), returning 0 on success
|
|---|
| 741 | # and nonzero on failure.
|
|---|
| 742 |
|
|---|
| 743 | sub run_command
|
|---|
| 744 | {
|
|---|
| 745 | local ($code);
|
|---|
| 746 |
|
|---|
| 747 | print "\nrun_command: @_\n" if $debug;
|
|---|
| 748 | $code = system @_;
|
|---|
| 749 | print "run_command: \"@_\" returned $code.\n" if $debug;
|
|---|
| 750 |
|
|---|
| 751 | return $code;
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | # run one command (passed as a list of arg 0 - n, with arg 0 being the
|
|---|
| 755 | # second arg to this routine), returning 0 on success and non-zero on failure.
|
|---|
| 756 | # The first arg to this routine is a filename to connect to the stdout
|
|---|
| 757 | # & stderr of the child process.
|
|---|
| 758 |
|
|---|
| 759 | sub run_command_with_output
|
|---|
| 760 | {
|
|---|
| 761 | local ($filename) = shift;
|
|---|
| 762 | local ($code);
|
|---|
| 763 |
|
|---|
| 764 | &attach_default_output ($filename);
|
|---|
| 765 | $code = system @_;
|
|---|
| 766 | &detach_default_output;
|
|---|
| 767 |
|
|---|
| 768 | print "run_command_with_output: '@_' returned $code.\n" if $debug;
|
|---|
| 769 |
|
|---|
| 770 | return $code;
|
|---|
| 771 | }
|
|---|
| 772 |
|
|---|
| 773 | # performs the equivalent of an "rm -rf" on the first argument. Like
|
|---|
| 774 | # rm, if the path ends in /, leaves the (now empty) directory; otherwise
|
|---|
| 775 | # deletes it, too.
|
|---|
| 776 |
|
|---|
| 777 | sub remove_directory_tree
|
|---|
| 778 | {
|
|---|
| 779 | local ($targetdir) = @_;
|
|---|
| 780 | local ($nuketop) = 1;
|
|---|
| 781 | local ($ch);
|
|---|
| 782 |
|
|---|
| 783 | $ch = substr ($targetdir, length ($targetdir) - 1);
|
|---|
| 784 | if ($ch eq "/" || $ch eq $pathsep)
|
|---|
| 785 | {
|
|---|
| 786 | $targetdir = substr ($targetdir, 0, length ($targetdir) - 1);
|
|---|
| 787 | $nuketop = 0;
|
|---|
| 788 | }
|
|---|
| 789 |
|
|---|
| 790 | if (! -e $targetdir)
|
|---|
| 791 | {
|
|---|
| 792 | return 1;
|
|---|
| 793 | }
|
|---|
| 794 |
|
|---|
| 795 | &remove_directory_tree_inner ("RDT00", $targetdir) || return 0;
|
|---|
| 796 | if ($nuketop)
|
|---|
| 797 | {
|
|---|
| 798 | rmdir $targetdir || return 0;
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 | return 1;
|
|---|
| 802 | }
|
|---|
| 803 |
|
|---|
| 804 | sub remove_directory_tree_inner
|
|---|
| 805 | {
|
|---|
| 806 | local ($dirhandle, $targetdir) = @_;
|
|---|
| 807 | local ($object);
|
|---|
| 808 | local ($subdirhandle);
|
|---|
| 809 |
|
|---|
| 810 | opendir ($dirhandle, $targetdir) || return 0;
|
|---|
| 811 | $subdirhandle = $dirhandle;
|
|---|
| 812 | $subdirhandle++;
|
|---|
| 813 | while ($object = readdir ($dirhandle))
|
|---|
| 814 | {
|
|---|
| 815 | if ($object =~ /^(\.\.?|CVS|RCS)$/)
|
|---|
| 816 | {
|
|---|
| 817 | next;
|
|---|
| 818 | }
|
|---|
| 819 |
|
|---|
| 820 | $object = "$targetdir$pathsep$object";
|
|---|
| 821 | lstat ($object);
|
|---|
| 822 |
|
|---|
| 823 | if (-d _ && &remove_directory_tree_inner ($subdirhandle, $object))
|
|---|
| 824 | {
|
|---|
| 825 | rmdir $object || return 0;
|
|---|
| 826 | }
|
|---|
| 827 | else
|
|---|
| 828 | {
|
|---|
| 829 | unlink $object || return 0;
|
|---|
| 830 | }
|
|---|
| 831 | }
|
|---|
| 832 | closedir ($dirhandle);
|
|---|
| 833 | return 1;
|
|---|
| 834 | }
|
|---|
| 835 |
|
|---|
| 836 | # We used to use this behavior for this function:
|
|---|
| 837 | #
|
|---|
| 838 | #sub touch
|
|---|
| 839 | #{
|
|---|
| 840 | # local (@filenames) = @_;
|
|---|
| 841 | # local ($now) = time;
|
|---|
| 842 | # local ($file);
|
|---|
| 843 | #
|
|---|
| 844 | # foreach $file (@filenames)
|
|---|
| 845 | # {
|
|---|
| 846 | # utime ($now, $now, $file)
|
|---|
| 847 | # || (open (TOUCHFD, ">> $file") && close (TOUCHFD))
|
|---|
| 848 | # || &error ("Couldn't touch $file: $!\n", 1);
|
|---|
| 849 | # }
|
|---|
| 850 | # return 1;
|
|---|
| 851 | #}
|
|---|
| 852 | #
|
|---|
| 853 | # But this behaves badly on networked filesystems where the time is
|
|---|
| 854 | # skewed, because it sets the time of the file based on the _local_
|
|---|
| 855 | # host. Normally when you modify a file, it's the _remote_ host that
|
|---|
| 856 | # determines the modtime, based on _its_ clock. So, instead, now we open
|
|---|
| 857 | # the file and write something into it to force the remote host to set
|
|---|
| 858 | # the modtime correctly according to its clock.
|
|---|
| 859 | #
|
|---|
| 860 |
|
|---|
| 861 | sub touch
|
|---|
| 862 | {
|
|---|
| 863 | local ($file);
|
|---|
| 864 |
|
|---|
| 865 | foreach $file (@_) {
|
|---|
| 866 | (open(T, ">> $file") && print(T "\n") && close(T))
|
|---|
| 867 | || &error("Couldn't touch $file: $!\n", 1);
|
|---|
| 868 | }
|
|---|
| 869 | }
|
|---|
| 870 |
|
|---|
| 871 | # Touch with a time offset. To DTRT, call touch() then use stat() to get the
|
|---|
| 872 | # access/mod time for each file and apply the offset.
|
|---|
| 873 |
|
|---|
| 874 | sub utouch
|
|---|
| 875 | {
|
|---|
| 876 | local ($off) = shift;
|
|---|
| 877 | local ($file);
|
|---|
| 878 |
|
|---|
| 879 | &touch(@_);
|
|---|
| 880 |
|
|---|
| 881 | local (@s) = stat($_[0]);
|
|---|
| 882 |
|
|---|
| 883 | utime($s[8]+$off, $s[9]+$off, @_);
|
|---|
| 884 | }
|
|---|
| 885 |
|
|---|
| 886 | # open a file, write some stuff to it, and close it.
|
|---|
| 887 |
|
|---|
| 888 | sub create_file
|
|---|
| 889 | {
|
|---|
| 890 | local ($filename, @lines) = @_;
|
|---|
| 891 |
|
|---|
| 892 | open (CF, "> $filename") || &error ("Couldn't open $filename: $!\n", 1);
|
|---|
| 893 | foreach $line (@lines)
|
|---|
| 894 | {
|
|---|
| 895 | print CF $line;
|
|---|
| 896 | }
|
|---|
| 897 | close (CF);
|
|---|
| 898 | }
|
|---|
| 899 |
|
|---|
| 900 | # create a directory tree described by an associative array, wherein each
|
|---|
| 901 | # key is a relative pathname (using slashes) and its associated value is
|
|---|
| 902 | # one of:
|
|---|
| 903 | # DIR indicates a directory
|
|---|
| 904 | # FILE:contents indicates a file, which should contain contents +\n
|
|---|
| 905 | # LINK:target indicates a symlink, pointing to $basedir/target
|
|---|
| 906 | # The first argument is the dir under which the structure will be created
|
|---|
| 907 | # (the dir will be made and/or cleaned if necessary); the second argument
|
|---|
| 908 | # is the associative array.
|
|---|
| 909 |
|
|---|
| 910 | sub create_dir_tree
|
|---|
| 911 | {
|
|---|
| 912 | local ($basedir, %dirtree) = @_;
|
|---|
| 913 | local ($path);
|
|---|
| 914 |
|
|---|
| 915 | &remove_directory_tree ("$basedir");
|
|---|
| 916 | mkdir ($basedir, 0777) || &error ("Couldn't mkdir $basedir: $!\n", 1);
|
|---|
| 917 |
|
|---|
| 918 | foreach $path (sort keys (%dirtree))
|
|---|
| 919 | {
|
|---|
| 920 | if ($dirtree {$path} =~ /^DIR$/)
|
|---|
| 921 | {
|
|---|
| 922 | mkdir ("$basedir/$path", 0777)
|
|---|
| 923 | || &error ("Couldn't mkdir $basedir/$path: $!\n", 1);
|
|---|
| 924 | }
|
|---|
| 925 | elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
|
|---|
| 926 | {
|
|---|
| 927 | &create_file ("$basedir/$path", $1 . "\n");
|
|---|
| 928 | }
|
|---|
| 929 | elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
|
|---|
| 930 | {
|
|---|
| 931 | symlink ("$basedir/$1", "$basedir/$path")
|
|---|
| 932 | || &error ("Couldn't symlink $basedir/$path -> $basedir/$1: $!\n", 1);
|
|---|
| 933 | }
|
|---|
| 934 | else
|
|---|
| 935 | {
|
|---|
| 936 | &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
|
|---|
| 937 | }
|
|---|
| 938 | }
|
|---|
| 939 | if ($just_setup_tree)
|
|---|
| 940 | {
|
|---|
| 941 | die "Tree is setup...\n";
|
|---|
| 942 | }
|
|---|
| 943 | }
|
|---|
| 944 |
|
|---|
| 945 | # compare a directory tree with an associative array in the format used
|
|---|
| 946 | # by create_dir_tree, above.
|
|---|
| 947 | # The first argument is the dir under which the structure should be found;
|
|---|
| 948 | # the second argument is the associative array.
|
|---|
| 949 |
|
|---|
| 950 | sub compare_dir_tree
|
|---|
| 951 | {
|
|---|
| 952 | local ($basedir, %dirtree) = @_;
|
|---|
| 953 | local ($path);
|
|---|
| 954 | local ($i);
|
|---|
| 955 | local ($bogus) = 0;
|
|---|
| 956 | local ($contents);
|
|---|
| 957 | local ($target);
|
|---|
| 958 | local ($fulltarget);
|
|---|
| 959 | local ($found);
|
|---|
| 960 | local (@files);
|
|---|
| 961 | local (@allfiles);
|
|---|
| 962 |
|
|---|
| 963 | opendir (DIR, $basedir) || &error ("Couldn't open $basedir: $!\n", 1);
|
|---|
| 964 | @allfiles = grep (!/^(\.\.?|CVS|RCS)$/, readdir (DIR) );
|
|---|
| 965 | closedir (DIR);
|
|---|
| 966 | if ($debug)
|
|---|
| 967 | {
|
|---|
| 968 | print "dirtree: (%dirtree)\n$basedir: (@allfiles)\n";
|
|---|
| 969 | }
|
|---|
| 970 |
|
|---|
| 971 | foreach $path (sort keys (%dirtree))
|
|---|
| 972 | {
|
|---|
| 973 | if ($debug)
|
|---|
| 974 | {
|
|---|
| 975 | print "Checking $path ($dirtree{$path}).\n";
|
|---|
| 976 | }
|
|---|
| 977 |
|
|---|
| 978 | $found = 0;
|
|---|
| 979 | foreach $i (0 .. $#allfiles)
|
|---|
| 980 | {
|
|---|
| 981 | if ($allfiles[$i] eq $path)
|
|---|
| 982 | {
|
|---|
| 983 | splice (@allfiles, $i, 1); # delete it
|
|---|
| 984 | if ($debug)
|
|---|
| 985 | {
|
|---|
| 986 | print " Zapped $path; files now (@allfiles).\n";
|
|---|
| 987 | }
|
|---|
| 988 | lstat ("$basedir/$path");
|
|---|
| 989 | $found = 1;
|
|---|
| 990 | last;
|
|---|
| 991 | }
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | if (!$found)
|
|---|
| 995 | {
|
|---|
| 996 | print "compare_dir_tree: $path does not exist.\n";
|
|---|
| 997 | $bogus = 1;
|
|---|
| 998 | next;
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | if ($dirtree {$path} =~ /^DIR$/)
|
|---|
| 1002 | {
|
|---|
| 1003 | if (-d _ && opendir (DIR, "$basedir/$path") )
|
|---|
| 1004 | {
|
|---|
| 1005 | @files = readdir (DIR);
|
|---|
| 1006 | closedir (DIR);
|
|---|
| 1007 | @files = grep (!/^(\.\.?|CVS|RCS)$/ && ($_ = "$path/$_"), @files);
|
|---|
| 1008 | push (@allfiles, @files);
|
|---|
| 1009 | if ($debug)
|
|---|
| 1010 | {
|
|---|
| 1011 | print " Read in $path; new files (@files).\n";
|
|---|
| 1012 | }
|
|---|
| 1013 | }
|
|---|
| 1014 | else
|
|---|
| 1015 | {
|
|---|
| 1016 | print "compare_dir_tree: $path is not a dir.\n";
|
|---|
| 1017 | $bogus = 1;
|
|---|
| 1018 | }
|
|---|
| 1019 | }
|
|---|
| 1020 | elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
|
|---|
| 1021 | {
|
|---|
| 1022 | if (-l _ || !-f _)
|
|---|
| 1023 | {
|
|---|
| 1024 | print "compare_dir_tree: $path is not a file.\n";
|
|---|
| 1025 | $bogus = 1;
|
|---|
| 1026 | next;
|
|---|
| 1027 | }
|
|---|
| 1028 |
|
|---|
| 1029 | if ($1 ne "*")
|
|---|
| 1030 | {
|
|---|
| 1031 | $contents = &read_file_into_string ("$basedir/$path");
|
|---|
| 1032 | if ($contents ne "$1\n")
|
|---|
| 1033 | {
|
|---|
| 1034 | print "compare_dir_tree: $path contains wrong stuff."
|
|---|
| 1035 | . " Is:\n$contentsShould be:\n$1\n";
|
|---|
| 1036 | $bogus = 1;
|
|---|
| 1037 | }
|
|---|
| 1038 | }
|
|---|
| 1039 | }
|
|---|
| 1040 | elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
|
|---|
| 1041 | {
|
|---|
| 1042 | $target = $1;
|
|---|
| 1043 | if (!-l _)
|
|---|
| 1044 | {
|
|---|
| 1045 | print "compare_dir_tree: $path is not a link.\n";
|
|---|
| 1046 | $bogus = 1;
|
|---|
| 1047 | next;
|
|---|
| 1048 | }
|
|---|
| 1049 |
|
|---|
| 1050 | $contents = readlink ("$basedir/$path");
|
|---|
| 1051 | $contents =~ tr/>/\//;
|
|---|
| 1052 | $fulltarget = "$basedir/$target";
|
|---|
| 1053 | $fulltarget =~ tr/>/\//;
|
|---|
| 1054 | if (!($contents =~ /$fulltarget$/))
|
|---|
| 1055 | {
|
|---|
| 1056 | if ($debug)
|
|---|
| 1057 | {
|
|---|
| 1058 | $target = $fulltarget;
|
|---|
| 1059 | }
|
|---|
| 1060 | print "compare_dir_tree: $path should be link to $target, "
|
|---|
| 1061 | . "not $contents.\n";
|
|---|
| 1062 | $bogus = 1;
|
|---|
| 1063 | }
|
|---|
| 1064 | }
|
|---|
| 1065 | else
|
|---|
| 1066 | {
|
|---|
| 1067 | &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
|
|---|
| 1068 | }
|
|---|
| 1069 | }
|
|---|
| 1070 |
|
|---|
| 1071 | if ($debug)
|
|---|
| 1072 | {
|
|---|
| 1073 | print "leftovers: (@allfiles).\n";
|
|---|
| 1074 | }
|
|---|
| 1075 |
|
|---|
| 1076 | foreach $file (@allfiles)
|
|---|
| 1077 | {
|
|---|
| 1078 | print "compare_dir_tree: $file should not exist.\n";
|
|---|
| 1079 | $bogus = 1;
|
|---|
| 1080 | }
|
|---|
| 1081 |
|
|---|
| 1082 | return !$bogus;
|
|---|
| 1083 | }
|
|---|
| 1084 |
|
|---|
| 1085 | # this subroutine generates the numeric suffix used to keep tmp filenames,
|
|---|
| 1086 | # log filenames, etc., unique. If the number passed in is 1, then a null
|
|---|
| 1087 | # string is returned; otherwise, we return ".n", where n + 1 is the number
|
|---|
| 1088 | # we were given.
|
|---|
| 1089 |
|
|---|
| 1090 | sub num_suffix
|
|---|
| 1091 | {
|
|---|
| 1092 | local($num) = @_;
|
|---|
| 1093 |
|
|---|
| 1094 | if (--$num > 0) {
|
|---|
| 1095 | return "$extext$num";
|
|---|
| 1096 | }
|
|---|
| 1097 |
|
|---|
| 1098 | return "";
|
|---|
| 1099 | }
|
|---|
| 1100 |
|
|---|
| 1101 | # This subroutine returns a log filename with a number appended to
|
|---|
| 1102 | # the end corresponding to how many logfiles have been created in the
|
|---|
| 1103 | # current running test. An optional parameter may be passed (0 or 1).
|
|---|
| 1104 | # If a 1 is passed, then it does NOT increment the logfile counter
|
|---|
| 1105 | # and returns the name of the latest logfile. If either no parameter
|
|---|
| 1106 | # is passed at all or a 0 is passed, then the logfile counter is
|
|---|
| 1107 | # incremented and the new name is returned.
|
|---|
| 1108 |
|
|---|
| 1109 | sub get_logfile
|
|---|
| 1110 | {
|
|---|
| 1111 | local($no_increment) = @_;
|
|---|
| 1112 |
|
|---|
| 1113 | $num_of_logfiles += !$no_increment;
|
|---|
| 1114 |
|
|---|
| 1115 | return ($log_filename . &num_suffix ($num_of_logfiles));
|
|---|
| 1116 | }
|
|---|
| 1117 |
|
|---|
| 1118 | # This subroutine returns a base (answer) filename with a number
|
|---|
| 1119 | # appended to the end corresponding to how many logfiles (and thus
|
|---|
| 1120 | # base files) have been created in the current running test.
|
|---|
| 1121 | # NO PARAMETERS ARE PASSED TO THIS SUBROUTINE.
|
|---|
| 1122 |
|
|---|
| 1123 | sub get_basefile
|
|---|
| 1124 | {
|
|---|
| 1125 | return ($base_filename . &num_suffix ($num_of_logfiles));
|
|---|
| 1126 | }
|
|---|
| 1127 |
|
|---|
| 1128 | # This subroutine returns a difference filename with a number appended
|
|---|
| 1129 | # to the end corresponding to how many logfiles (and thus diff files)
|
|---|
| 1130 | # have been created in the current running test.
|
|---|
| 1131 |
|
|---|
| 1132 | sub get_difffile
|
|---|
| 1133 | {
|
|---|
| 1134 | return ($diff_filename . &num_suffix ($num_of_logfiles));
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 | # just like logfile, only a generic tmp filename for use by the test.
|
|---|
| 1138 | # they are automatically cleaned up unless -keep was used, or the test fails.
|
|---|
| 1139 | # Pass an argument of 1 to return the same filename as the previous call.
|
|---|
| 1140 |
|
|---|
| 1141 | sub get_tmpfile
|
|---|
| 1142 | {
|
|---|
| 1143 | local($no_increment) = @_;
|
|---|
| 1144 |
|
|---|
| 1145 | $num_of_tmpfiles += !$no_increment;
|
|---|
| 1146 |
|
|---|
| 1147 | return ($tmp_filename . &num_suffix ($num_of_tmpfiles));
|
|---|
| 1148 | }
|
|---|
| 1149 |
|
|---|
| 1150 | 1;
|
|---|