| 1 | #!/usr/bin/env perl
|
|---|
| 2 | # -*-perl-*-
|
|---|
| 3 |
|
|---|
| 4 | # Test driver for the Make test suite
|
|---|
| 5 |
|
|---|
| 6 | # Usage: run_make_tests [testname]
|
|---|
| 7 | # [-debug]
|
|---|
| 8 | # [-help]
|
|---|
| 9 | # [-verbose]
|
|---|
| 10 | # [-keep]
|
|---|
| 11 | # [-make <make prog>]
|
|---|
| 12 | # (and others)
|
|---|
| 13 |
|
|---|
| 14 | # Copyright (C) 1992-2016 Free Software Foundation, Inc.
|
|---|
| 15 | # This file is part of GNU Make.
|
|---|
| 16 | #
|
|---|
| 17 | # GNU Make is free software; you can redistribute it and/or modify it under
|
|---|
| 18 | # the terms of the GNU General Public License as published by the Free Software
|
|---|
| 19 | # Foundation; either version 3 of the License, or (at your option) any later
|
|---|
| 20 | # version.
|
|---|
| 21 | #
|
|---|
| 22 | # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 23 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|---|
| 24 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|---|
| 25 | # details.
|
|---|
| 26 | #
|
|---|
| 27 | # You should have received a copy of the GNU General Public License along with
|
|---|
| 28 | # this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 29 |
|
|---|
| 30 | %FEATURES = ();
|
|---|
| 31 |
|
|---|
| 32 | $valgrind = 0; # invoke make with valgrind
|
|---|
| 33 | $valgrind_args = '';
|
|---|
| 34 | $memcheck_args = '--num-callers=15 --tool=memcheck --leak-check=full --suppressions=guile.supp';
|
|---|
| 35 | $massif_args = '--num-callers=15 --tool=massif --alloc-fn=xmalloc --alloc-fn=xcalloc --alloc-fn=xrealloc --alloc-fn=xstrdup --alloc-fn=xstrndup';
|
|---|
| 36 | $pure_log = undef;
|
|---|
| 37 |
|
|---|
| 38 | # The location of the GNU make source directory
|
|---|
| 39 | $srcdir = '';
|
|---|
| 40 |
|
|---|
| 41 | $command_string = '';
|
|---|
| 42 |
|
|---|
| 43 | $all_tests = 0;
|
|---|
| 44 |
|
|---|
| 45 | # rmdir broken in some Perls on VMS.
|
|---|
| 46 | if ($^O eq 'VMS')
|
|---|
| 47 | {
|
|---|
| 48 | require VMS::Filespec;
|
|---|
| 49 | VMS::Filespec->import();
|
|---|
| 50 |
|
|---|
| 51 | sub vms_rmdir {
|
|---|
| 52 | my $vms_file = vmspath($_[0]);
|
|---|
| 53 | $vms_file = fileify($vms_file);
|
|---|
| 54 | my $ret = unlink(vmsify($vms_file));
|
|---|
| 55 | return $ret
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | *CORE::GLOBAL::rmdir = \&vms_rmdir;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | require "test_driver.pl";
|
|---|
| 62 | require "config-flags.pm";
|
|---|
| 63 |
|
|---|
| 64 | # Some target systems might not have the POSIX module...
|
|---|
| 65 | $has_POSIX = eval { require "POSIX.pm" };
|
|---|
| 66 |
|
|---|
| 67 | #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
|
|---|
| 68 |
|
|---|
| 69 | sub valid_option
|
|---|
| 70 | {
|
|---|
| 71 | local($option) = @_;
|
|---|
| 72 |
|
|---|
| 73 | if ($option =~ /^-make([-_]?path)?$/i) {
|
|---|
| 74 | $make_path = shift @argv;
|
|---|
| 75 | if (!-f $make_path) {
|
|---|
| 76 | print "$option $make_path: Not found.\n";
|
|---|
| 77 | exit 0;
|
|---|
| 78 | }
|
|---|
| 79 | return 1;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | if ($option =~ /^-srcdir$/i) {
|
|---|
| 83 | $srcdir = shift @argv;
|
|---|
| 84 | if (! -f "$srcdir/gnumake.h") {
|
|---|
| 85 | print "$option $srcdir: Not a valid GNU make source directory.\n";
|
|---|
| 86 | exit 0;
|
|---|
| 87 | }
|
|---|
| 88 | return 1;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | if ($option =~ /^-all([-_]?tests)?$/i) {
|
|---|
| 92 | $all_tests = 1;
|
|---|
| 93 | return 1;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | if ($option =~ /^-(valgrind|memcheck)$/i) {
|
|---|
| 97 | $valgrind = 1;
|
|---|
| 98 | $valgrind_args = $memcheck_args;
|
|---|
| 99 | return 1;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | if ($option =~ /^-massif$/i) {
|
|---|
| 103 | $valgrind = 1;
|
|---|
| 104 | $valgrind_args = $massif_args;
|
|---|
| 105 | return 1;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | # This doesn't work--it _should_! Someone badly needs to fix this.
|
|---|
| 109 | #
|
|---|
| 110 | # elsif ($option =~ /^-work([-_]?dir)?$/)
|
|---|
| 111 | # {
|
|---|
| 112 | # $workdir = shift @argv;
|
|---|
| 113 | # return 1;
|
|---|
| 114 | # }
|
|---|
| 115 |
|
|---|
| 116 | return 0;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | # This is an "all-in-one" function. Arguments are as follows:
|
|---|
| 121 | #
|
|---|
| 122 | # [0] (string): The makefile to be tested. undef means use the last one.
|
|---|
| 123 | # [1] (string): Arguments to pass to make.
|
|---|
| 124 | # [2] (string): Answer we should get back.
|
|---|
| 125 | # [3] (integer): Exit code we expect. A missing code means 0 (success)
|
|---|
| 126 |
|
|---|
| 127 | $old_makefile = undef;
|
|---|
| 128 |
|
|---|
| 129 | sub subst_make_string
|
|---|
| 130 | {
|
|---|
| 131 | local $_ = shift;
|
|---|
| 132 | $makefile and s/#MAKEFILE#/$makefile/g;
|
|---|
| 133 | s/#MAKEPATH#/$mkpath/g;
|
|---|
| 134 | s/#MAKE#/$make_name/g;
|
|---|
| 135 | s/#PERL#/$perl_name/g;
|
|---|
| 136 | s/#PWD#/$pwd/g;
|
|---|
| 137 | return $_;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | sub run_make_test
|
|---|
| 141 | {
|
|---|
| 142 | local ($makestring, $options, $answer, $err_code, $timeout) = @_;
|
|---|
| 143 | my @call = caller;
|
|---|
| 144 |
|
|---|
| 145 | # If the user specified a makefile string, create a new makefile to contain
|
|---|
| 146 | # it. If the first value is not defined, use the last one (if there is
|
|---|
| 147 | # one).
|
|---|
| 148 |
|
|---|
| 149 | if (! defined $makestring) {
|
|---|
| 150 | defined $old_makefile
|
|---|
| 151 | || die "run_make_test(undef) invoked before run_make_test('...')\n";
|
|---|
| 152 | $makefile = $old_makefile;
|
|---|
| 153 | } else {
|
|---|
| 154 | if (! defined($makefile)) {
|
|---|
| 155 | $makefile = &get_tmpfile();
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | # Make sure it ends in a newline and substitute any special tokens.
|
|---|
| 159 | $makestring && $makestring !~ /\n$/s and $makestring .= "\n";
|
|---|
| 160 | $makestring = subst_make_string($makestring);
|
|---|
| 161 |
|
|---|
| 162 | # Populate the makefile!
|
|---|
| 163 | open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
|
|---|
| 164 | print MAKEFILE $makestring;
|
|---|
| 165 | close(MAKEFILE) || die "Failed to write $makefile: $!\n";
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | # Do the same processing on $answer as we did on $makestring.
|
|---|
| 169 | if (defined $answer) {
|
|---|
| 170 | $answer && $answer !~ /\n$/s and $answer .= "\n";
|
|---|
| 171 | $answer = subst_make_string($answer);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | run_make_with_options($makefile, $options, &get_logfile(0),
|
|---|
| 175 | $err_code, $timeout, @call);
|
|---|
| 176 | &compare_output($answer, &get_logfile(1));
|
|---|
| 177 |
|
|---|
| 178 | $old_makefile = $makefile;
|
|---|
| 179 | $makefile = undef;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | # The old-fashioned way...
|
|---|
| 183 | sub run_make_with_options {
|
|---|
| 184 | my ($filename,$options,$logname,$expected_code,$timeout,@call) = @_;
|
|---|
| 185 | @call = caller unless @call;
|
|---|
| 186 | local($code);
|
|---|
| 187 | local($command) = $make_path;
|
|---|
| 188 |
|
|---|
| 189 | $expected_code = 0 unless defined($expected_code);
|
|---|
| 190 |
|
|---|
| 191 | # Reset to reflect this one test.
|
|---|
| 192 | $test_passed = 1;
|
|---|
| 193 |
|
|---|
| 194 | if ($filename) {
|
|---|
| 195 | $command .= " -f $filename";
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | if ($options) {
|
|---|
| 199 | if ($^O eq 'VMS') {
|
|---|
| 200 | # Try to make sure arguments are properly quoted.
|
|---|
| 201 | # This does not handle all cases.
|
|---|
| 202 |
|
|---|
| 203 | # VMS uses double quotes instead of single quotes.
|
|---|
| 204 | $options =~ s/\'/\"/g;
|
|---|
| 205 |
|
|---|
| 206 | # If the leading quote is inside non-whitespace, then the
|
|---|
| 207 | # quote must be doubled, because it will be enclosed in another
|
|---|
| 208 | # set of quotes.
|
|---|
| 209 | $options =~ s/(\S)(\".*\")/$1\"$2\"/g;
|
|---|
| 210 |
|
|---|
| 211 | # Options must be quoted to preserve case if not already quoted.
|
|---|
| 212 | $options =~ s/(\S+)/\"$1\"/g;
|
|---|
| 213 |
|
|---|
| 214 | # Special fixup for embedded quotes.
|
|---|
| 215 | $options =~ s/(\"\".+)\"(\s+)\"(.+\"\")/$1$2$3/g;
|
|---|
| 216 |
|
|---|
| 217 | $options =~ s/(\A)(?:\"\")(.+)(?:\"\")/$1\"$2\"/g;
|
|---|
| 218 |
|
|---|
| 219 | # Special fixup for misc/general4 test.
|
|---|
| 220 | $options =~ s/""\@echo" "cc""/\@echo cc"/;
|
|---|
| 221 | $options =~ s/"\@echo link"""/\@echo link"/;
|
|---|
| 222 |
|
|---|
| 223 | # Remove shell escapes expected to be removed by bash
|
|---|
| 224 | if ($options !~ /path=pre/) {
|
|---|
| 225 | $options =~ s/\\//g;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | # special fixup for options/eval
|
|---|
| 229 | $options =~ s/"--eval=\$\(info" "eval/"--eval=\$\(info eval/;
|
|---|
| 230 |
|
|---|
| 231 | print ("Options fixup = -$options-\n") if $debug;
|
|---|
| 232 | }
|
|---|
| 233 | $command .= " $options";
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | $command_string = "";
|
|---|
| 237 | if (@call) {
|
|---|
| 238 | $command_string = "#$call[1]:$call[2]\n";
|
|---|
| 239 | }
|
|---|
| 240 | $command_string .= "$command\n";
|
|---|
| 241 |
|
|---|
| 242 | if ($valgrind) {
|
|---|
| 243 | print VALGRIND "\n\nExecuting: $command\n";
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 | {
|
|---|
| 248 | my $old_timeout = $test_timeout;
|
|---|
| 249 | $timeout and $test_timeout = $timeout;
|
|---|
| 250 |
|
|---|
| 251 | # If valgrind is enabled, turn off the timeout check
|
|---|
| 252 | $valgrind and $test_timeout = 0;
|
|---|
| 253 |
|
|---|
| 254 | $code = &run_command_with_output($logname,$command);
|
|---|
| 255 | $test_timeout = $old_timeout;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | # Check to see if we have Purify errors. If so, keep the logfile.
|
|---|
| 259 | # For this to work you need to build with the Purify flag -exit-status=yes
|
|---|
| 260 |
|
|---|
| 261 | if ($pure_log && -f $pure_log) {
|
|---|
| 262 | if ($code & 0x7000) {
|
|---|
| 263 | $code &= ~0x7000;
|
|---|
| 264 |
|
|---|
| 265 | # If we have a purify log, save it
|
|---|
| 266 | $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
|
|---|
| 267 | print("Renaming purify log file to $tn\n") if $debug;
|
|---|
| 268 | rename($pure_log, "$tn")
|
|---|
| 269 | || die "Can't rename $log to $tn: $!\n";
|
|---|
| 270 | ++$purify_errors;
|
|---|
| 271 | } else {
|
|---|
| 272 | unlink($pure_log);
|
|---|
| 273 | }
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | if ($code != $expected_code) {
|
|---|
| 277 | print "Error running $make_path (expected $expected_code; got $code): $command\n";
|
|---|
| 278 | $test_passed = 0;
|
|---|
| 279 | $runf = &get_runfile;
|
|---|
| 280 | &create_file (&get_runfile, $command_string);
|
|---|
| 281 | # If it's a SIGINT, stop here
|
|---|
| 282 | if ($code & 127) {
|
|---|
| 283 | print STDERR "\nCaught signal ".($code & 127)."!\n";
|
|---|
| 284 | ($code & 127) == 2 and exit($code);
|
|---|
| 285 | }
|
|---|
| 286 | return 0;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | if ($profile & $vos) {
|
|---|
| 290 | system "add_profile $make_path";
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | return 1;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | sub print_usage
|
|---|
| 297 | {
|
|---|
| 298 | &print_standard_usage ("run_make_tests",
|
|---|
| 299 | "[-make MAKE_PATHNAME] [-srcdir SRCDIR] [-memcheck] [-massif]",);
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | sub print_help
|
|---|
| 303 | {
|
|---|
| 304 | &print_standard_help (
|
|---|
| 305 | "-make",
|
|---|
| 306 | "\tYou may specify the pathname of the copy of make to run.",
|
|---|
| 307 | "-srcdir",
|
|---|
| 308 | "\tSpecify the make source directory.",
|
|---|
| 309 | "-valgrind",
|
|---|
| 310 | "-memcheck",
|
|---|
| 311 | "\tRun the test suite under valgrind's memcheck tool.",
|
|---|
| 312 | "\tChange the default valgrind args with the VALGRIND_ARGS env var.",
|
|---|
| 313 | "-massif",
|
|---|
| 314 | "\tRun the test suite under valgrind's massif toool.",
|
|---|
| 315 | "\tChange the default valgrind args with the VALGRIND_ARGS env var."
|
|---|
| 316 | );
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | sub get_this_pwd {
|
|---|
| 320 | $delete_command = 'rm -f';
|
|---|
| 321 | if ($has_POSIX) {
|
|---|
| 322 | $__pwd = POSIX::getcwd();
|
|---|
| 323 | } elsif ($vos) {
|
|---|
| 324 | $delete_command = "delete_file -no_ask";
|
|---|
| 325 | $__pwd = `++(current_dir)`;
|
|---|
| 326 | } else {
|
|---|
| 327 | # No idea... just try using pwd as a last resort.
|
|---|
| 328 | chop ($__pwd = `pwd`);
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | return $__pwd;
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | sub set_defaults
|
|---|
| 335 | {
|
|---|
| 336 | # $profile = 1;
|
|---|
| 337 | $testee = "GNU make";
|
|---|
| 338 | $make_path = "make";
|
|---|
| 339 | $tmpfilesuffix = "mk";
|
|---|
| 340 | $pwd = &get_this_pwd;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | sub set_more_defaults
|
|---|
| 344 | {
|
|---|
| 345 | local($string);
|
|---|
| 346 | local($index);
|
|---|
| 347 |
|
|---|
| 348 | # find the type of the port. We do this up front to have a single
|
|---|
| 349 | # point of change if it needs to be tweaked.
|
|---|
| 350 | #
|
|---|
| 351 | # This is probably not specific enough.
|
|---|
| 352 | #
|
|---|
| 353 | if ($osname =~ /Windows/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) {
|
|---|
| 354 | $port_type = 'W32';
|
|---|
| 355 | }
|
|---|
| 356 | # Bleah, the osname is so variable on DOS. This kind of bites.
|
|---|
| 357 | # Well, as far as I can tell if we check for some text at the
|
|---|
| 358 | # beginning of the line with either no spaces or a single space, then
|
|---|
| 359 | # a D, then either "OS", "os", or "ev" and a space. That should
|
|---|
| 360 | # match and be pretty specific.
|
|---|
| 361 | elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
|
|---|
| 362 | $port_type = 'DOS';
|
|---|
| 363 | }
|
|---|
| 364 | # Check for OS/2
|
|---|
| 365 | elsif ($osname =~ m%OS/2%) {
|
|---|
| 366 | $port_type = 'OS/2';
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | # VMS has a GNV Unix mode or a DCL mode.
|
|---|
| 370 | # The SHELL environment variable should not be defined in VMS-DCL mode.
|
|---|
| 371 | elsif ($osname eq 'VMS' && !defined $ENV{"SHELL"}) {
|
|---|
| 372 | $port_type = 'VMS-DCL';
|
|---|
| 373 | }
|
|---|
| 374 | # Everything else, right now, is UNIX. Note that we should integrate
|
|---|
| 375 | # the VOS support into this as well and get rid of $vos; we'll do
|
|---|
| 376 | # that next time.
|
|---|
| 377 | else {
|
|---|
| 378 | $port_type = 'UNIX';
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | # On DOS/Windows system the filesystem apparently can't track
|
|---|
| 382 | # timestamps with second granularity (!!). Change the sleep time
|
|---|
| 383 | # needed to force a file to be considered "old".
|
|---|
| 384 | $wtime = $port_type eq 'UNIX' ? 1 : $port_type eq 'OS/2' ? 2 : 4;
|
|---|
| 385 |
|
|---|
| 386 | print "Port type: $port_type\n" if $debug;
|
|---|
| 387 | print "Make path: $make_path\n" if $debug;
|
|---|
| 388 | print "fs type : case insensitive\n" if $debug && $case_insensitive_fs;
|
|---|
| 389 |
|
|---|
| 390 | # Find the full pathname of Make. For DOS systems this is more
|
|---|
| 391 | # complicated, so we ask make itself.
|
|---|
| 392 | if ($osname eq 'VMS') {
|
|---|
| 393 | $port_type = 'VMS-DCL' unless defined $ENV{"SHELL"};
|
|---|
| 394 | # On VMS pre-setup make to be found with simply 'make'.
|
|---|
| 395 | $make_path = 'make';
|
|---|
| 396 | } else {
|
|---|
| 397 | my $mk = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
|
|---|
| 398 | chop $mk;
|
|---|
| 399 | $mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE):\n
|
|---|
| 400 | 'echo \"all:;\@echo \\\$(MAKE)\" | $make_path -f-' failed!\n";
|
|---|
| 401 | $make_path = $mk;
|
|---|
| 402 | }
|
|---|
| 403 | print "Make\t= '$make_path'\n" if $debug;
|
|---|
| 404 |
|
|---|
| 405 | my $redir2 = '2> /dev/null';
|
|---|
| 406 | $redir2 = '' if os_name eq 'VMS';
|
|---|
| 407 | $string = `$make_path -v -f /dev/null $redir2`;
|
|---|
| 408 |
|
|---|
| 409 | $string =~ /^(GNU Make [^,\n]*)/;
|
|---|
| 410 | $testee_version = "$1\n";
|
|---|
| 411 |
|
|---|
| 412 | my $redir = '2>&1';
|
|---|
| 413 | $redir = '' if os_name eq 'VMS';
|
|---|
| 414 | $string = `sh -c "$make_path -f /dev/null $redir"`;
|
|---|
| 415 | if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
|
|---|
| 416 | $make_name = $1;
|
|---|
| 417 | }
|
|---|
| 418 | else {
|
|---|
| 419 | $make_path =~ /^(?:.*$pathsep)?(.+)$/;
|
|---|
| 420 | $make_name = $1;
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | # prepend pwd if this is a relative path (ie, does not
|
|---|
| 424 | # start with a slash, but contains one). Thanks for the
|
|---|
| 425 | # clue, Roland.
|
|---|
| 426 |
|
|---|
| 427 | if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
|
|---|
| 428 | {
|
|---|
| 429 | $mkpath = "$pwd$pathsep$make_path";
|
|---|
| 430 | }
|
|---|
| 431 | else
|
|---|
| 432 | {
|
|---|
| 433 | $mkpath = $make_path;
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | # If srcdir wasn't provided on the command line, see if the
|
|---|
| 437 | # location of the make program gives us a clue. Don't fail if not;
|
|---|
| 438 | # we'll assume it's been installed into /usr/include or wherever.
|
|---|
| 439 | if (! $srcdir) {
|
|---|
| 440 | $make_path =~ /^(.*$pathsep)?/;
|
|---|
| 441 | my $d = $1 || '../';
|
|---|
| 442 | -f "${d}gnumake.h" and $srcdir = $d;
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | # Not with the make program, so see if we can get it out of the makefile
|
|---|
| 446 | if (! $srcdir && open(MF, "< ../Makefile")) {
|
|---|
| 447 | local $/ = undef;
|
|---|
| 448 | $_ = <MF>;
|
|---|
| 449 | close(MF);
|
|---|
| 450 | /^abs_srcdir\s*=\s*(.*?)\s*$/m;
|
|---|
| 451 | -f "$1/gnumake.h" and $srcdir = $1;
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | # Get Purify log info--if any.
|
|---|
| 455 |
|
|---|
| 456 | if (exists $ENV{PURIFYOPTIONS}
|
|---|
| 457 | && $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/) {
|
|---|
| 458 | $pure_log = $1 || '';
|
|---|
| 459 | $pure_log =~ s/%v/$make_name/;
|
|---|
| 460 | $purify_errors = 0;
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | $string = `sh -c "$make_path -j 2 -f /dev/null $redir"`;
|
|---|
| 464 | if ($string =~ /not supported/) {
|
|---|
| 465 | $parallel_jobs = 0;
|
|---|
| 466 | }
|
|---|
| 467 | else {
|
|---|
| 468 | $parallel_jobs = 1;
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | %FEATURES = map { $_ => 1 } split /\s+/, `sh -c "echo '\\\$(info \\\$(.FEATURES))' | $make_path -f- 2>/dev/null"`;
|
|---|
| 472 |
|
|---|
| 473 | # Set up for valgrind, if requested.
|
|---|
| 474 |
|
|---|
| 475 | $make_command = $make_path;
|
|---|
| 476 |
|
|---|
| 477 | if ($valgrind) {
|
|---|
| 478 | my $args = $valgrind_args;
|
|---|
| 479 | open(VALGRIND, "> valgrind.out")
|
|---|
| 480 | || die "Cannot open valgrind.out: $!\n";
|
|---|
| 481 | # -q --leak-check=yes
|
|---|
| 482 | exists $ENV{VALGRIND_ARGS} and $args = $ENV{VALGRIND_ARGS};
|
|---|
| 483 | $make_path = "valgrind --log-fd=".fileno(VALGRIND)." $args $make_path";
|
|---|
| 484 | # F_SETFD is 2
|
|---|
| 485 | fcntl(VALGRIND, 2, 0) or die "fcntl(setfd) failed: $!\n";
|
|---|
| 486 | system("echo Starting on `date` 1>&".fileno(VALGRIND));
|
|---|
| 487 | print "Enabled valgrind support.\n";
|
|---|
| 488 | }
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | sub setup_for_test
|
|---|
| 492 | {
|
|---|
| 493 | $makefile = &get_tmpfile;
|
|---|
| 494 | if (-f $makefile) {
|
|---|
| 495 | unlink $makefile;
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | # Get rid of any Purify logs.
|
|---|
| 499 | if ($pure_log) {
|
|---|
| 500 | ($pure_testname = $testname) =~ tr,/,_,;
|
|---|
| 501 | $pure_testname = "$pure_log.$pure_testname";
|
|---|
| 502 | system("rm -f $pure_testname*");
|
|---|
| 503 | print("Purify testfiles are: $pure_testname*\n") if $debug;
|
|---|
| 504 | }
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | exit !&toplevel;
|
|---|