This commit was manufactured by cvs2svn to create tag
[kbuild-mirror.git] / src / gmake / tests / run_make_tests.pl
blob4389d4349f26fe182eecc65abb7501c62712eedc
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 # Check for OS/2
173 elsif ($osname =~ m%OS/2%) {
174 $port_type = '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
178 # that next time.
179 else {
180 $port_type = 'UNIX';
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-'`;
193 chop $make_path;
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\./) {
203 $make_name = $1;
205 else {
206 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
207 $make_name = $1;
209 else {
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
216 # clue, Roland.
218 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
220 $mkpath = "$pwd$pathsep$make_path";
222 else
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/;
232 $purify_errors = 0;
234 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
235 if ($string =~ /not supported/) {
236 $parallel_jobs = 0;
238 else {
239 $parallel_jobs = 1;
242 # Set up for valgrind, if requested.
244 if ($valgrind) {
245 # use POSIX qw(:fcntl_h);
246 # require Fcntl;
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";
251 # F_SETFD is 2
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";
258 sub setup_for_test
260 $makefile = &get_tmpfile;
261 if (-f $makefile) {
262 unlink $makefile;
265 # Get rid of any Purify logs.
266 if ($pure_log) {
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;
274 exit !&toplevel;