4 # Test driver for the Make test suite
6 # Usage: run_make_tests [testname]
14 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
15 # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
17 # This file is part of GNU Make.
19 # GNU Make is free software; you can redistribute it and/or modify it under
20 # the terms of the GNU General Public License as published by the Free Software
21 # Foundation; either version 3 of the License, or (at your option) any later
24 # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
25 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
29 # You should have received a copy of the GNU General Public License along with
30 # this program. If not, see <http://www.gnu.org/licenses/>.
33 $valgrind = 0; # invoke make with valgrind
35 $memcheck_args = '--num-callers=15 --tool=memcheck --leak-check=full';
36 $massif_args = '--num-callers=15 --tool=massif --alloc-fn=xmalloc --alloc-fn=xcalloc --alloc-fn=xrealloc --alloc-fn=xstrdup --alloc-fn=xstrndup';
43 require "test_driver.pl";
45 # Some target systems might not have the POSIX module...
46 $has_POSIX = eval { require "POSIX.pm" };
48 #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
54 if ($option =~ /^-make([-_]?path)?$/i) {
55 $make_path = shift @argv;
57 print "$option $make_path: Not found.\n";
63 if ($option =~ /^-all([-_]?tests)?$/i) {
68 if ($option =~ /^-(valgrind|memcheck)$/i) {
70 $valgrind_args = $memcheck_args;
74 if ($option =~ /^-massif$/i) {
76 $valgrind_args = $massif_args;
80 # This doesn't work--it _should_! Someone badly needs to fix this.
82 # elsif ($option =~ /^-work([-_]?dir)?$/)
84 # $workdir = shift @argv;
92 # This is an "all-in-one" function. Arguments are as follows:
94 # [0] (string): The makefile to be tested. undef means use the last one.
95 # [1] (string): Arguments to pass to make.
96 # [2] (string): Answer we should get back.
97 # [3] (integer): Exit code we expect. A missing code means 0 (success)
99 $old_makefile = undef;
103 local ($makestring, $options, $answer, $err_code, $timeout) = @_;
105 # If the user specified a makefile string, create a new makefile to contain
106 # it. If the first value is not defined, use the last one (if there is
109 if (! defined $makestring) {
110 defined $old_makefile
111 || die "run_make_test(undef) invoked before run_make_test('...')\n";
112 $makefile = $old_makefile;
114 if (! defined($makefile)) {
115 $makefile = &get_tmpfile
();
118 # Make sure it ends in a newline.
119 $makestring && $makestring !~ /\n$/s and $makestring .= "\n";
121 # Replace @MAKEFILE@ with the makefile name and @MAKE@ with the path to
123 $makestring =~ s/#MAKEFILE#/$makefile/g;
124 $makestring =~ s/#MAKEPATH#/$mkpath/g;
125 $makestring =~ s/#MAKE#/$make_name/g;
126 $makestring =~ s/#PERL#/$perl_name/g;
127 $makestring =~ s/#PWD#/$pwd/g;
129 # Populate the makefile!
130 open(MAKEFILE
, "> $makefile") || die "Failed to open $makefile: $!\n";
131 print MAKEFILE
$makestring;
132 close(MAKEFILE
) || die "Failed to write $makefile: $!\n";
135 # Do the same processing on $answer as we did on $makestring.
137 $answer && $answer !~ /\n$/s and $answer .= "\n";
138 $answer =~ s/#MAKEFILE#/$makefile/g;
139 $answer =~ s/#MAKEPATH#/$mkpath/g;
140 $answer =~ s/#MAKE#/$make_name/g;
141 $answer =~ s/#PERL#/$perl_name/g;
142 $answer =~ s/#PWD#/$pwd/g;
144 run_make_with_options
($makefile, $options, &get_logfile
(0),
145 $err_code, $timeout);
146 &compare_output
($answer, &get_logfile
(1));
148 $old_makefile = $makefile;
152 # The old-fashioned way...
153 sub run_make_with_options
{
154 local ($filename,$options,$logname,$expected_code,$timeout) = @_;
156 local($command) = $make_path;
158 $expected_code = 0 unless defined($expected_code);
160 # Reset to reflect this one test.
164 $command .= " -f $filename";
168 $command .= " $options";
171 $command_string = "$command\n";
174 print VALGRIND
"\n\nExecuting: $command\n";
179 my $old_timeout = $test_timeout;
180 $timeout and $test_timeout = $timeout;
182 # If valgrind is enabled, turn off the timeout check
183 $valgrind and $test_timeout = 0;
185 $code = &run_command_with_output
($logname,$command);
187 $test_timeout = $old_timeout;
190 # Check to see if we have Purify errors. If so, keep the logfile.
191 # For this to work you need to build with the Purify flag -exit-status=yes
193 if ($pure_log && -f
$pure_log) {
194 if ($code & 0x7000) {
197 # If we have a purify log, save it
198 $tn = $pure_testname . ($num_of_logfiles ?
".$num_of_logfiles" : "");
199 print("Renaming purify log file to $tn\n") if $debug;
200 rename($pure_log, "$tn")
201 || die "Can't rename $log to $tn: $!\n";
208 if ($code != $expected_code) {
209 print "Error running $make_path (expected $expected_code; got $code): $command\n";
211 $runf = &get_runfile
;
212 &create_file
(&get_runfile
, $command_string);
213 # If it's a SIGINT, stop here
215 print STDERR
"\nCaught signal ".($code & 127)."!\n";
216 ($code & 127) == 2 and exit($code);
221 if ($profile & $vos) {
222 system "add_profile $make_path";
230 &print_standard_usage
("run_make_tests",
231 "[-make_path make_pathname] [-memcheck] [-massif]",);
236 &print_standard_help
(
238 "\tYou may specify the pathname of the copy of make to run.",
241 "\tRun the test suite under valgrind's memcheck tool.",
242 "\tChange the default valgrind args with the VALGRIND_ARGS env var.",
244 "\tRun the test suite under valgrind's massif toool.",
245 "\tChange the default valgrind args with the VALGRIND_ARGS env var."
250 $delete_command = 'rm -f';
252 $__pwd = POSIX
::getcwd
();
254 $delete_command = "delete_file -no_ask";
255 $__pwd = `++(current_dir)`;
257 # No idea... just try using pwd as a last resort.
258 chop ($__pwd = `pwd`);
267 $testee = "GNU make";
269 $tmpfilesuffix = "mk";
270 $pwd = &get_this_pwd
;
273 sub set_more_defaults
278 # find the type of the port. We do this up front to have a single
279 # point of change if it needs to be tweaked.
281 # This is probably not specific enough.
283 if ($osname =~ /Windows/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) {
286 # Bleah, the osname is so variable on DOS. This kind of bites.
287 # Well, as far as I can tell if we check for some text at the
288 # beginning of the line with either no spaces or a single space, then
289 # a D, then either "OS", "os", or "ev" and a space. That should
290 # match and be pretty specific.
291 elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
295 elsif ($osname =~ m
%OS/2%) {
298 # Everything else, right now, is UNIX. Note that we should integrate
299 # the VOS support into this as well and get rid of $vos; we'll do
305 # On DOS/Windows system the filesystem apparently can't track
306 # timestamps with second granularity (!!). Change the sleep time
307 # needed to force a file to be considered "old".
308 $wtime = $port_type eq 'UNIX' ?
1 : $port_type eq 'OS/2' ?
2 : 4;
310 print "Port type: $port_type\n" if $debug;
311 print "Make path: $make_path\n" if $debug;
313 # Find the full pathname of Make. For DOS systems this is more
314 # complicated, so we ask make itself.
315 my $mk = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
317 $mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE):\n
318 'echo \"all:;\@echo \\\$(MAKE)\" | $make_path -f-' failed!\n";
320 print "Make\t= `$make_path'\n" if $debug;
322 $string = `$make_path -v -f /dev/null 2> /dev/null`;
324 $string =~ /^(GNU Make [^,\n]*)/;
325 $testee_version = "$1\n";
327 $string = `sh -c "$make_path -f /dev/null 2>&1"`;
328 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
332 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
336 $make_name = $make_path;
340 # prepend pwd if this is a relative path (ie, does not
341 # start with a slash, but contains one). Thanks for the
344 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
346 $mkpath = "$pwd$pathsep$make_path";
350 $mkpath = $make_path;
353 # Get Purify log info--if any.
355 if (exists $ENV{PURIFYOPTIONS
}
356 && $ENV{PURIFYOPTIONS
} =~ /.*-logfile=([^ ]+)/) {
357 $pure_log = $1 || '';
358 $pure_log =~ s/%v/$make_name/;
362 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
363 if ($string =~ /not supported/) {
370 # Set up for valgrind, if requested.
373 my $args = $valgrind_args;
374 open(VALGRIND
, "> valgrind.out")
375 || die "Cannot open valgrind.out: $!\n";
376 # -q --leak-check=yes
377 exists $ENV{VALGRIND_ARGS
} and $args = $ENV{VALGRIND_ARGS
};
378 $make_path = "valgrind --log-fd=".fileno(VALGRIND
)." $args $make_path";
380 fcntl(VALGRIND
, 2, 0) or die "fcntl(setfd) failed: $!\n";
381 system("echo Starting on `date` 1>&".fileno(VALGRIND
));
382 print "Enabled valgrind support.\n";
388 $makefile = &get_tmpfile
;
393 # Get rid of any Purify logs.
395 ($pure_testname = $testname) =~ tr
,/,_
,;
396 $pure_testname = "$pure_log.$pure_testname";
397 system("rm -f $pure_testname*");
398 print("Purify testfiles are: $pure_testname*\n") if $debug;