VirtualBox

source: kBuild/vendor/gnumake/current/tests/run_make_tests.pl

最後變更 在這個檔案是 3138,由 bird 提交於 7 年 前

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 13.8 KB
 
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-2016 Free Software Foundation, Inc.
15# This file is part of GNU Make.
16#
17# GNU Make is free software; you can redistribute it and/or modify it under
18# the terms of the GNU General Public License as published by the Free Software
19# Foundation; either version 3 of the License, or (at your option) any later
20# 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
24# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
25# details.
26#
27# You should have received a copy of the GNU General Public License along with
28# this program. If not, see <http://www.gnu.org/licenses/>.
29
30%FEATURES = ();
31
32$valgrind = 0; # invoke make with valgrind
33$valgrind_args = '';
34$memcheck_args = '--num-callers=15 --tool=memcheck --leak-check=full --suppressions=guile.supp';
35$massif_args = '--num-callers=15 --tool=massif --alloc-fn=xmalloc --alloc-fn=xcalloc --alloc-fn=xrealloc --alloc-fn=xstrdup --alloc-fn=xstrndup';
36$pure_log = undef;
37
38# The location of the GNU make source directory
39$srcdir = '';
40
41$command_string = '';
42
43$all_tests = 0;
44
45# rmdir broken in some Perls on VMS.
46if ($^O eq 'VMS')
47{
48 require VMS::Filespec;
49 VMS::Filespec->import();
50
51 sub vms_rmdir {
52 my $vms_file = vmspath($_[0]);
53 $vms_file = fileify($vms_file);
54 my $ret = unlink(vmsify($vms_file));
55 return $ret
56 };
57
58 *CORE::GLOBAL::rmdir = \&vms_rmdir;
59}
60
61require "test_driver.pl";
62require "config-flags.pm";
63
64# Some target systems might not have the POSIX module...
65$has_POSIX = eval { require "POSIX.pm" };
66
67#$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; };
68
69sub valid_option
70{
71 local($option) = @_;
72
73 if ($option =~ /^-make([-_]?path)?$/i) {
74 $make_path = shift @argv;
75 if (!-f $make_path) {
76 print "$option $make_path: Not found.\n";
77 exit 0;
78 }
79 return 1;
80 }
81
82 if ($option =~ /^-srcdir$/i) {
83 $srcdir = shift @argv;
84 if (! -f "$srcdir/gnumake.h") {
85 print "$option $srcdir: Not a valid GNU make source directory.\n";
86 exit 0;
87 }
88 return 1;
89 }
90
91 if ($option =~ /^-all([-_]?tests)?$/i) {
92 $all_tests = 1;
93 return 1;
94 }
95
96 if ($option =~ /^-(valgrind|memcheck)$/i) {
97 $valgrind = 1;
98 $valgrind_args = $memcheck_args;
99 return 1;
100 }
101
102 if ($option =~ /^-massif$/i) {
103 $valgrind = 1;
104 $valgrind_args = $massif_args;
105 return 1;
106 }
107
108# This doesn't work--it _should_! Someone badly needs to fix this.
109#
110# elsif ($option =~ /^-work([-_]?dir)?$/)
111# {
112# $workdir = shift @argv;
113# return 1;
114# }
115
116 return 0;
117}
118
119
120# This is an "all-in-one" function. Arguments are as follows:
121#
122# [0] (string): The makefile to be tested. undef means use the last one.
123# [1] (string): Arguments to pass to make.
124# [2] (string): Answer we should get back.
125# [3] (integer): Exit code we expect. A missing code means 0 (success)
126
127$old_makefile = undef;
128
129sub subst_make_string
130{
131 local $_ = shift;
132 $makefile and s/#MAKEFILE#/$makefile/g;
133 s/#MAKEPATH#/$mkpath/g;
134 s/#MAKE#/$make_name/g;
135 s/#PERL#/$perl_name/g;
136 s/#PWD#/$pwd/g;
137 return $_;
138}
139
140sub run_make_test
141{
142 local ($makestring, $options, $answer, $err_code, $timeout) = @_;
143 my @call = caller;
144
145 # If the user specified a makefile string, create a new makefile to contain
146 # it. If the first value is not defined, use the last one (if there is
147 # one).
148
149 if (! defined $makestring) {
150 defined $old_makefile
151 || die "run_make_test(undef) invoked before run_make_test('...')\n";
152 $makefile = $old_makefile;
153 } else {
154 if (! defined($makefile)) {
155 $makefile = &get_tmpfile();
156 }
157
158 # Make sure it ends in a newline and substitute any special tokens.
159 $makestring && $makestring !~ /\n$/s and $makestring .= "\n";
160 $makestring = subst_make_string($makestring);
161
162 # Populate the makefile!
163 open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
164 print MAKEFILE $makestring;
165 close(MAKEFILE) || die "Failed to write $makefile: $!\n";
166 }
167
168 # Do the same processing on $answer as we did on $makestring.
169 if (defined $answer) {
170 $answer && $answer !~ /\n$/s and $answer .= "\n";
171 $answer = subst_make_string($answer);
172 }
173
174 run_make_with_options($makefile, $options, &get_logfile(0),
175 $err_code, $timeout, @call);
176 &compare_output($answer, &get_logfile(1));
177
178 $old_makefile = $makefile;
179 $makefile = undef;
180}
181
182# The old-fashioned way...
183sub run_make_with_options {
184 my ($filename,$options,$logname,$expected_code,$timeout,@call) = @_;
185 @call = caller unless @call;
186 local($code);
187 local($command) = $make_path;
188
189 $expected_code = 0 unless defined($expected_code);
190
191 # Reset to reflect this one test.
192 $test_passed = 1;
193
194 if ($filename) {
195 $command .= " -f $filename";
196 }
197
198 if ($options) {
199 if ($^O eq 'VMS') {
200 # Try to make sure arguments are properly quoted.
201 # This does not handle all cases.
202
203 # VMS uses double quotes instead of single quotes.
204 $options =~ s/\'/\"/g;
205
206 # If the leading quote is inside non-whitespace, then the
207 # quote must be doubled, because it will be enclosed in another
208 # set of quotes.
209 $options =~ s/(\S)(\".*\")/$1\"$2\"/g;
210
211 # Options must be quoted to preserve case if not already quoted.
212 $options =~ s/(\S+)/\"$1\"/g;
213
214 # Special fixup for embedded quotes.
215 $options =~ s/(\"\".+)\"(\s+)\"(.+\"\")/$1$2$3/g;
216
217 $options =~ s/(\A)(?:\"\")(.+)(?:\"\")/$1\"$2\"/g;
218
219 # Special fixup for misc/general4 test.
220 $options =~ s/""\@echo" "cc""/\@echo cc"/;
221 $options =~ s/"\@echo link"""/\@echo link"/;
222
223 # Remove shell escapes expected to be removed by bash
224 if ($options !~ /path=pre/) {
225 $options =~ s/\\//g;
226 }
227
228 # special fixup for options/eval
229 $options =~ s/"--eval=\$\(info" "eval/"--eval=\$\(info eval/;
230
231 print ("Options fixup = -$options-\n") if $debug;
232 }
233 $command .= " $options";
234 }
235
236 $command_string = "";
237 if (@call) {
238 $command_string = "#$call[1]:$call[2]\n";
239 }
240 $command_string .= "$command\n";
241
242 if ($valgrind) {
243 print VALGRIND "\n\nExecuting: $command\n";
244 }
245
246
247 {
248 my $old_timeout = $test_timeout;
249 $timeout and $test_timeout = $timeout;
250
251 # If valgrind is enabled, turn off the timeout check
252 $valgrind and $test_timeout = 0;
253
254 $code = &run_command_with_output($logname,$command);
255 $test_timeout = $old_timeout;
256 }
257
258 # Check to see if we have Purify errors. If so, keep the logfile.
259 # For this to work you need to build with the Purify flag -exit-status=yes
260
261 if ($pure_log && -f $pure_log) {
262 if ($code & 0x7000) {
263 $code &= ~0x7000;
264
265 # If we have a purify log, save it
266 $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
267 print("Renaming purify log file to $tn\n") if $debug;
268 rename($pure_log, "$tn")
269 || die "Can't rename $log to $tn: $!\n";
270 ++$purify_errors;
271 } else {
272 unlink($pure_log);
273 }
274 }
275
276 if ($code != $expected_code) {
277 print "Error running $make_path (expected $expected_code; got $code): $command\n";
278 $test_passed = 0;
279 $runf = &get_runfile;
280 &create_file (&get_runfile, $command_string);
281 # If it's a SIGINT, stop here
282 if ($code & 127) {
283 print STDERR "\nCaught signal ".($code & 127)."!\n";
284 ($code & 127) == 2 and exit($code);
285 }
286 return 0;
287 }
288
289 if ($profile & $vos) {
290 system "add_profile $make_path";
291 }
292
293 return 1;
294}
295
296sub print_usage
297{
298 &print_standard_usage ("run_make_tests",
299 "[-make MAKE_PATHNAME] [-srcdir SRCDIR] [-memcheck] [-massif]",);
300}
301
302sub print_help
303{
304 &print_standard_help (
305 "-make",
306 "\tYou may specify the pathname of the copy of make to run.",
307 "-srcdir",
308 "\tSpecify the make source directory.",
309 "-valgrind",
310 "-memcheck",
311 "\tRun the test suite under valgrind's memcheck tool.",
312 "\tChange the default valgrind args with the VALGRIND_ARGS env var.",
313 "-massif",
314 "\tRun the test suite under valgrind's massif toool.",
315 "\tChange the default valgrind args with the VALGRIND_ARGS env var."
316 );
317}
318
319sub get_this_pwd {
320 $delete_command = 'rm -f';
321 if ($has_POSIX) {
322 $__pwd = POSIX::getcwd();
323 } elsif ($vos) {
324 $delete_command = "delete_file -no_ask";
325 $__pwd = `++(current_dir)`;
326 } else {
327 # No idea... just try using pwd as a last resort.
328 chop ($__pwd = `pwd`);
329 }
330
331 return $__pwd;
332}
333
334sub set_defaults
335{
336 # $profile = 1;
337 $testee = "GNU make";
338 $make_path = "make";
339 $tmpfilesuffix = "mk";
340 $pwd = &get_this_pwd;
341}
342
343sub set_more_defaults
344{
345 local($string);
346 local($index);
347
348 # find the type of the port. We do this up front to have a single
349 # point of change if it needs to be tweaked.
350 #
351 # This is probably not specific enough.
352 #
353 if ($osname =~ /Windows/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) {
354 $port_type = 'W32';
355 }
356 # Bleah, the osname is so variable on DOS. This kind of bites.
357 # Well, as far as I can tell if we check for some text at the
358 # beginning of the line with either no spaces or a single space, then
359 # a D, then either "OS", "os", or "ev" and a space. That should
360 # match and be pretty specific.
361 elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
362 $port_type = 'DOS';
363 }
364 # Check for OS/2
365 elsif ($osname =~ m%OS/2%) {
366 $port_type = 'OS/2';
367 }
368
369 # VMS has a GNV Unix mode or a DCL mode.
370 # The SHELL environment variable should not be defined in VMS-DCL mode.
371 elsif ($osname eq 'VMS' && !defined $ENV{"SHELL"}) {
372 $port_type = 'VMS-DCL';
373 }
374 # Everything else, right now, is UNIX. Note that we should integrate
375 # the VOS support into this as well and get rid of $vos; we'll do
376 # that next time.
377 else {
378 $port_type = 'UNIX';
379 }
380
381 # On DOS/Windows system the filesystem apparently can't track
382 # timestamps with second granularity (!!). Change the sleep time
383 # needed to force a file to be considered "old".
384 $wtime = $port_type eq 'UNIX' ? 1 : $port_type eq 'OS/2' ? 2 : 4;
385
386 print "Port type: $port_type\n" if $debug;
387 print "Make path: $make_path\n" if $debug;
388
389 # Find the full pathname of Make. For DOS systems this is more
390 # complicated, so we ask make itself.
391 if ($osname eq 'VMS') {
392 $port_type = 'VMS-DCL' unless defined $ENV{"SHELL"};
393 # On VMS pre-setup make to be found with simply 'make'.
394 $make_path = 'make';
395 } else {
396 my $mk = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
397 chop $mk;
398 $mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE):\n
399'echo \"all:;\@echo \\\$(MAKE)\" | $make_path -f-' failed!\n";
400 $make_path = $mk;
401 }
402 print "Make\t= '$make_path'\n" if $debug;
403
404 my $redir2 = '2> /dev/null';
405 $redir2 = '' if os_name eq 'VMS';
406 $string = `$make_path -v -f /dev/null $redir2`;
407
408 $string =~ /^(GNU Make [^,\n]*)/;
409 $testee_version = "$1\n";
410
411 my $redir = '2>&1';
412 $redir = '' if os_name eq 'VMS';
413 $string = `sh -c "$make_path -f /dev/null $redir"`;
414 if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
415 $make_name = $1;
416 }
417 else {
418 $make_path =~ /^(?:.*$pathsep)?(.+)$/;
419 $make_name = $1;
420 }
421
422 # prepend pwd if this is a relative path (ie, does not
423 # start with a slash, but contains one). Thanks for the
424 # clue, Roland.
425
426 if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
427 {
428 $mkpath = "$pwd$pathsep$make_path";
429 }
430 else
431 {
432 $mkpath = $make_path;
433 }
434
435 # If srcdir wasn't provided on the command line, see if the
436 # location of the make program gives us a clue. Don't fail if not;
437 # we'll assume it's been installed into /usr/include or wherever.
438 if (! $srcdir) {
439 $make_path =~ /^(.*$pathsep)?/;
440 my $d = $1 || '../';
441 -f "${d}gnumake.h" and $srcdir = $d;
442 }
443
444 # Not with the make program, so see if we can get it out of the makefile
445 if (! $srcdir && open(MF, "< ../Makefile")) {
446 local $/ = undef;
447 $_ = <MF>;
448 close(MF);
449 /^abs_srcdir\s*=\s*(.*?)\s*$/m;
450 -f "$1/gnumake.h" and $srcdir = $1;
451 }
452
453 # Get Purify log info--if any.
454
455 if (exists $ENV{PURIFYOPTIONS}
456 && $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/) {
457 $pure_log = $1 || '';
458 $pure_log =~ s/%v/$make_name/;
459 $purify_errors = 0;
460 }
461
462 $string = `sh -c "$make_path -j 2 -f /dev/null $redir"`;
463 if ($string =~ /not supported/) {
464 $parallel_jobs = 0;
465 }
466 else {
467 $parallel_jobs = 1;
468 }
469
470 %FEATURES = map { $_ => 1 } split /\s+/, `sh -c "echo '\\\$(info \\\$(.FEATURES))' | $make_path -f- 2>/dev/null"`;
471
472 # Set up for valgrind, if requested.
473
474 $make_command = $make_path;
475
476 if ($valgrind) {
477 my $args = $valgrind_args;
478 open(VALGRIND, "> valgrind.out")
479 || die "Cannot open valgrind.out: $!\n";
480 # -q --leak-check=yes
481 exists $ENV{VALGRIND_ARGS} and $args = $ENV{VALGRIND_ARGS};
482 $make_path = "valgrind --log-fd=".fileno(VALGRIND)." $args $make_path";
483 # F_SETFD is 2
484 fcntl(VALGRIND, 2, 0) or die "fcntl(setfd) failed: $!\n";
485 system("echo Starting on `date` 1>&".fileno(VALGRIND));
486 print "Enabled valgrind support.\n";
487 }
488}
489
490sub setup_for_test
491{
492 $makefile = &get_tmpfile;
493 if (-f $makefile) {
494 unlink $makefile;
495 }
496
497 # Get rid of any Purify logs.
498 if ($pure_log) {
499 ($pure_testname = $testname) =~ tr,/,_,;
500 $pure_testname = "$pure_log.$pure_testname";
501 system("rm -f $pure_testname*");
502 print("Purify testfiles are: $pure_testname*\n") if $debug;
503 }
504}
505
506exit !&toplevel;
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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