2022-04-24 03:33:41 +08:00
|
|
|
# -*-mode: perl-*-
|
|
|
|
|
|
|
|
$description = "Test handling of temporary file created from stdin.";
|
|
|
|
|
2022-08-29 11:48:09 +08:00
|
|
|
# These tests rely on the test_driver checking for leftover temporary content
|
2022-04-24 03:33:41 +08: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 11:48:09 +08:00
|
|
|
# Also test that make honors TMPDIR to create the temp file.
|
2022-04-24 03:33:41 +08: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 11:48:09 +08:00
|
|
|
'-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$temppath\E/");
|
2022-04-24 03:33:41 +08:00
|
|
|
|
|
|
|
if ($port_type eq 'UNIX') {
|
2022-10-16 04:34:54 +08: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);
|
2022-12-19 13:24:42 +08:00
|
|
|
s/\r?\n//g;
|
2022-10-16 04:34:54 +08:00
|
|
|
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-22 07:35:09 +08:00
|
|
|
# sleep is needed to let make write its "... Terminated" message to the log
|
|
|
|
# file.
|
2022-10-16 04:34:54 +08: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-07 03:14:28 +08:00
|
|
|
bye.mk: force; @#HELPER# term $(pid) sleep 10
|
2022-10-16 04:34:54 +08:00
|
|
|
force:
|
2022-10-22 07:35:09 +08:00
|
|
|
!, '-f-', '/#MAKE#: \*\*\* \[#MAKEFILE#:5: bye.mk] Terminated/', POSIX::SIGTERM);
|
2022-10-16 04:34:54 +08:00
|
|
|
}
|
|
|
|
unlink($fout);
|
|
|
|
|
2022-04-24 03:33:41 +08: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 11:48:09 +08:00
|
|
|
use File::Spec;
|
2022-04-24 03:33:41 +08:00
|
|
|
use File::Copy;
|
|
|
|
|
2022-10-29 03:21:55 +08:00
|
|
|
my $tmakedir = File::Spec->catfile($cwdpath, 'tmakedir');
|
|
|
|
mkdir($tmakedir, 0770);
|
|
|
|
my $makecopy = File::Spec->catfile($tmakedir, 'make');
|
2022-04-24 03:33:41 +08:00
|
|
|
copy("$mkpath", $makecopy);
|
|
|
|
# Set file mode bits, because perl copy won't.
|
2022-09-11 05:15:23 +08:00
|
|
|
chmod 0700, $makecopy;
|
2022-04-24 03:33:41 +08: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-11 05:15:23 +08:00
|
|
|
\$(MAKE_RESTARTS)bye.mk: force; touch \$@ && chmod u-x $makecopy
|
2022-04-24 03:33:41 +08:00
|
|
|
force:
|
|
|
|
",
|
2022-09-11 05:15:23 +08:00
|
|
|
"-f-", "touch bye.mk && chmod u-x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512);
|
2022-04-24 03:33:41 +08:00
|
|
|
|
|
|
|
@make_command = @make_orig;
|
2022-08-15 03:03:40 +08:00
|
|
|
unlink($makecopy);
|
2022-10-29 03:21:55 +08:00
|
|
|
rmdir($tmakedir);
|
2022-11-14 05:20:33 +08:00
|
|
|
|
|
|
|
# SV 63333. Test that make exits with an error message if we cannot store a
|
|
|
|
# makefile from stdin to a temporary file.
|
|
|
|
# Create a non-writable temporary directory.
|
|
|
|
|
|
|
|
my $tdir = 'test_tmp_dir';
|
|
|
|
mkdir($tdir, 0500);
|
|
|
|
$ENV{'TMPDIR'} = $tdir;
|
|
|
|
close(STDIN);
|
|
|
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
all:; $(info hello, world)
|
|
|
|
!, '-f-', '/cannot store makefile from stdin to a temporary file. Stop./', 512);
|
|
|
|
rmdir($tdir);
|
2022-04-24 03:33:41 +08:00
|
|
|
}
|
|
|
|
|
2022-08-15 03:03:40 +08:00
|
|
|
close(STDIN);
|
2022-04-24 03:33:41 +08:00
|
|
|
unlink('input.mk', 'bye.mk');
|
|
|
|
|
|
|
|
# This tells the test driver that the perl test script executed properly.
|
|
|
|
1;
|