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