* New config.sub and config.guess
[make.git] / tests / run_make_tests.pl
blobbaf55f8fa619b5104309bc3fd8c412ab1440fe71
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 require "test_driver.pl";
16 sub valid_option
18 local($option) = @_;
19 if ($option =~ /^-make([-_]?path)?$/)
21 $make_path = shift @argv;
22 if (!-f $make_path)
24 print "$option $make_path: Not found.\n";
25 exit 0;
27 return 1;
30 # This doesn't work--it _should_! Someone needs to fix this badly.
32 # elsif ($option =~ /^-work([-_]?dir)?$/)
33 # {
34 # $workdir = shift @argv;
35 # return 1;
36 # }
38 return 0;
41 sub run_make_with_options
43 local ($filename,$options,$logname,$expected_code) = @_;
44 local($code);
45 local($command) = $make_path;
47 $expected_code = 0 unless defined($expected_code);
49 if ($filename)
51 $command .= " -f $filename";
54 if ($options)
56 $command .= " $options";
59 $code = &run_command_with_output($logname,$command);
61 # Check to see if we have Purify errors. If so, keep the logfile.
62 # For this to work you need to build with the Purify flag -exit-status=yes
64 if ($pure_log && -f $pure_log) {
65 if ($code & 0x7000) {
66 $code &= ~0x7000;
68 # If we have a purify log, save it
69 $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
70 print("Renaming purify log file to $tn\n") if $debug;
71 rename($pure_log, "$tn")
72 || die "Can't rename $log to $tn: $!\n";
73 ++$purify_errors;
75 else {
76 unlink($pure_log);
80 if ($code != $expected_code)
82 print "Error running $make_path ($code): $command\n";
83 $test_passed = 0;
84 return 0;
87 if ($profile & $vos)
89 system "add_profile $make_path";
94 sub print_usage
96 &print_standard_usage ("run_make_tests", "[-make_path make_pathname]");
99 sub print_help
101 &print_standard_help ("-make_path",
102 "\tYou may specify the pathname of the copy of make to run.");
105 sub get_this_pwd {
106 if ($vos) {
107 $delete_command = "delete_file";
108 $__pwd = `++(current_dir)`;
110 else {
111 $delete_command = "rm";
112 chop ($__pwd = `pwd`);
115 return $__pwd;
118 sub set_defaults
120 # $profile = 1;
121 $testee = "GNU make";
122 $make_path = "make";
123 $tmpfilesuffix = "mk";
124 $pwd = &get_this_pwd;
127 sub set_more_defaults
129 local($string);
130 local($index);
132 # Make sure we're in the C locale for those systems that support it,
133 # so sorting, etc. is predictable.
135 $ENV{LANG} = 'C';
137 # find the type of the port. We do this up front to have a single
138 # point of change if it needs to be tweaked.
140 # This is probably not specific enough.
142 if ($osname =~ /Windows/i) {
143 $port_type = 'W32';
145 # Bleah, the osname is so variable on DOS. This kind of bites.
146 # Well, as far as I can tell if we check for some text at the
147 # beginning of the line with either no spaces or a single space, then
148 # a D, then either "OS", "os", or "ev" and a space. That should
149 # match and be pretty specific.
150 elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
151 $port_type = 'DOS';
153 # Everything else, right now, is UNIX. Note that we should integrate
154 # the VOS support into this as well and get rid of $vos; we'll do
155 # that next time.
156 else {
157 $port_type = 'UNIX';
160 # On DOS/Windows system the filesystem apparently can't track
161 # timestamps with second granularity (!!). Change the sleep time
162 # needed to force a file to be considered "old".
164 $wtime = $port_type eq 'UNIX' ? 1 : 4;
166 # Find the full pathname of Make. For DOS systems this is more
167 # complicated, so we ask make itself.
169 $make_path = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
170 chop $make_path;
171 print "Make\t= `$make_path'\n" if $debug;
173 $string = `$make_path -v -f /dev/null 2> /dev/null`;
175 $string =~ /^(GNU Make [^,\n]*)/;
176 $testee_version = "$1\n";
178 $string = `sh -c "$make_path -f /dev/null 2>&1"`;
179 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
180 $make_name = $1;
182 else {
183 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
184 $make_name = $1;
186 else {
187 $make_name = $make_path;
191 # prepend pwd if this is a relative path (ie, does not
192 # start with a slash, but contains one). Thanks for the
193 # clue, Roland.
195 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
197 $mkpath = "$pwd$pathsep$make_path";
199 else
201 $mkpath = $make_path;
204 # Get Purify log info--if any.
206 $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/;
207 $pure_log = $1 || '';
208 $pure_log =~ s/%v/$make_name/;
209 $purify_errors = 0;
211 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
212 if ($string =~ /not supported/) {
213 $parallel_jobs = 0;
215 else {
216 $parallel_jobs = 1;
220 sub setup_for_test
222 $makefile = &get_tmpfile;
223 if (-f $makefile) {
224 unlink $makefile;
227 # Get rid of any Purify logs.
228 if ($pure_log) {
229 ($pure_testname = $testname) =~ tr,/,_,;
230 $pure_testname = "$pure_log.$pure_testname";
231 system("rm -f $pure_testname*");
232 print("Purify testfiles are: $pure_testname*\n") if $debug;
236 exit !&toplevel;