Add missing load.c file to POTFILES.in
[make.git] / tests / run_make_tests.pl
blob4accd4aadb7b88e5548af4f58ba6aa3eeb53673f
1 #!/usr/bin/env perl
2 # -*-perl-*-
4 # Test driver for the Make test suite
6 # Usage: run_make_tests [testname]
7 # [-debug]
8 # [-help]
9 # [-verbose]
10 # [-keep]
11 # [-make <make prog>]
12 # (and others)
14 # Copyright (C) 1992-2012 Free Software Foundation, Inc.
15 # This file is part of GNU Make.
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.
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.
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/>.
30 %FEATURES = ();
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;
38 $command_string = '';
40 $all_tests = 0;
42 require "test_driver.pl";
44 # Some target systems might not have the POSIX module...
45 $has_POSIX = eval { require "POSIX.pm" };
47 #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
49 sub valid_option
51 local($option) = @_;
53 if ($option =~ /^-make([-_]?path)?$/i) {
54 $make_path = shift @argv;
55 if (!-f $make_path) {
56 print "$option $make_path: Not found.\n";
57 exit 0;
59 return 1;
62 if ($option =~ /^-all([-_]?tests)?$/i) {
63 $all_tests = 1;
64 return 1;
67 if ($option =~ /^-(valgrind|memcheck)$/i) {
68 $valgrind = 1;
69 $valgrind_args = $memcheck_args;
70 return 1;
73 if ($option =~ /^-massif$/i) {
74 $valgrind = 1;
75 $valgrind_args = $massif_args;
76 return 1;
79 # This doesn't work--it _should_! Someone badly needs to fix this.
81 # elsif ($option =~ /^-work([-_]?dir)?$/)
82 # {
83 # $workdir = shift @argv;
84 # return 1;
85 # }
87 return 0;
91 # This is an "all-in-one" function. Arguments are as follows:
93 # [0] (string): The makefile to be tested. undef means use the last one.
94 # [1] (string): Arguments to pass to make.
95 # [2] (string): Answer we should get back.
96 # [3] (integer): Exit code we expect. A missing code means 0 (success)
98 $old_makefile = undef;
100 sub subst_make_string
102 local $_ = shift;
103 $makefile and s/#MAKEFILE#/$makefile/g;
104 s/#MAKEPATH#/$mkpath/g;
105 s/#MAKE#/$make_name/g;
106 s/#PERL#/$perl_name/g;
107 s/#PWD#/$pwd/g;
108 return $_;
111 sub run_make_test
113 local ($makestring, $options, $answer, $err_code, $timeout) = @_;
115 # If the user specified a makefile string, create a new makefile to contain
116 # it. If the first value is not defined, use the last one (if there is
117 # one).
119 if (! defined $makestring) {
120 defined $old_makefile
121 || die "run_make_test(undef) invoked before run_make_test('...')\n";
122 $makefile = $old_makefile;
123 } else {
124 if (! defined($makefile)) {
125 $makefile = &get_tmpfile();
128 # Make sure it ends in a newline and substitute any special tokens.
129 $makestring && $makestring !~ /\n$/s and $makestring .= "\n";
130 $makestring = subst_make_string($makestring);
132 # Populate the makefile!
133 open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
134 print MAKEFILE $makestring;
135 close(MAKEFILE) || die "Failed to write $makefile: $!\n";
138 # Do the same processing on $answer as we did on $makestring.
139 $answer && $answer !~ /\n$/s and $answer .= "\n";
140 $answer = subst_make_string($answer);
142 run_make_with_options($makefile, $options, &get_logfile(0),
143 $err_code, $timeout);
144 &compare_output($answer, &get_logfile(1));
146 $old_makefile = $makefile;
147 $makefile = undef;
150 # The old-fashioned way...
151 sub run_make_with_options {
152 local ($filename,$options,$logname,$expected_code,$timeout) = @_;
153 local($code);
154 local($command) = $make_path;
156 $expected_code = 0 unless defined($expected_code);
158 # Reset to reflect this one test.
159 $test_passed = 1;
161 if ($filename) {
162 $command .= " -f $filename";
165 if ($options) {
166 $command .= " $options";
169 $command_string = "$command\n";
171 if ($valgrind) {
172 print VALGRIND "\n\nExecuting: $command\n";
177 my $old_timeout = $test_timeout;
178 $timeout and $test_timeout = $timeout;
180 # If valgrind is enabled, turn off the timeout check
181 $valgrind and $test_timeout = 0;
183 $code = &run_command_with_output($logname,$command);
185 $test_timeout = $old_timeout;
188 # Check to see if we have Purify errors. If so, keep the logfile.
189 # For this to work you need to build with the Purify flag -exit-status=yes
191 if ($pure_log && -f $pure_log) {
192 if ($code & 0x7000) {
193 $code &= ~0x7000;
195 # If we have a purify log, save it
196 $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
197 print("Renaming purify log file to $tn\n") if $debug;
198 rename($pure_log, "$tn")
199 || die "Can't rename $log to $tn: $!\n";
200 ++$purify_errors;
201 } else {
202 unlink($pure_log);
206 if ($code != $expected_code) {
207 print "Error running $make_path (expected $expected_code; got $code): $command\n";
208 $test_passed = 0;
209 $runf = &get_runfile;
210 &create_file (&get_runfile, $command_string);
211 # If it's a SIGINT, stop here
212 if ($code & 127) {
213 print STDERR "\nCaught signal ".($code & 127)."!\n";
214 ($code & 127) == 2 and exit($code);
216 return 0;
219 if ($profile & $vos) {
220 system "add_profile $make_path";
223 return 1;
226 sub print_usage
228 &print_standard_usage ("run_make_tests",
229 "[-make_path make_pathname] [-memcheck] [-massif]",);
232 sub print_help
234 &print_standard_help (
235 "-make_path",
236 "\tYou may specify the pathname of the copy of make to run.",
237 "-valgrind",
238 "-memcheck",
239 "\tRun the test suite under valgrind's memcheck tool.",
240 "\tChange the default valgrind args with the VALGRIND_ARGS env var.",
241 "-massif",
242 "\tRun the test suite under valgrind's massif toool.",
243 "\tChange the default valgrind args with the VALGRIND_ARGS env var."
247 sub get_this_pwd {
248 $delete_command = 'rm -f';
249 if ($has_POSIX) {
250 $__pwd = POSIX::getcwd();
251 } elsif ($vos) {
252 $delete_command = "delete_file -no_ask";
253 $__pwd = `++(current_dir)`;
254 } else {
255 # No idea... just try using pwd as a last resort.
256 chop ($__pwd = `pwd`);
259 return $__pwd;
262 sub set_defaults
264 # $profile = 1;
265 $testee = "GNU make";
266 $make_path = "make";
267 $tmpfilesuffix = "mk";
268 $pwd = &get_this_pwd;
271 sub set_more_defaults
273 local($string);
274 local($index);
276 # find the type of the port. We do this up front to have a single
277 # point of change if it needs to be tweaked.
279 # This is probably not specific enough.
281 if ($osname =~ /Windows/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) {
282 $port_type = 'W32';
284 # Bleah, the osname is so variable on DOS. This kind of bites.
285 # Well, as far as I can tell if we check for some text at the
286 # beginning of the line with either no spaces or a single space, then
287 # a D, then either "OS", "os", or "ev" and a space. That should
288 # match and be pretty specific.
289 elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
290 $port_type = 'DOS';
292 # Check for OS/2
293 elsif ($osname =~ m%OS/2%) {
294 $port_type = 'OS/2';
296 # Everything else, right now, is UNIX. Note that we should integrate
297 # the VOS support into this as well and get rid of $vos; we'll do
298 # that next time.
299 else {
300 $port_type = 'UNIX';
303 # On DOS/Windows system the filesystem apparently can't track
304 # timestamps with second granularity (!!). Change the sleep time
305 # needed to force a file to be considered "old".
306 $wtime = $port_type eq 'UNIX' ? 1 : $port_type eq 'OS/2' ? 2 : 4;
308 print "Port type: $port_type\n" if $debug;
309 print "Make path: $make_path\n" if $debug;
311 # Find the full pathname of Make. For DOS systems this is more
312 # complicated, so we ask make itself.
313 my $mk = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
314 chop $mk;
315 $mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE):\n
316 'echo \"all:;\@echo \\\$(MAKE)\" | $make_path -f-' failed!\n";
317 $make_path = $mk;
318 print "Make\t= '$make_path'\n" if $debug;
320 $string = `$make_path -v -f /dev/null 2> /dev/null`;
322 $string =~ /^(GNU Make [^,\n]*)/;
323 $testee_version = "$1\n";
325 $string = `sh -c "$make_path -f /dev/null 2>&1"`;
326 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
327 $make_name = $1;
329 else {
330 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
331 $make_name = $1;
333 else {
334 $make_name = $make_path;
338 # prepend pwd if this is a relative path (ie, does not
339 # start with a slash, but contains one). Thanks for the
340 # clue, Roland.
342 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
344 $mkpath = "$pwd$pathsep$make_path";
346 else
348 $mkpath = $make_path;
351 # Get Purify log info--if any.
353 if (exists $ENV{PURIFYOPTIONS}
354 && $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/) {
355 $pure_log = $1 || '';
356 $pure_log =~ s/%v/$make_name/;
357 $purify_errors = 0;
360 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
361 if ($string =~ /not supported/) {
362 $parallel_jobs = 0;
364 else {
365 $parallel_jobs = 1;
368 %FEATURES = map { $_ => 1 } split /\s+/, `sh -c "echo '\\\$(info \\\$(.FEATURES))' | $make_path -f- 2>/dev/null"`;
370 # Set up for valgrind, if requested.
372 if ($valgrind) {
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";
379 # F_SETFD is 2
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";
386 sub setup_for_test
388 $makefile = &get_tmpfile;
389 if (-f $makefile) {
390 unlink $makefile;
393 # Get rid of any Purify logs.
394 if ($pure_log) {
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;
402 exit !&toplevel;