2022-04-23 19:33:41 +00:00
|
|
|
# -*-mode: perl-*-
|
|
|
|
|
|
|
|
$description = "Test handling of temporary file created from stdin.";
|
|
|
|
|
2022-08-29 03:48:09 +00:00
|
|
|
# These tests rely on the test_driver checking for leftover temporary content
|
2022-04-23 19:33:41 +00:00
|
|
|
|
|
|
|
create_file('input.mk', "world:=1\n");
|
|
|
|
create_file('bye.mk', "moon:=2\n");
|
|
|
|
|
|
|
|
# sv 62118,62145.
|
|
|
|
# Test that makes leaves no temp file when make code is piped to stdin and -v,
|
|
|
|
# -h or an invalid option is specified.
|
|
|
|
my @opts = ('-v', '-h', '--nosuchopt');
|
|
|
|
my @exit_codes = (0, 0, 512);
|
|
|
|
for my $i (0 .. $#opts) {
|
|
|
|
close(STDIN);
|
|
|
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
|
|
|
run_make_test(q!
|
|
|
|
all:; $(info hello world)
|
|
|
|
!,
|
|
|
|
"$opts[$i] -f-", "/uilt for /", $exit_codes[$i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
# sv 62118,62145.
|
|
|
|
# Test that a stdin temp file is removed.
|
|
|
|
close(STDIN);
|
|
|
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
|
|
|
run_make_test(q!
|
|
|
|
all:; $(info world=$(world))
|
|
|
|
!,
|
|
|
|
'-f-', "world=1\n#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
# sv 62118,62145.
|
|
|
|
# Test that a stdin temp file is removed, even when make re-execs.
|
2022-08-29 03:48:09 +00:00
|
|
|
# Also test that make honors TMPDIR to create the temp file.
|
2022-04-23 19:33:41 +00:00
|
|
|
# Ensure touching bye.mk causes re-exec.
|
|
|
|
&utouch(-600, 'bye.mk');
|
|
|
|
close(STDIN);
|
|
|
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
|
|
|
run_make_test(q!
|
|
|
|
include bye.mk
|
|
|
|
all:; $(info hello)
|
|
|
|
$(MAKE_RESTARTS)bye.mk: force; touch $@
|
|
|
|
force:
|
|
|
|
!,
|
2022-08-29 03:48:09 +00:00
|
|
|
'-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$temppath\E/");
|
2022-04-23 19:33:41 +00:00
|
|
|
|
|
|
|
if ($port_type eq 'UNIX') {
|
2022-10-15 20:34:54 +00:00
|
|
|
# POSIX doesn't require sh to set PPID so test this
|
|
|
|
my $cmd = create_command();
|
|
|
|
add_options($cmd, '-f', '/dev/null', '-E', q!all:;@echo $$PPID!);
|
|
|
|
my $fout = 'ppidtest.out';
|
|
|
|
run_command_with_output($fout, @$cmd);
|
|
|
|
$_ = read_file_into_string($fout);
|
|
|
|
chomp($_);
|
|
|
|
if (/^[0-9]+$/) {
|
|
|
|
use POSIX ();
|
|
|
|
|
|
|
|
# sv 63157.
|
|
|
|
# Test that make removes the temporary file which holds make code from stdin,
|
|
|
|
# even when a signal is received.
|
|
|
|
# include bye.mk and bye.mk: rule is needed to cause make to keep the temporary
|
|
|
|
# file for re-exec. Without re-exec make will remove the file before the signal
|
|
|
|
# arrives.
|
2022-10-21 23:35:09 +00:00
|
|
|
# sleep is needed to let make write its "... Terminated" message to the log
|
|
|
|
# file.
|
2022-10-15 20:34:54 +00:00
|
|
|
&utouch(-600, 'bye.mk');
|
|
|
|
close(STDIN);
|
|
|
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
|
|
|
run_make_test(q!
|
|
|
|
include bye.mk
|
|
|
|
pid:=$(shell echo $$PPID)
|
|
|
|
all:;
|
2022-11-06 19:14:28 +00:00
|
|
|
bye.mk: force; @#HELPER# term $(pid) sleep 10
|
2022-10-15 20:34:54 +00:00
|
|
|
force:
|
2022-10-21 23:35:09 +00:00
|
|
|
!, '-f-', '/#MAKE#: \*\*\* \[#MAKEFILE#:5: bye.mk] Terminated/', POSIX::SIGTERM);
|
2022-10-15 20:34:54 +00:00
|
|
|
}
|
|
|
|
unlink($fout);
|
|
|
|
|
2022-04-23 19:33:41 +00:00
|
|
|
# sv 62118,62145.
|
|
|
|
# Test that a stdin temp file is removed, when execvp fails to re-exec make.
|
|
|
|
# In order to cause execvp to fail, copy the tested make binary to the temp
|
|
|
|
# directory and take away the 'x' bit.
|
2022-08-29 03:48:09 +00:00
|
|
|
use File::Spec;
|
2022-04-23 19:33:41 +00:00
|
|
|
use File::Copy;
|
|
|
|
|
2022-10-28 19:21:55 +00:00
|
|
|
my $tmakedir = File::Spec->catfile($cwdpath, 'tmakedir');
|
|
|
|
mkdir($tmakedir, 0770);
|
|
|
|
my $makecopy = File::Spec->catfile($tmakedir, 'make');
|
2022-04-23 19:33:41 +00:00
|
|
|
copy("$mkpath", $makecopy);
|
|
|
|
# Set file mode bits, because perl copy won't.
|
2022-09-10 21:15:23 +00:00
|
|
|
chmod 0700, $makecopy;
|
2022-04-23 19:33:41 +00:00
|
|
|
|
|
|
|
my @make_orig = @make_command;
|
|
|
|
@make_command = ($makecopy);
|
|
|
|
|
|
|
|
# Ensure touching bye.mk causes re-exec.
|
|
|
|
&utouch(-600, 'bye.mk');
|
|
|
|
close(STDIN);
|
|
|
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
|
|
|
run_make_test("
|
|
|
|
include bye.mk
|
|
|
|
all:; \$(info hello)
|
2022-09-10 21:15:23 +00:00
|
|
|
\$(MAKE_RESTARTS)bye.mk: force; touch \$@ && chmod u-x $makecopy
|
2022-04-23 19:33:41 +00:00
|
|
|
force:
|
|
|
|
",
|
2022-09-10 21:15:23 +00:00
|
|
|
"-f-", "touch bye.mk && chmod u-x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512);
|
2022-04-23 19:33:41 +00:00
|
|
|
|
|
|
|
@make_command = @make_orig;
|
2022-08-14 19:03:40 +00:00
|
|
|
unlink($makecopy);
|
2022-10-28 19:21:55 +00:00
|
|
|
rmdir($tmakedir);
|
2022-04-23 19:33:41 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 19:03:40 +00:00
|
|
|
close(STDIN);
|
2022-04-23 19:33:41 +00:00
|
|
|
unlink('input.mk', 'bye.mk');
|
|
|
|
|
|
|
|
# This tells the test driver that the perl test script executed properly.
|
|
|
|
1;
|