4 # Test driver for the Make test suite
6 # Usage: run_make_tests [testname]
14 $valgrind = 0; # invoke make with valgrind
16 require "test_driver.pl";
18 #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
24 if ($option =~ /^-make([-_]?path)?$/)
26 $make_path = shift @argv;
29 print "$option $make_path: Not found.\n";
35 if ($option =~ /^-valgrind$/i) {
40 # This doesn't work--it _should_! Someone needs to fix this badly.
42 # elsif ($option =~ /^-work([-_]?dir)?$/)
44 # $workdir = shift @argv;
51 sub run_make_with_options
53 local ($filename,$options,$logname,$expected_code) = @_;
55 local($command) = $make_path;
57 $expected_code = 0 unless defined($expected_code);
61 $command .= " -f $filename";
66 $command .= " $options";
70 print VALGRIND
"\n\nExecuting: $command\n";
73 $code = &run_command_with_output
($logname,$command);
75 # Check to see if we have Purify errors. If so, keep the logfile.
76 # For this to work you need to build with the Purify flag -exit-status=yes
78 if ($pure_log && -f
$pure_log) {
82 # If we have a purify log, save it
83 $tn = $pure_testname . ($num_of_logfiles ?
".$num_of_logfiles" : "");
84 print("Renaming purify log file to $tn\n") if $debug;
85 rename($pure_log, "$tn")
86 || die "Can't rename $log to $tn: $!\n";
94 if ($code != $expected_code)
96 print "Error running $make_path ($code): $command\n";
98 # If it's a SIGINT, stop here
100 print STDERR
"\nCaught signal ".($code & 127)."!\n";
108 system "add_profile $make_path";
115 &print_standard_usage
("run_make_tests", "[-make_path make_pathname]");
120 &print_standard_help
("-make_path",
121 "\tYou may specify the pathname of the copy of make to run.");
126 $delete_command = "delete_file";
127 $__pwd = `++(current_dir)`;
130 $delete_command = "rm";
131 chop ($__pwd = `pwd`);
140 $testee = "GNU make";
142 $tmpfilesuffix = "mk";
143 $pwd = &get_this_pwd
;
146 sub set_more_defaults
151 # Make sure we're in the C locale for those systems that support it,
152 # so sorting, etc. is predictable.
156 # find the type of the port. We do this up front to have a single
157 # point of change if it needs to be tweaked.
159 # This is probably not specific enough.
161 if ($osname =~ /Windows/i) {
164 # Bleah, the osname is so variable on DOS. This kind of bites.
165 # Well, as far as I can tell if we check for some text at the
166 # beginning of the line with either no spaces or a single space, then
167 # a D, then either "OS", "os", or "ev" and a space. That should
168 # match and be pretty specific.
169 elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
173 elsif ($osname =~ m
%OS/2%) {
176 # Everything else, right now, is UNIX. Note that we should integrate
177 # the VOS support into this as well and get rid of $vos; we'll do
183 # On DOS/Windows system the filesystem apparently can't track
184 # timestamps with second granularity (!!). Change the sleep time
185 # needed to force a file to be considered "old".
187 $wtime = $port_type eq 'UNIX' ?
1 : $port_type eq 'OS/2' ?
2 : 4;
189 # Find the full pathname of Make. For DOS systems this is more
190 # complicated, so we ask make itself.
192 $make_path = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
194 print "Make\t= `$make_path'\n" if $debug;
196 $string = `$make_path -v -f /dev/null 2> /dev/null`;
198 $string =~ /^(GNU Make [^,\n]*)/;
199 $testee_version = "$1\n";
201 $string = `sh -c "$make_path -f /dev/null 2>&1"`;
202 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
206 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
210 $make_name = $make_path;
214 # prepend pwd if this is a relative path (ie, does not
215 # start with a slash, but contains one). Thanks for the
218 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
220 $mkpath = "$pwd$pathsep$make_path";
224 $mkpath = $make_path;
227 # Get Purify log info--if any.
229 $ENV{PURIFYOPTIONS
} =~ /.*-logfile=([^ ]+)/;
230 $pure_log = $1 || '';
231 $pure_log =~ s/%v/$make_name/;
234 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
235 if ($string =~ /not supported/) {
242 # Set up for valgrind, if requested.
245 # use POSIX qw(:fcntl_h);
247 open(VALGRIND
, "> valgrind.out")
248 || die "Cannot open valgrind.out: $!\n";
249 # -q --leak-check=yes
250 $make_path = "valgrind --num-callers=15 --logfile-fd=".fileno(VALGRIND
)." $make_path";
252 fcntl(VALGRIND
, 2, 0) or die "fcntl(setfd) failed: $!\n";
253 system("echo Starting on `date` 1>&".fileno(VALGRIND
));
254 print "Enabled valgrind support.\n";
260 $makefile = &get_tmpfile
;
265 # Get rid of any Purify logs.
267 ($pure_testname = $testname) =~ tr
,/,_
,;
268 $pure_testname = "$pure_log.$pure_testname";
269 system("rm -f $pure_testname*");
270 print("Purify testfiles are: $pure_testname*\n") if $debug;