$valgrind = 0; $valgrind_args = '--num-callers=15 --tool=memcheck --leak-check=full';
$pure_log = undef;
require "test_driver.pl";
$has_POSIX = eval { require "POSIX.pm" };
sub valid_option
{
local($option) = @_;
if ($option =~ /^-make([-_]?path)?$/)
{
$make_path = shift @argv;
if (!-f $make_path)
{
print "$option $make_path: Not found.\n";
exit 0;
}
return 1;
}
if ($option =~ /^-valgrind$/i) {
$valgrind = 1;
return 1;
}
return 0;
}
$old_makefile = undef;
sub run_make_test
{
local ($makestring, $options, $answer, $err_code) = @_;
if (! defined $makestring) {
defined $old_makefile
|| die "run_make_test(undef) invoked before run_make_test('...')\n";
$makefile = $old_makefile;
} else {
if (! defined($makefile)) {
$makefile = &get_tmpfile();
}
$makestring && $makestring !~ /\n$/s and $makestring .= "\n";
$makestring =~ s/ $makestring =~ s/ $makestring =~ s/ $makestring =~ s/
open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
print MAKEFILE $makestring;
close(MAKEFILE) || die "Failed to write $makefile: $!\n";
}
$answer && $answer !~ /\n$/s and $answer .= "\n";
$answer =~ s/ $answer =~ s/ $answer =~ s/ $answer =~ s/
&run_make_with_options($makefile, $options, &get_logfile(0), $err_code);
&compare_output($answer, &get_logfile(1));
$old_makefile = $makefile;
$makefile = undef;
}
sub run_make_with_options {
local ($filename,$options,$logname,$expected_code) = @_;
local($code);
local($command) = $make_path;
$expected_code = 0 unless defined($expected_code);
$test_passed = 1;
if ($filename) {
$command .= " -f $filename";
}
if ($options) {
$command .= " $options";
}
if ($valgrind) {
print VALGRIND "\n\nExecuting: $command\n";
}
$code = &run_command_with_output($logname,$command);
if ($pure_log && -f $pure_log) {
if ($code & 0x7000) {
$code &= ~0x7000;
$tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
print("Renaming purify log file to $tn\n") if $debug;
rename($pure_log, "$tn")
|| die "Can't rename $log to $tn: $!\n";
++$purify_errors;
} else {
unlink($pure_log);
}
}
if ($code != $expected_code) {
print "Error running $make_path (expected $expected_code; got $code): $command\n";
$test_passed = 0;
if ($code & 127) {
print STDERR "\nCaught signal ".($code & 127)."!\n";
exit($code);
}
return 0;
}
if ($profile & $vos) {
system "add_profile $make_path";
}
1;
}
sub print_usage
{
&print_standard_usage ("run_make_tests", "[-make_path make_pathname]");
}
sub print_help
{
&print_standard_help ("-make_path",
"\tYou may specify the pathname of the copy of make to run.");
}
sub get_this_pwd {
$delete_command = 'rm -f';
if ($has_POSIX) {
$__pwd = POSIX::getcwd();
} elsif ($vos) {
$delete_command = "delete_file -no_ask";
$__pwd = `++(current_dir)`;
} else {
chop ($__pwd = `pwd`);
}
return $__pwd;
}
sub set_defaults
{
$testee = "GNU make";
$make_path = "make";
$tmpfilesuffix = "mk";
$pwd = &get_this_pwd;
}
sub set_more_defaults
{
local($string);
local($index);
$ENV{LANG} = 'C';
if ($osname =~ /Windows/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) {
$port_type = 'W32';
}
elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) {
$port_type = 'DOS';
}
elsif ($osname =~ m%OS/2%) {
$port_type = 'OS/2';
}
else {
$port_type = 'UNIX';
}
$wtime = $port_type eq 'UNIX' ? 1 : $port_type eq 'OS/2' ? 2 : 4;
print "Port type: $port_type\n" if $debug;
print "Make path: $make_path\n" if $debug;
my $mk = `sh -c 'echo "all:;\@echo \\\$(MAKE)" | $make_path -f-'`;
chop $mk;
$mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE):\n
'echo \"all:;\@echo \\\$(MAKE)\" | $make_path -f-' failed!\n";
$make_path = $mk;
print "Make\t= `$make_path'\n" if $debug;
$string = `$make_path -v -f /dev/null 2> /dev/null`;
$string =~ /^(GNU Make [^,\n]*)/;
$testee_version = "$1\n";
$string = `sh -c "$make_path -f /dev/null 2>&1"`;
if ($string =~ /(.*): \*\*\* No targets\. Stop\./) {
$make_name = $1;
}
else {
if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
$make_name = $1;
}
else {
$make_name = $make_path;
}
}
if (index ($make_path, ":") != 1 && index ($make_path, "/") > 0)
{
$mkpath = "$pwd$pathsep$make_path";
}
else
{
$mkpath = $make_path;
}
if (exists $ENV{PURIFYOPTIONS}
&& $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/) {
$pure_log = $1 || '';
$pure_log =~ s/%v/$make_name/;
$purify_errors = 0;
}
$string = `sh -c "$make_path -j 2 -f /dev/null 2>&1"`;
if ($string =~ /not supported/) {
$parallel_jobs = 0;
}
else {
$parallel_jobs = 1;
}
if ($valgrind) {
open(VALGRIND, "> valgrind.out")
|| die "Cannot open valgrind.out: $!\n";
exists $ENV{VALGRIND_ARGS} and $valgrind_args = $ENV{VALGRIND_ARGS};
$make_path = "valgrind --log-fd=".fileno(VALGRIND)." $valgrind_args $make_path";
fcntl(VALGRIND, 2, 0) or die "fcntl(setfd) failed: $!\n";
system("echo Starting on `date` 1>&".fileno(VALGRIND));
print "Enabled valgrind support.\n";
}
}
sub setup_for_test
{
$makefile = &get_tmpfile;
if (-f $makefile) {
unlink $makefile;
}
if ($pure_log) {
($pure_testname = $testname) =~ tr,/,_,;
$pure_testname = "$pure_log.$pure_testname";
system("rm -f $pure_testname*");
print("Purify testfiles are: $pure_testname*\n") if $debug;
}
}
exit !&toplevel;