VirtualBox

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

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

Merged in current GNU Make code (CVS from 2008-10-28). Ref #55.

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