| 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 | #
|
|---|
| 8 | # Copyright (C) 1991-2016 Free Software Foundation, Inc.
|
|---|
| 9 | # This file is part of GNU Make.
|
|---|
| 10 | #
|
|---|
| 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
|
|---|
| 14 | # version.
|
|---|
| 15 | #
|
|---|
| 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
|
|---|
| 19 | # details.
|
|---|
| 20 | #
|
|---|
| 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/>.
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | # Test driver routines used by a number of test suites, including
|
|---|
| 26 | # those for SCS, make, roll_dir, and scan_deps (?).
|
|---|
| 27 | #
|
|---|
| 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.
|
|---|
| 30 |
|
|---|
| 31 | # $Id$
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | # The number of test categories we've run
|
|---|
| 35 | $categories_run = 0;
|
|---|
| 36 | # The number of test categroies that have passed
|
|---|
| 37 | $categories_passed = 0;
|
|---|
| 38 | # The total number of individual tests that have been run
|
|---|
| 39 | $total_tests_run = 0;
|
|---|
| 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
|
|---|
| 43 | $tests_run = 0;
|
|---|
| 44 | # The number of tests in this category that have passed
|
|---|
| 45 | $tests_passed = 0;
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | # Yeesh. This whole test environment is such a hack!
|
|---|
| 49 | $test_passed = 1;
|
|---|
| 50 |
|
|---|
| 51 | # Timeout in seconds. If the test takes longer than this we'll fail it.
|
|---|
| 52 | $test_timeout = 5;
|
|---|
| 53 | $test_timeout = 10 if $^O eq 'VMS';
|
|---|
| 54 |
|
|---|
| 55 | # Path to Perl
|
|---|
| 56 | $perl_name = $^X;
|
|---|
| 57 |
|
|---|
| 58 | # %makeENV is the cleaned-out environment.
|
|---|
| 59 | %makeENV = ();
|
|---|
| 60 |
|
|---|
| 61 | # %extraENV are any extra environment variables the tests might want to set.
|
|---|
| 62 | # These are RESET AFTER EVERY TEST!
|
|---|
| 63 | %extraENV = ();
|
|---|
| 64 |
|
|---|
| 65 | sub vms_get_process_logicals {
|
|---|
| 66 | # Sorry for the long note here, but to keep this test running on
|
|---|
| 67 | # VMS, it is needed to be understood.
|
|---|
| 68 | #
|
|---|
| 69 | # Perl on VMS by default maps the %ENV array to the system wide logical
|
|---|
| 70 | # name table.
|
|---|
| 71 | #
|
|---|
| 72 | # This is a very large dynamically changing table.
|
|---|
| 73 | # On Linux, this would be the equivalent of a table that contained
|
|---|
| 74 | # every mount point, temporary pipe, and symbolic link on every
|
|---|
| 75 | # file system. You normally do not have permission to clear or replace it,
|
|---|
| 76 | # and if you did, the results would be catastrophic.
|
|---|
| 77 | #
|
|---|
| 78 | # On VMS, added/changed %ENV items show up in the process logical
|
|---|
| 79 | # name table. So to track changes, a copy of it needs to be captured.
|
|---|
| 80 |
|
|---|
| 81 | my $raw_output = `show log/process/access_mode=supervisor`;
|
|---|
| 82 | my @raw_output_lines = split('\n',$raw_output);
|
|---|
| 83 | my %log_hash;
|
|---|
| 84 | foreach my $line (@raw_output_lines) {
|
|---|
| 85 | if ($line =~ /^\s+"([A-Za-z\$_]+)"\s+=\s+"(.+)"$/) {
|
|---|
| 86 | $log_hash{$1} = $2;
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 | return \%log_hash
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | # %origENV is the caller's original environment
|
|---|
| 93 | if ($^O ne 'VMS') {
|
|---|
| 94 | %origENV = %ENV;
|
|---|
| 95 | } else {
|
|---|
| 96 | my $proc_env = vms_get_process_logicals;
|
|---|
| 97 | %origENV = %{$proc_env};
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | sub resetENV
|
|---|
| 101 | {
|
|---|
| 102 | # We used to say "%ENV = ();" but this doesn't work in Perl 5.000
|
|---|
| 103 | # through Perl 5.004. It was fixed in Perl 5.004_01, but we don't
|
|---|
| 104 | # want to require that here, so just delete each one individually.
|
|---|
| 105 |
|
|---|
| 106 | if ($^O ne 'VMS') {
|
|---|
| 107 | foreach $v (keys %ENV) {
|
|---|
| 108 | delete $ENV{$v};
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | %ENV = %makeENV;
|
|---|
| 112 | } else {
|
|---|
| 113 | my $proc_env = vms_get_process_logicals();
|
|---|
| 114 | my %delta = %{$proc_env};
|
|---|
| 115 | foreach my $v (keys %delta) {
|
|---|
| 116 | if (exists $origENV{$v}) {
|
|---|
| 117 | if ($origENV{$v} ne $delta{$v}) {
|
|---|
| 118 | $ENV{$v} = $origENV{$v};
|
|---|
| 119 | }
|
|---|
| 120 | } else {
|
|---|
| 121 | delete $ENV{$v};
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | foreach $v (keys %extraENV) {
|
|---|
| 127 | $ENV{$v} = $extraENV{$v};
|
|---|
| 128 | delete $extraENV{$v};
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | sub toplevel
|
|---|
| 133 | {
|
|---|
| 134 | # Pull in benign variables from the user's environment
|
|---|
| 135 |
|
|---|
| 136 | foreach (# UNIX-specific things
|
|---|
| 137 | 'TZ', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',
|
|---|
| 138 | 'LD_LIBRARY_PATH',
|
|---|
| 139 | # Purify things
|
|---|
| 140 | 'PURIFYOPTIONS',
|
|---|
| 141 | # Windows NT-specific stuff
|
|---|
| 142 | 'Path', 'SystemRoot',
|
|---|
| 143 | # DJGPP-specific stuff
|
|---|
| 144 | 'DJDIR', 'DJGPP', 'SHELL', 'COMSPEC', 'HOSTNAME', 'LFN',
|
|---|
| 145 | 'FNCASE', '387', 'EMU387', 'GROUP'
|
|---|
| 146 | ) {
|
|---|
| 147 | $makeENV{$_} = $ENV{$_} if $ENV{$_};
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | # Make sure our compares are not foiled by locale differences
|
|---|
| 151 |
|
|---|
| 152 | $makeENV{LC_ALL} = 'C';
|
|---|
| 153 |
|
|---|
| 154 | # Replace the environment with the new one
|
|---|
| 155 | #
|
|---|
| 156 | %origENV = %ENV unless $^O eq 'VMS';
|
|---|
| 157 |
|
|---|
| 158 | resetENV();
|
|---|
| 159 |
|
|---|
| 160 | $| = 1; # unbuffered output
|
|---|
| 161 |
|
|---|
| 162 | $debug = 0; # debug flag
|
|---|
| 163 | $profile = 0; # profiling flag
|
|---|
| 164 | $verbose = 0; # verbose mode flag
|
|---|
| 165 | $detail = 0; # detailed verbosity
|
|---|
| 166 | $keep = 0; # keep temp files around
|
|---|
| 167 | $workdir = "work"; # The directory where the test will start running
|
|---|
| 168 | $scriptdir = "scripts"; # The directory where we find the test scripts
|
|---|
| 169 | $tmpfilesuffix = "t"; # the suffix used on tmpfiles
|
|---|
| 170 | $default_output_stack_level = 0; # used by attach_default_output, etc.
|
|---|
| 171 | $default_input_stack_level = 0; # used by attach_default_input, etc.
|
|---|
| 172 | $cwd = "."; # don't we wish we knew
|
|---|
| 173 | $cwdslash = ""; # $cwd . $pathsep, but "" rather than "./"
|
|---|
| 174 | $is_kmk = 0; # kmk flag.
|
|---|
| 175 | $is_fast = 0; # kmk_fgmake flag.
|
|---|
| 176 |
|
|---|
| 177 | &get_osname; # sets $osname, $vos, $pathsep, $short_filenames,
|
|---|
| 178 | # and $case_insensitive_fs
|
|---|
| 179 |
|
|---|
| 180 | &set_defaults; # suite-defined
|
|---|
| 181 |
|
|---|
| 182 | &parse_command_line (@ARGV);
|
|---|
| 183 |
|
|---|
| 184 | print "OS name = '$osname'\n" if $debug;
|
|---|
| 185 |
|
|---|
| 186 | $workpath = "$cwdslash$workdir";
|
|---|
| 187 | $scriptpath = "$cwdslash$scriptdir";
|
|---|
| 188 |
|
|---|
| 189 | &set_more_defaults; # suite-defined
|
|---|
| 190 |
|
|---|
| 191 | &print_banner;
|
|---|
| 192 |
|
|---|
| 193 | if ($osname eq 'VMS' && $cwdslash eq "")
|
|---|
| 194 | {
|
|---|
| 195 | # Porting this script to VMS revealed a small bug in opendir() not
|
|---|
| 196 | # handling search lists correctly when the directory only exists in
|
|---|
| 197 | # one of the logical_devices. Need to find the first directory in
|
|---|
| 198 | # the search list, as that is where things will be written to.
|
|---|
| 199 | my @dirs = split("/", $pwd);
|
|---|
| 200 |
|
|---|
| 201 | my $logical_device = $ENV{$dirs[1]};
|
|---|
| 202 | if ($logical_device =~ /([A-Za-z0-9_]+):(:?.+:)+/)
|
|---|
| 203 | {
|
|---|
| 204 | # A search list was found. Grab the first logical device
|
|---|
| 205 | # and use it instead of the search list.
|
|---|
| 206 | $dirs[1]=$1;
|
|---|
| 207 | my $lcl_pwd = join('/', @dirs);
|
|---|
| 208 | $workpath = $lcl_pwd . '/' . $workdir
|
|---|
| 209 | }
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | if (-d $workpath)
|
|---|
| 213 | {
|
|---|
| 214 | print "Clearing $workpath...\n";
|
|---|
| 215 | &remove_directory_tree("$workpath/")
|
|---|
| 216 | || &error ("Couldn't wipe out $workpath\n");
|
|---|
| 217 | }
|
|---|
| 218 | else
|
|---|
| 219 | {
|
|---|
| 220 | mkdir ($workpath, 0777) || &error ("Couldn't mkdir $workpath: $!\n");
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | if (!-d $scriptpath)
|
|---|
| 224 | {
|
|---|
| 225 | &error ("Failed to find $scriptpath containing perl test scripts.\n");
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | if (@TESTS)
|
|---|
| 229 | {
|
|---|
| 230 | print "Making work dirs...\n";
|
|---|
| 231 | foreach $test (@TESTS)
|
|---|
| 232 | {
|
|---|
| 233 | if ($test =~ /^([^\/]+)\//)
|
|---|
| 234 | {
|
|---|
| 235 | $dir = $1;
|
|---|
| 236 | push (@rmdirs, $dir);
|
|---|
| 237 | -d "$workpath/$dir"
|
|---|
| 238 | || mkdir ("$workpath/$dir", 0777)
|
|---|
| 239 | || &error ("Couldn't mkdir $workpath/$dir: $!\n");
|
|---|
| 240 | }
|
|---|
| 241 | }
|
|---|
| 242 | }
|
|---|
| 243 | else
|
|---|
| 244 | {
|
|---|
| 245 | print "Finding tests...\n";
|
|---|
| 246 | opendir (SCRIPTDIR, $scriptpath)
|
|---|
| 247 | || &error ("Couldn't opendir $scriptpath: $!\n");
|
|---|
| 248 | @dirs = grep (!/^(\..*|CVS|RCS)$/, readdir (SCRIPTDIR) );
|
|---|
| 249 | closedir (SCRIPTDIR);
|
|---|
| 250 | foreach $dir (@dirs)
|
|---|
| 251 | {
|
|---|
| 252 | next if ($dir =~ /^(\..*|CVS|RCS)$/ || ! -d "$scriptpath/$dir");
|
|---|
| 253 | push (@rmdirs, $dir);
|
|---|
| 254 | # VMS can have overlayed file systems, so directories may repeat.
|
|---|
| 255 | next if -d "$workpath/$dir";
|
|---|
| 256 | mkdir ("$workpath/$dir", 0777)
|
|---|
| 257 | || &error ("Couldn't mkdir $workpath/$dir: $!\n");
|
|---|
| 258 | opendir (SCRIPTDIR, "$scriptpath/$dir")
|
|---|
| 259 | || &error ("Couldn't opendir $scriptpath/$dir: $!\n");
|
|---|
| 260 | @files = grep (!/^(\..*|CVS|RCS|.*~)$/, readdir (SCRIPTDIR) );
|
|---|
| 261 | closedir (SCRIPTDIR);
|
|---|
| 262 | foreach $test (@files)
|
|---|
| 263 | {
|
|---|
| 264 | -d $test and next;
|
|---|
| 265 | push (@TESTS, "$dir/$test");
|
|---|
| 266 | }
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | if (@TESTS == 0)
|
|---|
| 271 | {
|
|---|
| 272 | &error ("\nNo tests in $scriptpath, and none were specified.\n");
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | print "\n";
|
|---|
| 276 |
|
|---|
| 277 | run_all_tests();
|
|---|
| 278 |
|
|---|
| 279 | foreach $dir (@rmdirs)
|
|---|
| 280 | {
|
|---|
| 281 | rmdir ("$workpath/$dir");
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | $| = 1;
|
|---|
| 285 |
|
|---|
| 286 | $categories_failed = $categories_run - $categories_passed;
|
|---|
| 287 | $total_tests_failed = $total_tests_run - $total_tests_passed;
|
|---|
| 288 |
|
|---|
| 289 | if ($total_tests_failed)
|
|---|
| 290 | {
|
|---|
| 291 | print "\n$total_tests_failed Test";
|
|---|
| 292 | print "s" unless $total_tests_failed == 1;
|
|---|
| 293 | print " in $categories_failed Categor";
|
|---|
| 294 | print ($categories_failed == 1 ? "y" : "ies");
|
|---|
| 295 | print " Failed (See .$diffext* files in $workdir dir for details) :-(\n\n";
|
|---|
| 296 | return 0;
|
|---|
| 297 | }
|
|---|
| 298 | else
|
|---|
| 299 | {
|
|---|
| 300 | print "\n$total_tests_passed Test";
|
|---|
| 301 | print "s" unless $total_tests_passed == 1;
|
|---|
| 302 | print " in $categories_passed Categor";
|
|---|
| 303 | print ($categories_passed == 1 ? "y" : "ies");
|
|---|
| 304 | print " Complete ... No Failures :-)\n\n";
|
|---|
| 305 | return 1;
|
|---|
| 306 | }
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | sub get_osname
|
|---|
| 310 | {
|
|---|
| 311 | # Set up an initial value. In perl5 we can do it the easy way.
|
|---|
| 312 | $osname = defined($^O) ? $^O : '';
|
|---|
| 313 |
|
|---|
| 314 | if ($osname eq 'VMS')
|
|---|
| 315 | {
|
|---|
| 316 | $vos = 0;
|
|---|
| 317 | $pathsep = "/";
|
|---|
| 318 | return;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | # Find a path to Perl
|
|---|
| 322 |
|
|---|
| 323 | # See if the filesystem supports long file names with multiple
|
|---|
| 324 | # dots. DOS doesn't.
|
|---|
| 325 | $short_filenames = 0;
|
|---|
| 326 | (open (TOUCHFD, "> fancy.file.name") && close (TOUCHFD))
|
|---|
| 327 | || ($short_filenames = 1);
|
|---|
| 328 | unlink ("fancy.file.name") || ($short_filenames = 1);
|
|---|
| 329 |
|
|---|
| 330 | if (! $short_filenames) {
|
|---|
| 331 | # Thanks go to meyering@cs.utexas.edu (Jim Meyering) for suggesting a
|
|---|
| 332 | # better way of doing this. (We used to test for existence of a /mnt
|
|---|
| 333 | # dir, but that apparently fails on an SGI Indigo (whatever that is).)
|
|---|
| 334 | # Because perl on VOS translates /'s to >'s, we need to test for
|
|---|
| 335 | # VOSness rather than testing for Unixness (ie, try > instead of /).
|
|---|
| 336 |
|
|---|
| 337 | mkdir (".ostest", 0777) || &error ("Couldn't create .ostest: $!\n", 1);
|
|---|
| 338 | open (TOUCHFD, "> .ostest>ick") && close (TOUCHFD);
|
|---|
| 339 | chdir (".ostest") || &error ("Couldn't chdir to .ostest: $!\n", 1);
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | if (! $short_filenames && -f "ick")
|
|---|
| 343 | {
|
|---|
| 344 | $osname = "vos";
|
|---|
| 345 | $vos = 1;
|
|---|
| 346 | $pathsep = ">";
|
|---|
| 347 | }
|
|---|
| 348 | else
|
|---|
| 349 | {
|
|---|
| 350 | # the following is regrettably knarly, but it seems to be the only way
|
|---|
| 351 | # to not get ugly error messages if uname can't be found.
|
|---|
| 352 | # Hmmm, BSD/OS 2.0's uname -a is excessively verbose. Let's try it
|
|---|
| 353 | # with switches first.
|
|---|
| 354 | eval "chop (\$osname = `sh -c 'uname -nmsr 2>&1'`)";
|
|---|
| 355 | if ($osname =~ /not found/i)
|
|---|
| 356 | {
|
|---|
| 357 | $osname = "(something posixy with no uname)";
|
|---|
| 358 | }
|
|---|
| 359 | elsif ($@ ne "" || $?)
|
|---|
| 360 | {
|
|---|
| 361 | eval "chop (\$osname = `sh -c 'uname -a 2>&1'`)";
|
|---|
| 362 | if ($@ ne "" || $?)
|
|---|
| 363 | {
|
|---|
| 364 | $osname = "(something posixy)";
|
|---|
| 365 | }
|
|---|
| 366 | }
|
|---|
| 367 | $vos = 0;
|
|---|
| 368 | $pathsep = "/";
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | if (! $short_filenames) {
|
|---|
| 372 | chdir ("..") || &error ("Couldn't chdir to ..: $!\n", 1);
|
|---|
| 373 | unlink (".ostest>ick");
|
|---|
| 374 | rmdir (".ostest") || &error ("Couldn't rmdir .ostest: $!\n", 1);
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | # Check for case insensitive file system (bird)
|
|---|
| 378 | # The deal is that the 2nd unlink will fail because the first one
|
|---|
| 379 | # will already have removed the file if the fs ignore case.
|
|---|
| 380 | $case_insensitive_fs = 0;
|
|---|
| 381 | my $testfile1 = $short_filenames ? "CaseFs.rmt" : "CaseInSensitiveFs.check";
|
|---|
| 382 | my $testfile2 = $short_filenames ? "casEfS.rmt" : "casEiNsensitivEfS.Check";
|
|---|
| 383 | (open (TOUCHFD, "> $testfile1") && close (TOUCHFD))
|
|---|
| 384 | || &error ("Couldn't create $testfile1: $!\n", 1);
|
|---|
| 385 | (open (TOUCHFD, "> $testfile2") && close (TOUCHFD))
|
|---|
| 386 | || &error ("Couldn't create $testfile2: $!\n", 1);
|
|---|
| 387 | unlink ($testfile1) || &error ("Couldn't unlink $testfile1: $!\n", 1);
|
|---|
| 388 | unlink ($testfile2) || ($case_insensitive_fs = 1);
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | sub parse_command_line
|
|---|
| 392 | {
|
|---|
| 393 | @argv = @_;
|
|---|
| 394 |
|
|---|
| 395 | # use @ARGV if no args were passed in
|
|---|
| 396 |
|
|---|
| 397 | if (@argv == 0)
|
|---|
| 398 | {
|
|---|
| 399 | @argv = @ARGV;
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | # look at each option; if we don't recognize it, maybe the suite-specific
|
|---|
| 403 | # command line parsing code will...
|
|---|
| 404 |
|
|---|
| 405 | while (@argv)
|
|---|
| 406 | {
|
|---|
| 407 | $option = shift @argv;
|
|---|
| 408 | if ($option =~ /^-debug$/i)
|
|---|
| 409 | {
|
|---|
| 410 | print "\nDEBUG ON\n";
|
|---|
| 411 | $debug = 1;
|
|---|
| 412 | }
|
|---|
| 413 | elsif ($option =~ /^-usage$/i)
|
|---|
| 414 | {
|
|---|
| 415 | &print_usage;
|
|---|
| 416 | exit 0;
|
|---|
| 417 | }
|
|---|
| 418 | elsif ($option =~ /^-(h|help)$/i)
|
|---|
| 419 | {
|
|---|
| 420 | &print_help;
|
|---|
| 421 | exit 0;
|
|---|
| 422 | }
|
|---|
| 423 | elsif ($option =~ /^-profile$/i)
|
|---|
| 424 | {
|
|---|
| 425 | $profile = 1;
|
|---|
| 426 | }
|
|---|
| 427 | elsif ($option =~ /^-verbose$/i)
|
|---|
| 428 | {
|
|---|
| 429 | $verbose = 1;
|
|---|
| 430 | }
|
|---|
| 431 | elsif ($option =~ /^-detail$/i)
|
|---|
| 432 | {
|
|---|
| 433 | $detail = 1;
|
|---|
| 434 | $verbose = 1;
|
|---|
| 435 | }
|
|---|
| 436 | elsif ($option =~ /^-keep$/i)
|
|---|
| 437 | {
|
|---|
| 438 | $keep = 1;
|
|---|
| 439 | }
|
|---|
| 440 | elsif ($option =~ /^-kmk/i)
|
|---|
| 441 | {
|
|---|
| 442 | $is_kmk = 1;
|
|---|
| 443 | }
|
|---|
| 444 | elsif ($option =~ /^-fast/i)
|
|---|
| 445 | {
|
|---|
| 446 | $is_fast = 1;
|
|---|
| 447 | }
|
|---|
| 448 | elsif (&valid_option($option))
|
|---|
| 449 | {
|
|---|
| 450 | # The suite-defined subroutine takes care of the option
|
|---|
| 451 | }
|
|---|
| 452 | elsif ($option =~ /^-/)
|
|---|
| 453 | {
|
|---|
| 454 | print "Invalid option: $option\n";
|
|---|
| 455 | &print_usage;
|
|---|
| 456 | exit 0;
|
|---|
| 457 | }
|
|---|
| 458 | else # must be the name of a test
|
|---|
| 459 | {
|
|---|
| 460 | $option =~ s/\.pl$//;
|
|---|
| 461 | push(@TESTS,$option);
|
|---|
| 462 | }
|
|---|
| 463 | }
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | sub max
|
|---|
| 467 | {
|
|---|
| 468 | local($num) = shift @_;
|
|---|
| 469 | local($newnum);
|
|---|
| 470 |
|
|---|
| 471 | while (@_)
|
|---|
| 472 | {
|
|---|
| 473 | $newnum = shift @_;
|
|---|
| 474 | if ($newnum > $num)
|
|---|
| 475 | {
|
|---|
| 476 | $num = $newnum;
|
|---|
| 477 | }
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | return $num;
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | sub print_centered
|
|---|
| 484 | {
|
|---|
| 485 | local($width, $string) = @_;
|
|---|
| 486 | local($pad);
|
|---|
| 487 |
|
|---|
| 488 | if (length ($string))
|
|---|
| 489 | {
|
|---|
| 490 | $pad = " " x ( ($width - length ($string) + 1) / 2);
|
|---|
| 491 | print "$pad$string";
|
|---|
| 492 | }
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | sub print_banner
|
|---|
| 496 | {
|
|---|
| 497 | local($info);
|
|---|
| 498 | local($line);
|
|---|
| 499 | local($len);
|
|---|
| 500 |
|
|---|
| 501 | $info = "Running tests for $testee on $osname\n"; # $testee is suite-defined
|
|---|
| 502 | $len = &max (length ($line), length ($testee_version),
|
|---|
| 503 | length ($banner_info), 73) + 5;
|
|---|
| 504 | $line = ("-" x $len) . "\n";
|
|---|
| 505 | if ($len < 78)
|
|---|
| 506 | {
|
|---|
| 507 | $len = 78;
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | &print_centered ($len, $line);
|
|---|
| 511 | &print_centered ($len, $info);
|
|---|
| 512 | &print_centered ($len, $testee_version); # suite-defined
|
|---|
| 513 | &print_centered ($len, $banner_info); # suite-defined
|
|---|
| 514 | &print_centered ($len, $line);
|
|---|
| 515 | print "\n";
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | sub run_all_tests
|
|---|
| 519 | {
|
|---|
| 520 | $categories_run = 0;
|
|---|
| 521 |
|
|---|
| 522 | $lasttest = '';
|
|---|
| 523 | foreach $testname (sort @TESTS) {
|
|---|
| 524 | # Skip duplicates on VMS caused by logical name search lists.
|
|---|
| 525 | next if $testname eq $lasttest;
|
|---|
| 526 | $lasttest = $testname;
|
|---|
| 527 | $suite_passed = 1; # reset by test on failure
|
|---|
| 528 | $num_of_logfiles = 0;
|
|---|
| 529 | $num_of_tmpfiles = 0;
|
|---|
| 530 | $description = "";
|
|---|
| 531 | $details = "";
|
|---|
| 532 | $old_makefile = undef;
|
|---|
| 533 | $testname =~ s/^$scriptpath$pathsep//;
|
|---|
| 534 | $perl_testname = "$scriptpath$pathsep$testname";
|
|---|
| 535 | $testname =~ s/(\.pl|\.perl)$//;
|
|---|
| 536 | $testpath = "$workpath$pathsep$testname";
|
|---|
| 537 | # Leave enough space in the extensions to append a number, even
|
|---|
| 538 | # though it needs to fit into 8+3 limits.
|
|---|
| 539 | if ($short_filenames) {
|
|---|
| 540 | $logext = 'l';
|
|---|
| 541 | $diffext = 'd';
|
|---|
| 542 | $baseext = 'b';
|
|---|
| 543 | $runext = 'r';
|
|---|
| 544 | $extext = '';
|
|---|
| 545 | } else {
|
|---|
| 546 | $logext = 'log';
|
|---|
| 547 | $diffext = 'diff';
|
|---|
| 548 | $baseext = 'base';
|
|---|
| 549 | $runext = 'run';
|
|---|
| 550 | $extext = '.';
|
|---|
| 551 | }
|
|---|
| 552 | $extext = '_' if $^O eq 'VMS';
|
|---|
| 553 | $log_filename = "$testpath.$logext";
|
|---|
| 554 | $diff_filename = "$testpath.$diffext";
|
|---|
| 555 | $base_filename = "$testpath.$baseext";
|
|---|
| 556 | $run_filename = "$testpath.$runext";
|
|---|
| 557 | $tmp_filename = "$testpath.$tmpfilesuffix";
|
|---|
| 558 |
|
|---|
| 559 | setup_for_test();
|
|---|
| 560 |
|
|---|
| 561 | $output = "........................................................ ";
|
|---|
| 562 |
|
|---|
| 563 | substr($output,0,length($testname)) = "$testname ";
|
|---|
| 564 |
|
|---|
| 565 | print $output;
|
|---|
| 566 |
|
|---|
| 567 | $tests_run = 0;
|
|---|
| 568 | $tests_passed = 0;
|
|---|
| 569 |
|
|---|
| 570 | # Run the test!
|
|---|
| 571 | $code = do $perl_testname;
|
|---|
| 572 |
|
|---|
| 573 | ++$categories_run;
|
|---|
| 574 | $total_tests_run += $tests_run;
|
|---|
| 575 | $total_tests_passed += $tests_passed;
|
|---|
| 576 |
|
|---|
| 577 | # How did it go?
|
|---|
| 578 | if (!defined($code)) {
|
|---|
| 579 | # Failed to parse or called die
|
|---|
| 580 | if (length ($@)) {
|
|---|
| 581 | warn "\n*** Test died ($testname): $@\n";
|
|---|
| 582 | } else {
|
|---|
| 583 | warn "\n*** Couldn't parse $perl_testname\n";
|
|---|
| 584 | }
|
|---|
| 585 | $status = "FAILED ($tests_passed/$tests_run passed)";
|
|---|
| 586 | }
|
|---|
| 587 |
|
|---|
| 588 | elsif ($code == -1) {
|
|---|
| 589 | # Skipped... not supported
|
|---|
| 590 | $status = "N/A";
|
|---|
| 591 | --$categories_run;
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | elsif ($code != 1) {
|
|---|
| 595 | # Bad result... this shouldn't really happen. Usually means that
|
|---|
| 596 | # the suite forgot to end with "1;".
|
|---|
| 597 | warn "\n*** Test returned $code\n";
|
|---|
| 598 | $status = "FAILED ($tests_passed/$tests_run passed)";
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | elsif ($tests_run == 0) {
|
|---|
| 602 | # Nothing was done!!
|
|---|
| 603 | $status = "FAILED (no tests found!)";
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | elsif ($tests_run > $tests_passed) {
|
|---|
| 607 | # Lose!
|
|---|
| 608 | $status = "FAILED ($tests_passed/$tests_run passed)";
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | else {
|
|---|
| 612 | # Win!
|
|---|
| 613 | ++$categories_passed;
|
|---|
| 614 | $status = "ok ($tests_passed passed)";
|
|---|
| 615 |
|
|---|
| 616 | # Clean up
|
|---|
| 617 | for ($i = $num_of_tmpfiles; $i; $i--) {
|
|---|
| 618 | rmfiles($tmp_filename . num_suffix($i));
|
|---|
| 619 | }
|
|---|
| 620 | for ($i = $num_of_logfiles ? $num_of_logfiles : 1; $i; $i--) {
|
|---|
| 621 | rmfiles($log_filename . num_suffix($i));
|
|---|
| 622 | rmfiles($base_filename . num_suffix($i));
|
|---|
| 623 | }
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | # If the verbose option has been specified, then a short description
|
|---|
| 627 | # of each test is printed before displaying the results of each test
|
|---|
| 628 | # describing WHAT is being tested.
|
|---|
| 629 |
|
|---|
| 630 | if ($verbose) {
|
|---|
| 631 | if ($detail) {
|
|---|
| 632 | print "\nWHAT IS BEING TESTED\n";
|
|---|
| 633 | print "--------------------";
|
|---|
| 634 | }
|
|---|
| 635 | print "\n\n$description\n\n";
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | # If the detail option has been specified, then the details of HOW
|
|---|
| 639 | # the test is testing what it says it is testing in the verbose output
|
|---|
| 640 | # will be displayed here before the results of the test are displayed.
|
|---|
| 641 |
|
|---|
| 642 | if ($detail) {
|
|---|
| 643 | print "\nHOW IT IS TESTED\n";
|
|---|
| 644 | print "----------------";
|
|---|
| 645 | print "\n\n$details\n\n";
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | print "$status\n";
|
|---|
| 649 | }
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | # If the keep flag is not set, this subroutine deletes all filenames that
|
|---|
| 653 | # are sent to it.
|
|---|
| 654 |
|
|---|
| 655 | sub rmfiles
|
|---|
| 656 | {
|
|---|
| 657 | local(@files) = @_;
|
|---|
| 658 |
|
|---|
| 659 | if (!$keep)
|
|---|
| 660 | {
|
|---|
| 661 | return (unlink @files);
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | return 1;
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 | sub print_standard_usage
|
|---|
| 668 | {
|
|---|
| 669 | local($plname,@moreusage) = @_;
|
|---|
| 670 | local($line);
|
|---|
| 671 |
|
|---|
| 672 | print "usage:\t$plname [testname] [-verbose] [-detail] [-keep]\n";
|
|---|
| 673 | print "\t\t\t[-profile] [-usage] [-help] [-debug]\n";
|
|---|
| 674 | foreach (@moreusage) {
|
|---|
| 675 | print "\t\t\t$_\n";
|
|---|
| 676 | }
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | sub print_standard_help
|
|---|
| 680 | {
|
|---|
| 681 | local(@morehelp) = @_;
|
|---|
| 682 | local($line);
|
|---|
| 683 | local($tline);
|
|---|
| 684 | local($t) = " ";
|
|---|
| 685 |
|
|---|
| 686 | $line = "Test Driver For $testee";
|
|---|
| 687 | print "$line\n";
|
|---|
| 688 | $line = "=" x length ($line);
|
|---|
| 689 | print "$line\n";
|
|---|
| 690 |
|
|---|
| 691 | &print_usage;
|
|---|
| 692 |
|
|---|
| 693 | print "\ntestname\n"
|
|---|
| 694 | . "${t}You may, if you wish, run only ONE test if you know the name\n"
|
|---|
| 695 | . "${t}of that test and specify this name anywhere on the command\n"
|
|---|
| 696 | . "${t}line. Otherwise ALL existing tests in the scripts directory\n"
|
|---|
| 697 | . "${t}will be run.\n"
|
|---|
| 698 | . "-verbose\n"
|
|---|
| 699 | . "${t}If this option is given, a description of every test is\n"
|
|---|
| 700 | . "${t}displayed before the test is run. (Not all tests may have\n"
|
|---|
| 701 | . "${t}descriptions at this time)\n"
|
|---|
| 702 | . "-detail\n"
|
|---|
| 703 | . "${t}If this option is given, a detailed description of every\n"
|
|---|
| 704 | . "${t}test is displayed before the test is run. (Not all tests\n"
|
|---|
| 705 | . "${t}have descriptions at this time)\n"
|
|---|
| 706 | . "-profile\n"
|
|---|
| 707 | . "${t}If this option is given, then the profile file\n"
|
|---|
| 708 | . "${t}is added to other profiles every time $testee is run.\n"
|
|---|
| 709 | . "${t}This option only works on VOS at this time.\n"
|
|---|
| 710 | . "-keep\n"
|
|---|
| 711 | . "${t}You may give this option if you DO NOT want ANY\n"
|
|---|
| 712 | . "${t}of the files generated by the tests to be deleted. \n"
|
|---|
| 713 | . "${t}Without this option, all files generated by the test will\n"
|
|---|
| 714 | . "${t}be deleted IF THE TEST PASSES.\n"
|
|---|
| 715 | . "-debug\n"
|
|---|
| 716 | . "${t}Use this option if you would like to see all of the system\n"
|
|---|
| 717 | . "${t}calls issued and their return status while running the tests\n"
|
|---|
| 718 | . "${t}This can be helpful if you're having a problem adding a test\n"
|
|---|
| 719 | . "${t}to the suite, or if the test fails!\n";
|
|---|
| 720 |
|
|---|
| 721 | foreach $line (@morehelp)
|
|---|
| 722 | {
|
|---|
| 723 | $tline = $line;
|
|---|
| 724 | if (substr ($tline, 0, 1) eq "\t")
|
|---|
| 725 | {
|
|---|
| 726 | substr ($tline, 0, 1) = $t;
|
|---|
| 727 | }
|
|---|
| 728 | print "$tline\n";
|
|---|
| 729 | }
|
|---|
| 730 | }
|
|---|
| 731 |
|
|---|
| 732 | #######################################################################
|
|---|
| 733 | ########### Generic Test Driver Subroutines ###########
|
|---|
| 734 | #######################################################################
|
|---|
| 735 |
|
|---|
| 736 | sub get_caller
|
|---|
| 737 | {
|
|---|
| 738 | local($depth);
|
|---|
| 739 | local($package);
|
|---|
| 740 | local($filename);
|
|---|
| 741 | local($linenum);
|
|---|
| 742 |
|
|---|
| 743 | $depth = defined ($_[0]) ? $_[0] : 1;
|
|---|
| 744 | ($package, $filename, $linenum) = caller ($depth + 1);
|
|---|
| 745 | return "$filename: $linenum";
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | sub error
|
|---|
| 749 | {
|
|---|
| 750 | local($message) = $_[0];
|
|---|
| 751 | local($caller) = &get_caller (1);
|
|---|
| 752 |
|
|---|
| 753 | if (defined ($_[1]))
|
|---|
| 754 | {
|
|---|
| 755 | $caller = &get_caller ($_[1] + 1) . " -> $caller";
|
|---|
| 756 | }
|
|---|
| 757 |
|
|---|
| 758 | die "$caller: $message";
|
|---|
| 759 | }
|
|---|
| 760 |
|
|---|
| 761 | sub compare_output
|
|---|
| 762 | {
|
|---|
| 763 | local($answer,$logfile) = @_;
|
|---|
| 764 | local($slurp, $answer_matched) = ('', 0);
|
|---|
| 765 |
|
|---|
| 766 | ++$tests_run;
|
|---|
| 767 |
|
|---|
| 768 | if (! defined $answer) {
|
|---|
| 769 | print "Ignoring output ........ " if $debug;
|
|---|
| 770 | $answer_matched = 1;
|
|---|
| 771 | } else {
|
|---|
| 772 | print "Comparing Output ........ " if $debug;
|
|---|
| 773 |
|
|---|
| 774 | $slurp = &read_file_into_string ($logfile);
|
|---|
| 775 |
|
|---|
| 776 | # For make, get rid of any time skew error before comparing--too bad this
|
|---|
| 777 | # has to go into the "generic" driver code :-/
|
|---|
| 778 | $slurp =~ s/^.*modification time .*in the future.*\n//gm;
|
|---|
| 779 | $slurp =~ s/^.*Clock skew detected.*\n//gm;
|
|---|
| 780 |
|
|---|
| 781 | if ($slurp eq $answer) {
|
|---|
| 782 | $answer_matched = 1;
|
|---|
| 783 | } else {
|
|---|
| 784 | # See if it is a slash or CRLF problem
|
|---|
| 785 | local ($answer_mod, $slurp_mod) = ($answer, $slurp);
|
|---|
| 786 |
|
|---|
| 787 | $answer_mod =~ tr,\\,/,;
|
|---|
| 788 | $answer_mod =~ s,\r\n,\n,gs;
|
|---|
| 789 |
|
|---|
| 790 | $slurp_mod =~ tr,\\,/,;
|
|---|
| 791 | $slurp_mod =~ s,\r\n,\n,gs;
|
|---|
| 792 |
|
|---|
| 793 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 794 | if ($^O eq 'VMS') {
|
|---|
| 795 |
|
|---|
| 796 | # VMS has extra blank lines in output sometimes.
|
|---|
| 797 | # Ticket #41760
|
|---|
| 798 | if (!$answer_matched) {
|
|---|
| 799 | $slurp_mod =~ s/\n\n+/\n/gm;
|
|---|
| 800 | $slurp_mod =~ s/\A\n+//g;
|
|---|
| 801 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 802 | }
|
|---|
| 803 |
|
|---|
| 804 | # VMS adding a "Waiting for unfinished jobs..."
|
|---|
| 805 | # Remove it for now to see what else is going on.
|
|---|
| 806 | if (!$answer_matched) {
|
|---|
| 807 | $slurp_mod =~ s/^.+\*\*\* Waiting for unfinished jobs.+$//m;
|
|---|
| 808 | $slurp_mod =~ s/\n\n/\n/gm;
|
|---|
| 809 | $slurp_mod =~ s/^\n+//gm;
|
|---|
| 810 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 811 | }
|
|---|
| 812 |
|
|---|
| 813 | # VMS wants target device to exist or generates an error,
|
|---|
| 814 | # Some test tagets look like VMS devices and trip this.
|
|---|
| 815 | if (!$answer_matched) {
|
|---|
| 816 | $slurp_mod =~ s/^.+\: no such device or address.*$//gim;
|
|---|
| 817 | $slurp_mod =~ s/\n\n/\n/gm;
|
|---|
| 818 | $slurp_mod =~ s/^\n+//gm;
|
|---|
| 819 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 820 | }
|
|---|
| 821 |
|
|---|
| 822 | # VMS error message has a different case
|
|---|
| 823 | if (!$answer_matched) {
|
|---|
| 824 | $slurp_mod =~ s/no such file /No such file /gm;
|
|---|
| 825 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 826 | }
|
|---|
| 827 |
|
|---|
| 828 | # VMS is putting comas instead of spaces in output
|
|---|
| 829 | if (!$answer_matched) {
|
|---|
| 830 | $slurp_mod =~ s/,/ /gm;
|
|---|
| 831 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 832 | }
|
|---|
| 833 |
|
|---|
| 834 | # VMS Is sometimes adding extra leading spaces to output?
|
|---|
| 835 | if (!$answer_matched) {
|
|---|
| 836 | my $slurp_mod = $slurp_mod;
|
|---|
| 837 | $slurp_mod =~ s/^ +//gm;
|
|---|
| 838 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 839 | }
|
|---|
| 840 |
|
|---|
| 841 | # VMS port not handling POSIX encoded child status
|
|---|
| 842 | # Translate error case it for now.
|
|---|
| 843 | if (!$answer_matched) {
|
|---|
| 844 | $slurp_mod =~ s/0x1035a00a/1/gim;
|
|---|
| 845 | $answer_matched = 1 if $slurp_mod =~ /\Q$answer_mod\E/i;
|
|---|
| 846 |
|
|---|
| 847 | }
|
|---|
| 848 | if (!$answer_matched) {
|
|---|
| 849 | $slurp_mod =~ s/0x1035a012/2/gim;
|
|---|
| 850 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | # Tests are using a UNIX null command, temp hack
|
|---|
| 854 | # until this can be handled by the VMS port.
|
|---|
| 855 | # ticket # 41761
|
|---|
| 856 | if (!$answer_matched) {
|
|---|
| 857 | $slurp_mod =~ s/^.+DCL-W-NOCOMD.*$//gim;
|
|---|
| 858 | $slurp_mod =~ s/\n\n+/\n/gm;
|
|---|
| 859 | $slurp_mod =~ s/^\n+//gm;
|
|---|
| 860 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 861 | }
|
|---|
| 862 | # Tests are using exit 0;
|
|---|
| 863 | # this generates a warning that should stop the make, but does not
|
|---|
| 864 | if (!$answer_matched) {
|
|---|
| 865 | $slurp_mod =~ s/^.+NONAME-W-NOMSG.*$//gim;
|
|---|
| 866 | $slurp_mod =~ s/\n\n+/\n/gm;
|
|---|
| 867 | $slurp_mod =~ s/^\n+//gm;
|
|---|
| 868 | $answer_matched = ($slurp_mod eq $answer_mod);
|
|---|
| 869 | }
|
|---|
| 870 |
|
|---|
| 871 | # VMS is sometimes adding single quotes to output?
|
|---|
| 872 | if (!$answer_matched) {
|
|---|
| 873 | my $noq_slurp_mod = $slurp_mod;
|
|---|
| 874 | $noq_slurp_mod =~ s/\'//gm;
|
|---|
| 875 | $answer_matched = ($noq_slurp_mod eq $answer_mod);
|
|---|
| 876 |
|
|---|
| 877 | # And missing an extra space in output
|
|---|
| 878 | if (!$answer_matched) {
|
|---|
| 879 | $noq_answer_mod = $answer_mod;
|
|---|
| 880 | $noq_answer_mod =~ s/\h\h+/ /gm;
|
|---|
| 881 | $answer_matched = ($noq_slurp_mod eq $noq_answer_mod);
|
|---|
| 882 | }
|
|---|
| 883 |
|
|---|
| 884 | # VMS adding ; to end of some lines.
|
|---|
| 885 | if (!$answer_matched) {
|
|---|
| 886 | $noq_slurp_mod =~ s/;\n/\n/gm;
|
|---|
| 887 | $answer_matched = ($noq_slurp_mod eq $noq_answer_mod);
|
|---|
| 888 | }
|
|---|
| 889 |
|
|---|
| 890 | # VMS adding trailing space to end of some quoted lines.
|
|---|
| 891 | if (!$answer_matched) {
|
|---|
| 892 | $noq_slurp_mod =~ s/\h+\n/\n/gm;
|
|---|
| 893 | $answer_matched = ($noq_slurp_mod eq $noq_answer_mod);
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 | # And VMS missing leading blank line
|
|---|
| 897 | if (!$answer_matched) {
|
|---|
| 898 | $noq_answer_mod =~ s/\A\n//g;
|
|---|
| 899 | $answer_matched = ($noq_slurp_mod eq $noq_answer_mod);
|
|---|
| 900 | }
|
|---|
| 901 |
|
|---|
| 902 | # Unix double quotes showing up as single quotes on VMS.
|
|---|
| 903 | if (!$answer_matched) {
|
|---|
| 904 | $noq_answer_mod =~ s/\"//g;
|
|---|
| 905 | $answer_matched = ($noq_slurp_mod eq $noq_answer_mod);
|
|---|
| 906 | }
|
|---|
| 907 | }
|
|---|
| 908 | }
|
|---|
| 909 |
|
|---|
| 910 | # If it still doesn't match, see if the answer might be a regex.
|
|---|
| 911 | if (!$answer_matched && $answer =~ m,^/(.+)/$,) {
|
|---|
| 912 | $answer_matched = ($slurp =~ /$1/);
|
|---|
| 913 | if (!$answer_matched && $answer_mod =~ m,^/(.+)/$,) {
|
|---|
| 914 | $answer_matched = ($slurp_mod =~ /$1/);
|
|---|
| 915 | }
|
|---|
| 916 | }
|
|---|
| 917 | }
|
|---|
| 918 | }
|
|---|
| 919 |
|
|---|
| 920 | if ($answer_matched && $test_passed)
|
|---|
| 921 | {
|
|---|
| 922 | print "ok\n" if $debug;
|
|---|
| 923 | ++$tests_passed;
|
|---|
| 924 | return 1;
|
|---|
| 925 | }
|
|---|
| 926 |
|
|---|
| 927 | if (! $answer_matched) {
|
|---|
| 928 | print "DIFFERENT OUTPUT\n" if $debug;
|
|---|
| 929 |
|
|---|
| 930 | &create_file (&get_basefile, $answer);
|
|---|
| 931 | &create_file (&get_runfile, $command_string);
|
|---|
| 932 |
|
|---|
| 933 | print "\nCreating Difference File ...\n" if $debug;
|
|---|
| 934 |
|
|---|
| 935 | # Create the difference file
|
|---|
| 936 |
|
|---|
| 937 | local($command) = "diff -c " . &get_basefile . " " . $logfile;
|
|---|
| 938 | &run_command_with_output(&get_difffile,$command);
|
|---|
| 939 | }
|
|---|
| 940 |
|
|---|
| 941 | return 0;
|
|---|
| 942 | }
|
|---|
| 943 |
|
|---|
| 944 | sub read_file_into_string
|
|---|
| 945 | {
|
|---|
| 946 | local($filename) = @_;
|
|---|
| 947 | local($oldslash) = $/;
|
|---|
| 948 |
|
|---|
| 949 | undef $/;
|
|---|
| 950 |
|
|---|
| 951 | open (RFISFILE, $filename) || return "";
|
|---|
| 952 | local ($slurp) = <RFISFILE>;
|
|---|
| 953 | close (RFISFILE);
|
|---|
| 954 |
|
|---|
| 955 | $/ = $oldslash;
|
|---|
| 956 |
|
|---|
| 957 | return $slurp;
|
|---|
| 958 | }
|
|---|
| 959 |
|
|---|
| 960 | my @OUTSTACK = ();
|
|---|
| 961 | my @ERRSTACK = ();
|
|---|
| 962 |
|
|---|
| 963 | sub attach_default_output
|
|---|
| 964 | {
|
|---|
| 965 | local ($filename) = @_;
|
|---|
| 966 | local ($code);
|
|---|
| 967 |
|
|---|
| 968 | if ($vos)
|
|---|
| 969 | {
|
|---|
| 970 | $code = system "++attach_default_output_hack $filename";
|
|---|
| 971 | $code == -2 || &error ("adoh death\n", 1);
|
|---|
| 972 | return 1;
|
|---|
| 973 | }
|
|---|
| 974 |
|
|---|
| 975 | my $dup = undef;
|
|---|
| 976 | open($dup, '>&', STDOUT) or error("ado: $! duping STDOUT\n", 1);
|
|---|
| 977 | push @OUTSTACK, $dup;
|
|---|
| 978 |
|
|---|
| 979 | $dup = undef;
|
|---|
| 980 | open($dup, '>&', STDERR) or error("ado: $! duping STDERR\n", 1);
|
|---|
| 981 | push @ERRSTACK, $dup;
|
|---|
| 982 |
|
|---|
| 983 | open(STDOUT, '>', $filename) or error("ado: $filename: $!\n", 1);
|
|---|
| 984 | open(STDERR, ">&STDOUT") or error("ado: $filename: $!\n", 1);
|
|---|
| 985 | }
|
|---|
| 986 |
|
|---|
| 987 | # close the current stdout/stderr, and restore the previous ones from
|
|---|
| 988 | # the "stack."
|
|---|
| 989 |
|
|---|
| 990 | sub detach_default_output
|
|---|
| 991 | {
|
|---|
| 992 | local ($code);
|
|---|
| 993 |
|
|---|
| 994 | if ($vos)
|
|---|
| 995 | {
|
|---|
| 996 | $code = system "++detach_default_output_hack";
|
|---|
| 997 | $code == -2 || &error ("ddoh death\n", 1);
|
|---|
| 998 | return 1;
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | @OUTSTACK or error("default output stack has flown under!\n", 1);
|
|---|
| 1002 |
|
|---|
| 1003 | close(STDOUT);
|
|---|
| 1004 | close(STDERR) unless $^O eq 'VMS';
|
|---|
| 1005 |
|
|---|
| 1006 |
|
|---|
| 1007 | open (STDOUT, '>&', pop @OUTSTACK) or error("ddo: $! duping STDOUT\n", 1);
|
|---|
| 1008 | open (STDERR, '>&', pop @ERRSTACK) or error("ddo: $! duping STDERR\n", 1);
|
|---|
| 1009 | }
|
|---|
| 1010 |
|
|---|
| 1011 | # This runs a command without any debugging info.
|
|---|
| 1012 | sub _run_command
|
|---|
| 1013 | {
|
|---|
| 1014 | my $code;
|
|---|
| 1015 |
|
|---|
| 1016 | # We reset this before every invocation. On Windows I think there is only
|
|---|
| 1017 | # one environment, not one per process, so I think that variables set in
|
|---|
| 1018 | # test scripts might leak into subsequent tests if this isn't reset--???
|
|---|
| 1019 | resetENV();
|
|---|
| 1020 |
|
|---|
| 1021 | eval {
|
|---|
| 1022 | if ($^O eq 'VMS') {
|
|---|
| 1023 | local $SIG{ALRM} = sub {
|
|---|
| 1024 | my $e = $ERRSTACK[0];
|
|---|
| 1025 | print $e "\nTest timed out after $test_timeout seconds\n";
|
|---|
| 1026 | die "timeout\n"; };
|
|---|
| 1027 | # alarm $test_timeout;
|
|---|
| 1028 | system(@_);
|
|---|
| 1029 | my $severity = ${^CHILD_ERROR_NATIVE} & 7;
|
|---|
| 1030 | $code = 0;
|
|---|
| 1031 | if (($severity & 1) == 0) {
|
|---|
| 1032 | $code = 512;
|
|---|
| 1033 | }
|
|---|
| 1034 |
|
|---|
| 1035 | # Get the vms status.
|
|---|
| 1036 | my $vms_code = ${^CHILD_ERROR_NATIVE};
|
|---|
| 1037 |
|
|---|
| 1038 | # Remove the print status bit
|
|---|
| 1039 | $vms_code &= ~0x10000000;
|
|---|
| 1040 |
|
|---|
| 1041 | # Posix code translation.
|
|---|
| 1042 | if (($vms_code & 0xFFFFF000) == 0x35a000) {
|
|---|
| 1043 | $code = (($vms_code & 0xFFF) >> 3) * 256;
|
|---|
| 1044 | }
|
|---|
| 1045 | } else {
|
|---|
| 1046 | my $pid = fork();
|
|---|
| 1047 | if (! $pid) {
|
|---|
| 1048 | exec(@_) or die "Cannot execute $_[0]\n";
|
|---|
| 1049 | }
|
|---|
| 1050 | local $SIG{ALRM} = sub { my $e = $ERRSTACK[0]; print $e "\nTest timed out after $test_timeout seconds\n"; die "timeout\n"; };
|
|---|
| 1051 | alarm $test_timeout;
|
|---|
| 1052 | waitpid($pid, 0) > 0 or die "No such pid: $pid\n";
|
|---|
| 1053 | $code = $?;
|
|---|
| 1054 | }
|
|---|
| 1055 | alarm 0;
|
|---|
| 1056 | };
|
|---|
| 1057 | if ($@) {
|
|---|
| 1058 | # The eval failed. If it wasn't SIGALRM then die.
|
|---|
| 1059 | $@ eq "timeout\n" or die "Command failed: $@";
|
|---|
| 1060 |
|
|---|
| 1061 | # Timed out. Resend the alarm to our process group to kill the children.
|
|---|
| 1062 | $SIG{ALRM} = 'IGNORE';
|
|---|
| 1063 | kill -14, $$;
|
|---|
| 1064 | $code = 14;
|
|---|
| 1065 | }
|
|---|
| 1066 |
|
|---|
| 1067 | return $code;
|
|---|
| 1068 | }
|
|---|
| 1069 |
|
|---|
| 1070 | # run one command (passed as a list of arg 0 - n), returning 0 on success
|
|---|
| 1071 | # and nonzero on failure.
|
|---|
| 1072 |
|
|---|
| 1073 | sub run_command
|
|---|
| 1074 | {
|
|---|
| 1075 | print "\nrun_command: @_\n" if $debug;
|
|---|
| 1076 | my $code = _run_command(@_);
|
|---|
| 1077 | print "run_command returned $code.\n" if $debug;
|
|---|
| 1078 | print "vms status = ${^CHILD_ERROR_NATIVE}\n" if $debug and $^O eq 'VMS';
|
|---|
| 1079 | return $code;
|
|---|
| 1080 | }
|
|---|
| 1081 |
|
|---|
| 1082 | # run one command (passed as a list of arg 0 - n, with arg 0 being the
|
|---|
| 1083 | # second arg to this routine), returning 0 on success and non-zero on failure.
|
|---|
| 1084 | # The first arg to this routine is a filename to connect to the stdout
|
|---|
| 1085 | # & stderr of the child process.
|
|---|
| 1086 |
|
|---|
| 1087 | sub run_command_with_output
|
|---|
| 1088 | {
|
|---|
| 1089 | my $filename = shift;
|
|---|
| 1090 |
|
|---|
| 1091 | print "\nrun_command_with_output($filename,$runname): @_\n" if $debug;
|
|---|
| 1092 | &attach_default_output ($filename);
|
|---|
| 1093 | my $code = eval { _run_command(@_) };
|
|---|
| 1094 | my $err = $@;
|
|---|
| 1095 | &detach_default_output;
|
|---|
| 1096 |
|
|---|
| 1097 | $err and die $err;
|
|---|
| 1098 |
|
|---|
| 1099 | print "run_command_with_output returned $code.\n" if $debug;
|
|---|
| 1100 | print "vms status = ${^CHILD_ERROR_NATIVE}\n" if $debug and $^O eq 'VMS';
|
|---|
| 1101 | return $code;
|
|---|
| 1102 | }
|
|---|
| 1103 |
|
|---|
| 1104 | # performs the equivalent of an "rm -rf" on the first argument. Like
|
|---|
| 1105 | # rm, if the path ends in /, leaves the (now empty) directory; otherwise
|
|---|
| 1106 | # deletes it, too.
|
|---|
| 1107 |
|
|---|
| 1108 | sub remove_directory_tree
|
|---|
| 1109 | {
|
|---|
| 1110 | local ($targetdir) = @_;
|
|---|
| 1111 | local ($nuketop) = 1;
|
|---|
| 1112 | local ($ch);
|
|---|
| 1113 |
|
|---|
| 1114 | $ch = substr ($targetdir, length ($targetdir) - 1);
|
|---|
| 1115 | if ($ch eq "/" || $ch eq $pathsep)
|
|---|
| 1116 | {
|
|---|
| 1117 | $targetdir = substr ($targetdir, 0, length ($targetdir) - 1);
|
|---|
| 1118 | $nuketop = 0;
|
|---|
| 1119 | }
|
|---|
| 1120 |
|
|---|
| 1121 | if (! -e $targetdir)
|
|---|
| 1122 | {
|
|---|
| 1123 | return 1;
|
|---|
| 1124 | }
|
|---|
| 1125 |
|
|---|
| 1126 | &remove_directory_tree_inner ("RDT00", $targetdir) || return 0;
|
|---|
| 1127 | if ($nuketop)
|
|---|
| 1128 | {
|
|---|
| 1129 | rmdir $targetdir || return 0;
|
|---|
| 1130 | }
|
|---|
| 1131 |
|
|---|
| 1132 | return 1;
|
|---|
| 1133 | }
|
|---|
| 1134 |
|
|---|
| 1135 | sub remove_directory_tree_inner
|
|---|
| 1136 | {
|
|---|
| 1137 | local ($dirhandle, $targetdir) = @_;
|
|---|
| 1138 | local ($object);
|
|---|
| 1139 | local ($subdirhandle);
|
|---|
| 1140 |
|
|---|
| 1141 | opendir ($dirhandle, $targetdir) || return 0;
|
|---|
| 1142 | $subdirhandle = $dirhandle;
|
|---|
| 1143 | $subdirhandle++;
|
|---|
| 1144 | while ($object = readdir ($dirhandle))
|
|---|
| 1145 | {
|
|---|
| 1146 | if ($object =~ /^(\.\.?|CVS|RCS)$/)
|
|---|
| 1147 | {
|
|---|
| 1148 | next;
|
|---|
| 1149 | }
|
|---|
| 1150 |
|
|---|
| 1151 | $object = "$targetdir$pathsep$object";
|
|---|
| 1152 | lstat ($object);
|
|---|
| 1153 |
|
|---|
| 1154 | if (-d _ && &remove_directory_tree_inner ($subdirhandle, $object))
|
|---|
| 1155 | {
|
|---|
| 1156 | rmdir $object || return 0;
|
|---|
| 1157 | }
|
|---|
| 1158 | else
|
|---|
| 1159 | {
|
|---|
| 1160 | if ($^O ne 'VMS')
|
|---|
| 1161 | {
|
|---|
| 1162 | unlink $object || return 0;
|
|---|
| 1163 | }
|
|---|
| 1164 | else
|
|---|
| 1165 | {
|
|---|
| 1166 | # VMS can have multiple versions of a file.
|
|---|
| 1167 | 1 while unlink $object;
|
|---|
| 1168 | }
|
|---|
| 1169 | }
|
|---|
| 1170 | }
|
|---|
| 1171 | closedir ($dirhandle);
|
|---|
| 1172 | return 1;
|
|---|
| 1173 | }
|
|---|
| 1174 |
|
|---|
| 1175 | # We used to use this behavior for this function:
|
|---|
| 1176 | #
|
|---|
| 1177 | #sub touch
|
|---|
| 1178 | #{
|
|---|
| 1179 | # local (@filenames) = @_;
|
|---|
| 1180 | # local ($now) = time;
|
|---|
| 1181 | # local ($file);
|
|---|
| 1182 | #
|
|---|
| 1183 | # foreach $file (@filenames)
|
|---|
| 1184 | # {
|
|---|
| 1185 | # utime ($now, $now, $file)
|
|---|
| 1186 | # || (open (TOUCHFD, ">> $file") && close (TOUCHFD))
|
|---|
| 1187 | # || &error ("Couldn't touch $file: $!\n", 1);
|
|---|
| 1188 | # }
|
|---|
| 1189 | # return 1;
|
|---|
| 1190 | #}
|
|---|
| 1191 | #
|
|---|
| 1192 | # But this behaves badly on networked filesystems where the time is
|
|---|
| 1193 | # skewed, because it sets the time of the file based on the _local_
|
|---|
| 1194 | # host. Normally when you modify a file, it's the _remote_ host that
|
|---|
| 1195 | # determines the modtime, based on _its_ clock. So, instead, now we open
|
|---|
| 1196 | # the file and write something into it to force the remote host to set
|
|---|
| 1197 | # the modtime correctly according to its clock.
|
|---|
| 1198 | #
|
|---|
| 1199 |
|
|---|
| 1200 | sub touch
|
|---|
| 1201 | {
|
|---|
| 1202 | local ($file);
|
|---|
| 1203 |
|
|---|
| 1204 | foreach $file (@_) {
|
|---|
| 1205 | (open(T, ">> $file") && print(T "\n") && close(T))
|
|---|
| 1206 | || &error("Couldn't touch $file: $!\n", 1);
|
|---|
| 1207 | }
|
|---|
| 1208 | }
|
|---|
| 1209 |
|
|---|
| 1210 | # Touch with a time offset. To DTRT, call touch() then use stat() to get the
|
|---|
| 1211 | # access/mod time for each file and apply the offset.
|
|---|
| 1212 |
|
|---|
| 1213 | sub utouch
|
|---|
| 1214 | {
|
|---|
| 1215 | local ($off) = shift;
|
|---|
| 1216 | local ($file);
|
|---|
| 1217 |
|
|---|
| 1218 | &touch(@_);
|
|---|
| 1219 |
|
|---|
| 1220 | local (@s) = stat($_[0]);
|
|---|
| 1221 |
|
|---|
| 1222 | utime($s[8]+$off, $s[9]+$off, @_);
|
|---|
| 1223 | }
|
|---|
| 1224 |
|
|---|
| 1225 | # open a file, write some stuff to it, and close it.
|
|---|
| 1226 |
|
|---|
| 1227 | sub create_file
|
|---|
| 1228 | {
|
|---|
| 1229 | local ($filename, @lines) = @_;
|
|---|
| 1230 |
|
|---|
| 1231 | open (CF, "> $filename") || &error ("Couldn't open $filename: $!\n", 1);
|
|---|
| 1232 | foreach $line (@lines)
|
|---|
| 1233 | {
|
|---|
| 1234 | print CF $line;
|
|---|
| 1235 | }
|
|---|
| 1236 | close (CF);
|
|---|
| 1237 | }
|
|---|
| 1238 |
|
|---|
| 1239 | # create a directory tree described by an associative array, wherein each
|
|---|
| 1240 | # key is a relative pathname (using slashes) and its associated value is
|
|---|
| 1241 | # one of:
|
|---|
| 1242 | # DIR indicates a directory
|
|---|
| 1243 | # FILE:contents indicates a file, which should contain contents +\n
|
|---|
| 1244 | # LINK:target indicates a symlink, pointing to $basedir/target
|
|---|
| 1245 | # The first argument is the dir under which the structure will be created
|
|---|
| 1246 | # (the dir will be made and/or cleaned if necessary); the second argument
|
|---|
| 1247 | # is the associative array.
|
|---|
| 1248 |
|
|---|
| 1249 | sub create_dir_tree
|
|---|
| 1250 | {
|
|---|
| 1251 | local ($basedir, %dirtree) = @_;
|
|---|
| 1252 | local ($path);
|
|---|
| 1253 |
|
|---|
| 1254 | &remove_directory_tree ("$basedir");
|
|---|
| 1255 | mkdir ($basedir, 0777) || &error ("Couldn't mkdir $basedir: $!\n", 1);
|
|---|
| 1256 |
|
|---|
| 1257 | foreach $path (sort keys (%dirtree))
|
|---|
| 1258 | {
|
|---|
| 1259 | if ($dirtree {$path} =~ /^DIR$/)
|
|---|
| 1260 | {
|
|---|
| 1261 | mkdir ("$basedir/$path", 0777)
|
|---|
| 1262 | || &error ("Couldn't mkdir $basedir/$path: $!\n", 1);
|
|---|
| 1263 | }
|
|---|
| 1264 | elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
|
|---|
| 1265 | {
|
|---|
| 1266 | &create_file ("$basedir/$path", $1 . "\n");
|
|---|
| 1267 | }
|
|---|
| 1268 | elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
|
|---|
| 1269 | {
|
|---|
| 1270 | symlink ("$basedir/$1", "$basedir/$path")
|
|---|
| 1271 | || &error ("Couldn't symlink $basedir/$path -> $basedir/$1: $!\n", 1);
|
|---|
| 1272 | }
|
|---|
| 1273 | else
|
|---|
| 1274 | {
|
|---|
| 1275 | &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
|
|---|
| 1276 | }
|
|---|
| 1277 | }
|
|---|
| 1278 | if ($just_setup_tree)
|
|---|
| 1279 | {
|
|---|
| 1280 | die "Tree is setup...\n";
|
|---|
| 1281 | }
|
|---|
| 1282 | }
|
|---|
| 1283 |
|
|---|
| 1284 | # compare a directory tree with an associative array in the format used
|
|---|
| 1285 | # by create_dir_tree, above.
|
|---|
| 1286 | # The first argument is the dir under which the structure should be found;
|
|---|
| 1287 | # the second argument is the associative array.
|
|---|
| 1288 |
|
|---|
| 1289 | sub compare_dir_tree
|
|---|
| 1290 | {
|
|---|
| 1291 | local ($basedir, %dirtree) = @_;
|
|---|
| 1292 | local ($path);
|
|---|
| 1293 | local ($i);
|
|---|
| 1294 | local ($bogus) = 0;
|
|---|
| 1295 | local ($contents);
|
|---|
| 1296 | local ($target);
|
|---|
| 1297 | local ($fulltarget);
|
|---|
| 1298 | local ($found);
|
|---|
| 1299 | local (@files);
|
|---|
| 1300 | local (@allfiles);
|
|---|
| 1301 |
|
|---|
| 1302 | opendir (DIR, $basedir) || &error ("Couldn't open $basedir: $!\n", 1);
|
|---|
| 1303 | @allfiles = grep (!/^(\.\.?|CVS|RCS)$/, readdir (DIR) );
|
|---|
| 1304 | closedir (DIR);
|
|---|
| 1305 | if ($debug)
|
|---|
| 1306 | {
|
|---|
| 1307 | print "dirtree: (%dirtree)\n$basedir: (@allfiles)\n";
|
|---|
| 1308 | }
|
|---|
| 1309 |
|
|---|
| 1310 | foreach $path (sort keys (%dirtree))
|
|---|
| 1311 | {
|
|---|
| 1312 | if ($debug)
|
|---|
| 1313 | {
|
|---|
| 1314 | print "Checking $path ($dirtree{$path}).\n";
|
|---|
| 1315 | }
|
|---|
| 1316 |
|
|---|
| 1317 | $found = 0;
|
|---|
| 1318 | foreach $i (0 .. $#allfiles)
|
|---|
| 1319 | {
|
|---|
| 1320 | if ($allfiles[$i] eq $path)
|
|---|
| 1321 | {
|
|---|
| 1322 | splice (@allfiles, $i, 1); # delete it
|
|---|
| 1323 | if ($debug)
|
|---|
| 1324 | {
|
|---|
| 1325 | print " Zapped $path; files now (@allfiles).\n";
|
|---|
| 1326 | }
|
|---|
| 1327 | lstat ("$basedir/$path");
|
|---|
| 1328 | $found = 1;
|
|---|
| 1329 | last;
|
|---|
| 1330 | }
|
|---|
| 1331 | }
|
|---|
| 1332 |
|
|---|
| 1333 | if (!$found)
|
|---|
| 1334 | {
|
|---|
| 1335 | print "compare_dir_tree: $path does not exist.\n";
|
|---|
| 1336 | $bogus = 1;
|
|---|
| 1337 | next;
|
|---|
| 1338 | }
|
|---|
| 1339 |
|
|---|
| 1340 | if ($dirtree {$path} =~ /^DIR$/)
|
|---|
| 1341 | {
|
|---|
| 1342 | if (-d _ && opendir (DIR, "$basedir/$path") )
|
|---|
| 1343 | {
|
|---|
| 1344 | @files = readdir (DIR);
|
|---|
| 1345 | closedir (DIR);
|
|---|
| 1346 | @files = grep (!/^(\.\.?|CVS|RCS)$/ && ($_ = "$path/$_"), @files);
|
|---|
| 1347 | push (@allfiles, @files);
|
|---|
| 1348 | if ($debug)
|
|---|
| 1349 | {
|
|---|
| 1350 | print " Read in $path; new files (@files).\n";
|
|---|
| 1351 | }
|
|---|
| 1352 | }
|
|---|
| 1353 | else
|
|---|
| 1354 | {
|
|---|
| 1355 | print "compare_dir_tree: $path is not a dir.\n";
|
|---|
| 1356 | $bogus = 1;
|
|---|
| 1357 | }
|
|---|
| 1358 | }
|
|---|
| 1359 | elsif ($dirtree {$path} =~ /^FILE:(.*)$/)
|
|---|
| 1360 | {
|
|---|
| 1361 | if (-l _ || !-f _)
|
|---|
| 1362 | {
|
|---|
| 1363 | print "compare_dir_tree: $path is not a file.\n";
|
|---|
| 1364 | $bogus = 1;
|
|---|
| 1365 | next;
|
|---|
| 1366 | }
|
|---|
| 1367 |
|
|---|
| 1368 | if ($1 ne "*")
|
|---|
| 1369 | {
|
|---|
| 1370 | $contents = &read_file_into_string ("$basedir/$path");
|
|---|
| 1371 | if ($contents ne "$1\n")
|
|---|
| 1372 | {
|
|---|
| 1373 | print "compare_dir_tree: $path contains wrong stuff."
|
|---|
| 1374 | . " Is:\n$contentsShould be:\n$1\n";
|
|---|
| 1375 | $bogus = 1;
|
|---|
| 1376 | }
|
|---|
| 1377 | }
|
|---|
| 1378 | }
|
|---|
| 1379 | elsif ($dirtree {$path} =~ /^LINK:(.*)$/)
|
|---|
| 1380 | {
|
|---|
| 1381 | $target = $1;
|
|---|
| 1382 | if (!-l _)
|
|---|
| 1383 | {
|
|---|
| 1384 | print "compare_dir_tree: $path is not a link.\n";
|
|---|
| 1385 | $bogus = 1;
|
|---|
| 1386 | next;
|
|---|
| 1387 | }
|
|---|
| 1388 |
|
|---|
| 1389 | $contents = readlink ("$basedir/$path");
|
|---|
| 1390 | $contents =~ tr/>/\//;
|
|---|
| 1391 | $fulltarget = "$basedir/$target";
|
|---|
| 1392 | $fulltarget =~ tr/>/\//;
|
|---|
| 1393 | if (!($contents =~ /$fulltarget$/))
|
|---|
| 1394 | {
|
|---|
| 1395 | if ($debug)
|
|---|
| 1396 | {
|
|---|
| 1397 | $target = $fulltarget;
|
|---|
| 1398 | }
|
|---|
| 1399 | print "compare_dir_tree: $path should be link to $target, "
|
|---|
| 1400 | . "not $contents.\n";
|
|---|
| 1401 | $bogus = 1;
|
|---|
| 1402 | }
|
|---|
| 1403 | }
|
|---|
| 1404 | else
|
|---|
| 1405 | {
|
|---|
| 1406 | &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1);
|
|---|
| 1407 | }
|
|---|
| 1408 | }
|
|---|
| 1409 |
|
|---|
| 1410 | if ($debug)
|
|---|
| 1411 | {
|
|---|
| 1412 | print "leftovers: (@allfiles).\n";
|
|---|
| 1413 | }
|
|---|
| 1414 |
|
|---|
| 1415 | foreach $file (@allfiles)
|
|---|
| 1416 | {
|
|---|
| 1417 | print "compare_dir_tree: $file should not exist.\n";
|
|---|
| 1418 | $bogus = 1;
|
|---|
| 1419 | }
|
|---|
| 1420 |
|
|---|
| 1421 | return !$bogus;
|
|---|
| 1422 | }
|
|---|
| 1423 |
|
|---|
| 1424 | # this subroutine generates the numeric suffix used to keep tmp filenames,
|
|---|
| 1425 | # log filenames, etc., unique. If the number passed in is 1, then a null
|
|---|
| 1426 | # string is returned; otherwise, we return ".n", where n + 1 is the number
|
|---|
| 1427 | # we were given.
|
|---|
| 1428 |
|
|---|
| 1429 | sub num_suffix
|
|---|
| 1430 | {
|
|---|
| 1431 | local($num) = @_;
|
|---|
| 1432 |
|
|---|
| 1433 | if (--$num > 0) {
|
|---|
| 1434 | return "$extext$num";
|
|---|
| 1435 | }
|
|---|
| 1436 |
|
|---|
| 1437 | return "";
|
|---|
| 1438 | }
|
|---|
| 1439 |
|
|---|
| 1440 | # This subroutine returns a log filename with a number appended to
|
|---|
| 1441 | # the end corresponding to how many logfiles have been created in the
|
|---|
| 1442 | # current running test. An optional parameter may be passed (0 or 1).
|
|---|
| 1443 | # If a 1 is passed, then it does NOT increment the logfile counter
|
|---|
| 1444 | # and returns the name of the latest logfile. If either no parameter
|
|---|
| 1445 | # is passed at all or a 0 is passed, then the logfile counter is
|
|---|
| 1446 | # incremented and the new name is returned.
|
|---|
| 1447 |
|
|---|
| 1448 | sub get_logfile
|
|---|
| 1449 | {
|
|---|
| 1450 | local($no_increment) = @_;
|
|---|
| 1451 |
|
|---|
| 1452 | $num_of_logfiles += !$no_increment;
|
|---|
| 1453 |
|
|---|
| 1454 | return ($log_filename . &num_suffix ($num_of_logfiles));
|
|---|
| 1455 | }
|
|---|
| 1456 |
|
|---|
| 1457 | # This subroutine returns a base (answer) filename with a number
|
|---|
| 1458 | # appended to the end corresponding to how many logfiles (and thus
|
|---|
| 1459 | # base files) have been created in the current running test.
|
|---|
| 1460 | # NO PARAMETERS ARE PASSED TO THIS SUBROUTINE.
|
|---|
| 1461 |
|
|---|
| 1462 | sub get_basefile
|
|---|
| 1463 | {
|
|---|
| 1464 | return ($base_filename . &num_suffix ($num_of_logfiles));
|
|---|
| 1465 | }
|
|---|
| 1466 |
|
|---|
| 1467 | # This subroutine returns a difference filename with a number appended
|
|---|
| 1468 | # to the end corresponding to how many logfiles (and thus diff files)
|
|---|
| 1469 | # have been created in the current running test.
|
|---|
| 1470 |
|
|---|
| 1471 | sub get_difffile
|
|---|
| 1472 | {
|
|---|
| 1473 | return ($diff_filename . &num_suffix ($num_of_logfiles));
|
|---|
| 1474 | }
|
|---|
| 1475 |
|
|---|
| 1476 | # This subroutine returns a command filename with a number appended
|
|---|
| 1477 | # to the end corresponding to how many logfiles (and thus command files)
|
|---|
| 1478 | # have been created in the current running test.
|
|---|
| 1479 |
|
|---|
| 1480 | sub get_runfile
|
|---|
| 1481 | {
|
|---|
| 1482 | return ($run_filename . &num_suffix ($num_of_logfiles));
|
|---|
| 1483 | }
|
|---|
| 1484 |
|
|---|
| 1485 | # just like logfile, only a generic tmp filename for use by the test.
|
|---|
| 1486 | # they are automatically cleaned up unless -keep was used, or the test fails.
|
|---|
| 1487 | # Pass an argument of 1 to return the same filename as the previous call.
|
|---|
| 1488 |
|
|---|
| 1489 | sub get_tmpfile
|
|---|
| 1490 | {
|
|---|
| 1491 | local($no_increment) = @_;
|
|---|
| 1492 |
|
|---|
| 1493 | $num_of_tmpfiles += !$no_increment;
|
|---|
| 1494 |
|
|---|
| 1495 | return ($tmp_filename . &num_suffix ($num_of_tmpfiles));
|
|---|
| 1496 | }
|
|---|
| 1497 |
|
|---|
| 1498 | 1;
|
|---|