make/tests/scripts/features/exec
Paul Smith 9db74434cd Clean up memory leak warnings from ASAN and Valgrind
* src/main.c (main): Add "sanitize" to .FEATURES if ASAN is enabled.
* src/expand.c (expand_variable_output): Remember "recursive" setting
in case it's changed by the expansion of the variable.
* src/file.c (rehash_file): If we drop a file from the global 'files'
hash, remember it in rehashed_files.  We can't free it because it's
still being referenced (callers will invoke check_renamed()) but
it will be a leak since it's no longer referenced by 'files'.
* src/remake.c (update_file_1): If we drop a dependency, remember it
in dropped_list.  We can't free it because it's still being referenced
by callers but it will be a leak since it's no longer referenced as
a prerequisite.
* tests/scripts/functions/guile: Don't run Guile tests when ASAN is
enabled.
* tests/scripts/functions/wildcard: Enabling ASAN causes glob(3) to
break!  Don't run this test.
* tests/scripts/features/exec: Valgrind's exec() doesn't support
scripts with no shbang.
* tests/scripts/jobserver: Valgrind fails if TMPDIR is set to an
invalid directory: skip those tests.
* tests/scripts/features/output-sync: Ditto.
* tests/scripts/features/temp_stdin: Ditto.
2023-04-01 11:13:12 -04:00

76 lines
2.2 KiB
Perl

# -*-perl-*-
use warnings;
my $description = "Test that make can execute binaries as well as scripts with"
." various shabangs and without a shbang";
my $details = "The various shells that this test uses are the default"
." /bin/sh, \$SHELL and the perl interpreter that is"
." executing this test program. The shells are used for the value"
." of SHELL inside the test makefile and also as a shbang in the"
." executed script. There is also a test which executes a script"
." that has no shbang.";
# Only bother with this on UNIX systems
$port_type eq 'UNIX' or return -1;
$^O =~ /cygwin/ and return -1;
my @shbangs = ('#!/bin/sh', "#!$perl_name");
# The exec in Valgrind's VM doesn't allow starting commands without any shbang
$valgrind or push @shbangs, '';
my @shells = ('', 'SHELL=/bin/sh');
# Try whatever shell the user has, as long as it's not a C shell.
# The C shell is not usable with make, due to not correctly handling
# file descriptors and possibly other issues.
my $usersh = $origENV{SHELL};
if ($usersh !~ /csh/) {
push @shbangs, ("#!$usersh");
push @shells, ("SHELL=$usersh");
}
my $answer = 'hello, world';
# tests [0-11]
# Have a makefile with various SHELL= exec a shell program with varios
# shbangs or without a shbang at all.
my $stem = './exec.cmd';
my $k = 0;
for my $shbang (@shbangs) {
for my $shell (@shells) {
my $cmd = $k ? "$stem.$k" : $stem;
++$k;
unlink $cmd;
open(CMD,"> $cmd");
print CMD "$shbang\n";
print CMD "printf \"$answer\\n\";\n";
close(CMD);
chmod 0700, $cmd;
run_make_test("# shbang=$shbang\n# shell=$shell" . q!
all:; @$(CMD)
!, "$shell CMD=$cmd", "$answer\n");
rmfiles($cmd);
}
}
# tests [12-14]
# Exec a binary from a makefile that has SHELL=.
for my $shell (@shells) {
run_make_test(q!
all:; @#PERL# -e 'printf "$(ANSWER)\n"';
!, "$shell ANSWER='$answer'", "$answer\n");
}
# test 15
# Use perl as a shell.
run_make_test(q!
SHELL = #PERL#
.SHELLFLAGS = -e
all:; @printf "$(ANSWER)\n";
!, "ANSWER='$answer'", "$answer\n");
1;