Fix bug#1379: don't use alloca() where it could overrun the stack size.
[make/kirr.git] / tests / run_make_tests.pl
blob0ada574ffa91f7335e686f6dc5a01f93e1d31a2f
1 #!/usr/local/bin/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 $valgrind = 0; # invoke make with valgrind
16 require "test_driver.pl";
18 #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
20 sub valid_option
22 local($option) = @_;
24 if ($option =~ /^-make([-_]?path)?$/)
26 $make_path = shift @argv;
27 if (!-f $make_path)
29 print "$option $make_path: Not found.\n";
30 exit 0;
32 return 1;
35 if ($option =~ /^-valgrind$/i) {
36 $valgrind = 1;
37 return 1;
40 # This doesn't work--it _should_! Someone needs to fix this badly.
42 # elsif ($option =~ /^-work([-_]?dir)?$/)
43 # {
44 # $workdir = shift @argv;
45 # return 1;
46 # }
48 return 0;
51 sub run_make_with_options
53 local ($filename,$options,$logname,$expected_code) = @_;
54 local($code);
55 local($command) = $make_path;
57 $expected_code = 0 unless defined($expected_code);
59 if ($filename)
61 $command .= " -f $filename";
64 if ($options)
66 $command .= " $options";
69 if ($valgrind) {
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) {
79 if ($code & 0x7000) {
80 $code &= ~0x7000;
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";
87 ++$purify_errors;
89 else {
90 unlink($pure_log);
94 if ($code != $expected_code)
96 print "Error running $make_path ($code): $command\n";
97 $test_passed = 0;
98 # If it's a SIGINT, stop here
99 if ($code & 127) {
100 print STDERR "\nCaught signal ".($code & 127)."!\n";
101 exit($code);
103 return 0;
106 if ($profile & $vos)
108 system "add_profile $make_path";
113 sub print_usage
115 &print_standard_usage ("run_make_tests", "[-make_path make_pathname]");
118 sub print_help
120 &print_standard_help ("-make_path",
121 "\tYou may specify the pathname of the copy of make to run.");
124 sub get_this_pwd {
125 if ($vos) {
126 $delete_command = "delete_file";
127 $__pwd = `++(current_dir)`;
129 else {
130 $delete_command = "rm";
131 chop ($__pwd = `pwd`);
134 return $__pwd;
137 sub set_defaults
139 # $profile = 1;
140 $testee = "GNU make";
141 $make_path = "make";
142 $tmpfilesuffix = "mk";
143 $pwd = &get_this_pwd;
146 sub set_more_defaults
148 local($string);
149 local($index);
151 # Make sure we're in the C locale for those systems that support it,
152 # so sorting, etc. is predictable.
154 $ENV{LANG} = 'C';
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) {
162 $port_type = 'W32';
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) /) {
170 $port_type = 'DOS';
172 # Everything else, right now, is UNIX. Note that we should integrate
173 # the VOS support into this as well and get rid of $vos; we'll do
174 # that next time.
175 else {
176 $port_type = 'UNIX';
179 # On DOS/Windows system the filesystem apparently can't track
180 # timestamps with second granularity (!!). Change the sleep time
181 # needed to force a file to be considered "old".
183 $wtime = $port_type eq 'UNIX' ? 1 : 4;
185 # Find the full pathname of Make. For DOS systems this is more
186 # complicated, so we ask make itself.
188 $make_path = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
189 chop $make_path;
190 print "Make\t= `$make_path'\n" if $debug;
192 $string = `$make_path -v -f /dev/null 2> /dev/null`;
194 $string =~ /^(GNU Make [^,\n]*)/;
195 $testee_version = "$1\n";
197 $string = `sh -c "$make_path -f /dev/null 2>&1"`;
198 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
199 $make_name = $1;
201 else {
202 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
203 $make_name = $1;
205 else {
206 $make_name = $make_path;
210 # prepend pwd if this is a relative path (ie, does not
211 # start with a slash, but contains one). Thanks for the
212 # clue, Roland.
214 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
216 $mkpath = "$pwd$pathsep$make_path";
218 else
220 $mkpath = $make_path;
223 # Get Purify log info--if any.
225 $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/;
226 $pure_log = $1 || '';
227 $pure_log =~ s/%v/$make_name/;
228 $purify_errors = 0;
230 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
231 if ($string =~ /not supported/) {
232 $parallel_jobs = 0;
234 else {
235 $parallel_jobs = 1;
238 # Set up for valgrind, if requested.
240 if ($valgrind) {
241 # use POSIX qw(:fcntl_h);
242 # require Fcntl;
243 open(VALGRIND, "> valgrind.out")
244 || die "Cannot open valgrind.out: $!\n";
245 # -q --leak-check=yes
246 $make_path = "valgrind --num-callers=15 --logfile-fd=".fileno(VALGRIND)." $make_path";
247 # F_SETFD is 2
248 fcntl(VALGRIND, 2, 0) or die "fcntl(setfd) failed: $!\n";
249 system("echo Starting on `date` 1>&".fileno(VALGRIND));
250 print "Enabled valgrind support.\n";
254 sub setup_for_test
256 $makefile = &get_tmpfile;
257 if (-f $makefile) {
258 unlink $makefile;
261 # Get rid of any Purify logs.
262 if ($pure_log) {
263 ($pure_testname = $testname) =~ tr,/,_,;
264 $pure_testname = "$pure_log.$pure_testname";
265 system("rm -f $pure_testname*");
266 print("Purify testfiles are: $pure_testname*\n") if $debug;
270 exit !&toplevel;