VirtualBox

source: kBuild/trunk/src/kmk/tests/run_make_tests.pl@ 1970

Last change on this file since 1970 was 1970, checked in by bird, 16 years ago

scripts/variables/flavors: last test isn't -jX safe.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 9.7 KB
Line 
1#!/usr/bin/env perl
2# -*-perl-*-
3
4# Test driver for the Make test suite
5
6# Usage: run_make_tests [testname]
7# [-debug]
8# [-help]
9# [-verbose]
10# [-keep]
11# [-make <make prog>]
12# (and others)
13
14# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
15# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
16# This file is part of GNU Make.
17#
18# GNU Make is free software; you can redistribute it and/or modify it under the
19# terms of the GNU General Public License as published by the Free Software
20# Foundation; either version 2, or (at your option) any later version.
21#
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 FOR
24# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
25#
26# You should have received a copy of the GNU General Public License along with
27# GNU Make; see the file COPYING. If not, write to the Free Software
28# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29
30$valgrind = 0; # invoke make with valgrind
31$valgrind_args = '--num-callers=15 --tool=memcheck --leak-check=full';
32$pure_log = undef;
33
34require "test_driver.pl";
35
36# Some target systems might not have the POSIX module...
37$has_POSIX = eval { require "POSIX.pm" };
38
39#$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
40
41sub valid_option
42{
43 local($option) = @_;
44
45 if ($option =~ /^-make([-_]?path)?$/)
46 {
47 $make_path = shift @argv;
48 if (!-f $make_path)
49 {
50 print "$option $make_path: Not found.\n";
51 exit 0;
52 }
53 return 1;
54 }
55
56 if ($option =~ /^-valgrind$/i) {
57 $valgrind = 1;
58 return 1;
59 }
60
61# This doesn't work--it _should_! Someone badly needs to fix this.
62#
63# elsif ($option =~ /^-work([-_]?dir)?$/)
64# {
65# $workdir = shift @argv;
66# return 1;
67# }
68
69 return 0;
70}
71
72
73# This is an "all-in-one" function. Arguments are as follows:
74#
75# [0] (string): The makefile to be tested. undef means use the last one.
76# [1] (string): Arguments to pass to make.
77# [2] (string): Answer we should get back.
78# [3] (integer): Exit code we expect. A missing code means 0 (success)
79
80$old_makefile = undef;
81
82sub run_make_test
83{
84 local ($makestring, $options, $answer, $err_code) = @_;
85
86 # If the user specified a makefile string, create a new makefile to contain
87 # it. If the first value is not defined, use the last one (if there is
88 # one).
89
90 if (! defined $makestring) {
91 defined $old_makefile
92 || die "run_make_test(undef) invoked before run_make_test('...')\n";
93 $makefile = $old_makefile;
94 } else {
95 if (! defined($makefile)) {
96 $makefile = &get_tmpfile();
97 }
98
99 # Make sure it ends in a newline.
100 $makestring && $makestring !~ /\n$/s and $makestring .= "\n";
101
102 # Replace @MAKEFILE@ with the makefile name and @MAKE@ with the path to
103 # make
104 $makestring =~ s/#MAKEFILE#/$makefile/g;
105 $makestring =~ s/#MAKEPATH#/$mkpath/g;
106 $makestring =~ s/#MAKE#/$make_name/g;
107 $makestring =~ s/#PWD#/$pwd/g;
108
109 # Populate the makefile!
110 open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
111 print MAKEFILE $makestring;
112 close(MAKEFILE) || die "Failed to write $makefile: $!\n";
113 }
114
115 # Do the same processing on $answer as we did on $makestring.
116
117 $answer && $answer !~ /\n$/s and $answer .= "\n";
118 $answer =~ s/#MAKEFILE#/$makefile/g;
119 $answer =~ s/#MAKEPATH#/$mkpath/g;
120 $answer =~ s/#MAKE#/$make_name/g;
121 $answer =~ s/#PWD#/$pwd/g;
122
123 &run_make_with_options($makefile, $options, &get_logfile(0), $err_code);
124 &compare_output($answer, &get_logfile(1));
125
126 $old_makefile = $makefile;
127 $makefile = undef;
128}
129
130# The old-fashioned way...
131sub run_make_with_options {
132 local ($filename,$options,$logname,$expected_code) = @_;
133 local($code);
134 local($command) = $make_path;
135
136 $expected_code = 0 unless defined($expected_code);
137
138 # Reset to reflect this one test.
139 $test_passed = 1;
140
141 if ($filename) {
142 $command .= " -f $filename";
143 }
144
145 if ($options) {
146 $command .= " $options";
147 } elsif ($is_kmk) {
148# $command .= " -j1";
149 }
150
151 if ($valgrind) {
152 print VALGRIND "\n\nExecuting: $command\n";
153 }
154
155 $code = &run_command_with_output($logname,$command);
156
157 # Check to see if we have Purify errors. If so, keep the logfile.
158 # For this to work you need to build with the Purify flag -exit-status=yes
159
160 if ($pure_log && -f $pure_log) {
161 if ($code & 0x7000) {
162 $code &= ~0x7000;
163
164 # If we have a purify log, save it
165 $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
166 print("Renaming purify log file to $tn\n") if $debug;
167 rename($pure_log, "$tn")
168 || die "Can't rename $log to $tn: $!\n";
169 ++$purify_errors;
170 } else {
171 unlink($pure_log);
172 }
173 }
174
175 if ($code != $expected_code) {
176 print "Error running $make_path (expected $expected_code; got $code): $command\n";
177 $test_passed = 0;
178 # If it's a SIGINT, stop here
179 if ($code & 127) {
180 print STDERR "\nCaught signal ".($code & 127)."!\n";
181 exit($code);
182 }
183 return 0;
184 }
185
186 if ($profile & $vos) {
187 system "add_profile $make_path";
188 }
189
190 1;
191}
192
193sub print_usage
194{
195 &print_standard_usage ("run_make_tests",
196 "[-make_path make_pathname] [-valgrind]",);
197}
198
199sub print_help
200{
201 &print_standard_help ("-make_path",
202 "\tYou may specify the pathname of the copy of make to run.");
203}
204
205sub get_this_pwd {
206 $delete_command = 'rm -f';
207 if ($has_POSIX) {
208 $__pwd = POSIX::getcwd();
209 } elsif ($vos) {
210 $delete_command = "delete_file -no_ask";
211 $__pwd = `++(current_dir)`;
212 } else {
213 # No idea... just try using pwd as a last resort.
214 chop ($__pwd = `pwd`);
215 }
216
217 return $__pwd;
218}
219
220sub set_defaults
221{
222 # $profile = 1;
223 $testee = "GNU make";
224 $make_path = "make";
225 $tmpfilesuffix = "mk";
226 $pwd = &get_this_pwd;
227}
228
229sub set_more_defaults
230{
231 local($string);
232 local($index);
233
234 # find the type of the port. We do this up front to have a single
235 # point of change if it needs to be tweaked.
236 #
237 # This is probably not specific enough.
238 #
239 if ($osname =~ /Windows/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) {
240 $port_type = 'W32';
241 }
242 # Bleah, the osname is so variable on DOS. This kind of bites.
243 # Well, as far as I can tell if we check for some text at the
244 # beginning of the line with either no spaces or a single space, then
245 # a D, then either "OS", "os", or "ev" and a space. That should
246 # match and be pretty specific.
247 elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
248 $port_type = 'DOS';
249 }
250 # Check for OS/2
251 elsif ($osname =~ m%OS/2%) {
252 $port_type = 'OS/2';
253 }
254 # Everything else, right now, is UNIX. Note that we should integrate
255 # the VOS support into this as well and get rid of $vos; we'll do
256 # that next time.
257 else {
258 $port_type = 'UNIX';
259 }
260
261 # On DOS/Windows system the filesystem apparently can't track
262 # timestamps with second granularity (!!). Change the sleep time
263 # needed to force a file to be considered "old".
264 $wtime = $port_type eq 'UNIX' ? 1 : $port_type eq 'OS/2' ? 2 : 4;
265
266 print "Port type: $port_type\n" if $debug;
267 print "Make path: $make_path\n" if $debug;
268 print "fs type : case insensitive\n" if $debug && $case_insensitive_fs;
269
270 # Find the full pathname of Make. For DOS systems this is more
271 # complicated, so we ask make itself.
272 my $mk = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
273 chop $mk;
274 $mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE):\n
275'echo \"all:;\@echo \\\$(MAKE)\" | $make_path -f-' failed!\n";
276 $make_path = $mk;
277 print "Make\t= `$make_path'\n" if $debug;
278
279 $string = `$make_path -v -f /dev/null 2> /dev/null`;
280
281 $string =~ /^(GNU Make [^,\n]*)/;
282 $testee_version = "$1\n";
283
284 $string = `sh -c "$make_path -f /dev/null 2>&1"`;
285 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
286 $make_name = $1;
287 }
288 else {
289 if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
290 $make_name = $1;
291 }
292 else {
293 $make_name = $make_path;
294 }
295 }
296
297 # prepend pwd if this is a relative path (ie, does not
298 # start with a slash, but contains one). Thanks for the
299 # clue, Roland.
300
301 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
302 {
303 $mkpath = "$pwd$pathsep$make_path";
304 }
305 else
306 {
307 $mkpath = $make_path;
308 }
309
310 # Get Purify log info--if any.
311
312 if (exists $ENV{PURIFYOPTIONS}
313 && $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/) {
314 $pure_log = $1 || '';
315 $pure_log =~ s/%v/$make_name/;
316 $purify_errors = 0;
317 }
318
319 $string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
320 if ($string =~ /not supported/) {
321 $parallel_jobs = 0;
322 }
323 else {
324 $parallel_jobs = 1;
325 }
326
327 # Set up for valgrind, if requested.
328
329 if ($valgrind) {
330 open(VALGRIND, "> valgrind.out")
331 || die "Cannot open valgrind.out: $!\n";
332 # -q --leak-check=yes
333 exists $ENV{VALGRIND_ARGS} and $valgrind_args = $ENV{VALGRIND_ARGS};
334 $make_path = "valgrind --log-fd=".fileno(VALGRIND)." $valgrind_args $make_path";
335 # F_SETFD is 2
336 fcntl(VALGRIND, 2, 0) or die "fcntl(setfd) failed: $!\n";
337 system("echo Starting on `date` 1>&".fileno(VALGRIND));
338 print "Enabled valgrind support.\n";
339 }
340}
341
342sub setup_for_test
343{
344 $makefile = &get_tmpfile;
345 if (-f $makefile) {
346 unlink $makefile;
347 }
348
349 # Get rid of any Purify logs.
350 if ($pure_log) {
351 ($pure_testname = $testname) =~ tr,/,_,;
352 $pure_testname = "$pure_log.$pure_testname";
353 system("rm -f $pure_testname*");
354 print("Purify testfiles are: $pure_testname*\n") if $debug;
355 }
356}
357
358exit !&toplevel;
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette