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 Free Software Foundation, Inc.
16 # This file is part of GNU Make.
18 # GNU Make is free software; you can redistribute it and/or modify it under
19 # the terms of the GNU General Public License as published by the Free Software
20 # Foundation; either version 3 of the License, or (at your option) any later
23 # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
24 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
28 # You should have received a copy of the GNU General Public License along with
29 # this program. If not, see <http://www.gnu.org/licenses/>.
31 $valgrind = 0; # invoke make with valgrind
32 $valgrind_args = '--num-callers=15 --tool=memcheck --leak-check=full';
35 require "test_driver.pl";
37 # Some target systems might not have the POSIX module...
38 $has_POSIX = eval { require "POSIX.pm" };
40 #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
46 if ($option =~ /^-make([-_]?path)?$/)
48 $make_path = shift @argv;
51 print "$option $make_path: Not found.\n";
57 if ($option =~ /^-valgrind$/i) {
62 # This doesn't work--it _should_! Someone badly needs to fix this.
64 # elsif ($option =~ /^-work([-_]?dir)?$/)
66 # $workdir = shift @argv;
74 # This is an "all-in-one" function. Arguments are as follows:
76 # [0] (string): The makefile to be tested. undef means use the last one.
77 # [1] (string): Arguments to pass to make.
78 # [2] (string): Answer we should get back.
79 # [3] (integer): Exit code we expect. A missing code means 0 (success)
81 $old_makefile = undef;
85 local ($makestring, $options, $answer, $err_code, $timeout) = @_;
87 # If the user specified a makefile string, create a new makefile to contain
88 # it. If the first value is not defined, use the last one (if there is
91 if (! defined $makestring) {
93 || die "run_make_test(undef) invoked before run_make_test('...')\n";
94 $makefile = $old_makefile;
96 if (! defined($makefile)) {
97 $makefile = &get_tmpfile
();
100 # Make sure it ends in a newline.
101 $makestring && $makestring !~ /\n$/s and $makestring .= "\n";
103 # Replace @MAKEFILE@ with the makefile name and @MAKE@ with the path to
105 $makestring =~ s/#MAKEFILE#/$makefile/g;
106 $makestring =~ s/#MAKEPATH#/$mkpath/g;
107 $makestring =~ s/#MAKE#/$make_name/g;
108 $makestring =~ s/#PWD#/$pwd/g;
110 # Populate the makefile!
111 open(MAKEFILE
, "> $makefile") || die "Failed to open $makefile: $!\n";
112 print MAKEFILE
$makestring;
113 close(MAKEFILE
) || die "Failed to write $makefile: $!\n";
116 # Do the same processing on $answer as we did on $makestring.
118 $answer && $answer !~ /\n$/s and $answer .= "\n";
119 $answer =~ s/#MAKEFILE#/$makefile/g;
120 $answer =~ s/#MAKEPATH#/$mkpath/g;
121 $answer =~ s/#MAKE#/$make_name/g;
122 $answer =~ s/#PWD#/$pwd/g;
124 run_make_with_options
($makefile, $options, &get_logfile
(0),
125 $err_code, $timeout);
126 &compare_output
($answer, &get_logfile
(1));
128 $old_makefile = $makefile;
132 # The old-fashioned way...
133 sub run_make_with_options
{
134 local ($filename,$options,$logname,$expected_code,$timeout) = @_;
136 local($command) = $make_path;
138 $expected_code = 0 unless defined($expected_code);
140 # Reset to reflect this one test.
144 $command .= " -f $filename";
148 $command .= " $options";
152 print VALGRIND
"\n\nExecuting: $command\n";
157 my $old_timeout = $test_timeout;
158 $test_timeout = $timeout if $timeout;
160 $code = &run_command_with_output
($logname,$command);
162 $test_timeout = $old_timeout;
165 # Check to see if we have Purify errors. If so, keep the logfile.
166 # For this to work you need to build with the Purify flag -exit-status=yes
168 if ($pure_log && -f
$pure_log) {
169 if ($code & 0x7000) {
172 # If we have a purify log, save it
173 $tn = $pure_testname . ($num_of_logfiles ?
".$num_of_logfiles" : "");
174 print("Renaming purify log file to $tn\n") if $debug;
175 rename($pure_log, "$tn")
176 || die "Can't rename $log to $tn: $!\n";
183 if ($code != $expected_code) {
184 print "Error running $make_path (expected $expected_code; got $code): $command\n";
186 # If it's a SIGINT, stop here
188 print STDERR
"\nCaught signal ".($code & 127)."!\n";
194 if ($profile & $vos) {
195 system "add_profile $make_path";
203 &print_standard_usage
("run_make_tests",
204 "[-make_path make_pathname] [-valgrind]",);
209 &print_standard_help
("-make_path",
210 "\tYou may specify the pathname of the copy of make to run.");
214 $delete_command = 'rm -f';
216 $__pwd = POSIX
::getcwd
();
218 $delete_command = "delete_file -no_ask";
219 $__pwd = `++(current_dir)`;
221 # No idea... just try using pwd as a last resort.
222 chop ($__pwd = `pwd`);
231 $testee = "GNU make";
233 $tmpfilesuffix = "mk";
234 $pwd = &get_this_pwd
;
237 sub set_more_defaults
242 # find the type of the port. We do this up front to have a single
243 # point of change if it needs to be tweaked.
245 # This is probably not specific enough.
247 if ($osname =~ /Windows/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) {
250 # Bleah, the osname is so variable on DOS. This kind of bites.
251 # Well, as far as I can tell if we check for some text at the
252 # beginning of the line with either no spaces or a single space, then
253 # a D, then either "OS", "os", or "ev" and a space. That should
254 # match and be pretty specific.
255 elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
259 elsif ($osname =~ m
%OS/2%) {
262 # Everything else, right now, is UNIX. Note that we should integrate
263 # the VOS support into this as well and get rid of $vos; we'll do
269 # On DOS/Windows system the filesystem apparently can't track
270 # timestamps with second granularity (!!). Change the sleep time
271 # needed to force a file to be considered "old".
272 $wtime = $port_type eq 'UNIX' ?
1 : $port_type eq 'OS/2' ?
2 : 4;
274 print "Port type: $port_type\n" if $debug;
275 print "Make path: $make_path\n" if $debug;
277 # Find the full pathname of Make. For DOS systems this is more
278 # complicated, so we ask make itself.
279 my $mk = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
281 $mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE):\n
282 'echo \"all:;\@echo \\\$(MAKE)\" | $make_path -f-' failed!\n";
284 print "Make\t= `$make_path'\n" if $debug;
286 $string = `$make_path -v -f /dev/null 2> /dev/null`;
288 $string =~ /^(GNU Make [^,\n]*)/;
289 $testee_version = "$1\n";
291 $string = `sh -c "$make_path -f /dev/null 2>&1"`;
292 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
296 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
300 $make_name = $make_path;
304 # prepend pwd if this is a relative path (ie, does not
305 # start with a slash, but contains one). Thanks for the
308 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
310 $mkpath = "$pwd$pathsep$make_path";
314 $mkpath = $make_path;
317 # Get Purify log info--if any.
319 if (exists $ENV{PURIFYOPTIONS
}
320 && $ENV{PURIFYOPTIONS
} =~ /.*-logfile=([^ ]+)/) {
321 $pure_log = $1 || '';
322 $pure_log =~ s/%v/$make_name/;
326 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
327 if ($string =~ /not supported/) {
334 # Set up for valgrind, if requested.
337 open(VALGRIND
, "> valgrind.out")
338 || die "Cannot open valgrind.out: $!\n";
339 # -q --leak-check=yes
340 exists $ENV{VALGRIND_ARGS
} and $valgrind_args = $ENV{VALGRIND_ARGS
};
341 $make_path = "valgrind --log-fd=".fileno(VALGRIND
)." $valgrind_args $make_path";
343 fcntl(VALGRIND
, 2, 0) or die "fcntl(setfd) failed: $!\n";
344 system("echo Starting on `date` 1>&".fileno(VALGRIND
));
345 print "Enabled valgrind support.\n";
351 $makefile = &get_tmpfile
;
356 # Get rid of any Purify logs.
358 ($pure_testname = $testname) =~ tr
,/,_
,;
359 $pure_testname = "$pure_log.$pure_testname";
360 system("rm -f $pure_testname*");
361 print("Purify testfiles are: $pure_testname*\n") if $debug;