VirtualBox

source: kBuild/trunk/src/gmake/tests/run_make_tests.pl@ 281

Last change on this file since 281 was 281, checked in by bird, 19 years ago

This commit was generated by cvs2svn to compensate for changes in r280,
which included commits to RCS files with non-trunk default branches.

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