Debian Codegraph @

tests/scripts/features/temp_stdin

raw
1 # -*-mode: perl-*-
2
3 $description = "Test handling of temporary file created from stdin.";
4
5 # These tests rely on the test_driver checking for leftover temporary content
6
7 create_file('input.mk', "world:=1\n");
8 create_file('bye.mk', "moon:=2\n");
9
10 # sv 62118,62145.
11 # Test that makes leaves no temp file when make code is piped to stdin and -v,
12 # -h or an invalid option is specified.
13 my @opts = ('-v', '-h', '--nosuchopt');
14 my @exit_codes = (0, 0, 512);
15 for my $i (0 .. $#opts) {
16 close(STDIN);
17 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
18 run_make_test(q!
19 all:; $(info hello world)
20 !,
21 "$opts[$i] -f-", "/uilt for /", $exit_codes[$i]);
22 }
23
24 # sv 62118,62145.
25 # Test that a stdin temp file is removed.
26 close(STDIN);
27 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
28 run_make_test(q!
29 all:; $(info world=$(world))
30 !,
31 '-f-', "world=1\n#MAKE#: 'all' is up to date.\n");
32
33 # sv 62118,62145.
34 # Test that a stdin temp file is removed, even when make re-execs.
35 # Also test that make honors TMPDIR to create the temp file.
36 # Ensure touching bye.mk causes re-exec.
37 &utouch(-600, 'bye.mk');
38 close(STDIN);
39 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
40 run_make_test(q!
41 include bye.mk
42 all:; $(info hello)
43 $(MAKE_RESTARTS)bye.mk: force; touch $@
44 force:
45 !,
46 '-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$temppath\E/");
47
48 if ($port_type eq 'UNIX') {
49 # POSIX doesn't require sh to set PPID so test this
50 my $cmd = create_command();
51 add_options($cmd, '-f', '/dev/null', '-E', q!all:;@echo $$PPID!);
52 my $fout = 'ppidtest.out';
53 run_command_with_output($fout, @$cmd);
54 $_ = read_file_into_string($fout);
55 s/\r?\n//g;
56 if (/^[0-9]+$/) {
57 use POSIX ();
58
59 # sv 63157.
60 # Test that make removes the temporary file which holds make code from stdin,
61 # even when a signal is received. include bye.mk and bye.mk: rule is needed
62 # to cause make to keep the temporary file for re-exec. Without re-exec make
63 # will remove the file before the signal arrives. sleep is needed to let make
64 # write its "... Terminated" message to the log file. Must use REGEX because
65 # some systems (MacOS) add extra text after Terminated.
66 &utouch(-600, 'bye.mk');
67 close(STDIN);
68 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
69
70 run_make_test(q!
71 include bye.mk
72 pid := $(shell echo $$PPID)
73 all:;
74 bye.mk: force; @#HELPER# -q term $(pid) sleep 10
75 force:
76 !,
77 '-f-', '/#MAKE#: \*\*\* \[#MAKEFILE#:5: bye.mk] Terminated/', POSIX::SIGTERM);
78 }
79 unlink($fout);
80
81 # sv 62118,62145.
82 # Test that a stdin temp file is removed, when execvp fails to re-exec make.
83 # In order to cause execvp to fail, copy the tested make binary to the temp
84 # directory and take away the 'x' bit.
85 use File::Spec;
86 use File::Copy;
87
88 my $tmakedir = File::Spec->catfile($cwdpath, 'tmakedir');
89 mkdir($tmakedir, 0770);
90 my $makecopy = File::Spec->catfile($tmakedir, 'make');
91 copy("$mkpath", $makecopy);
92 # Set file mode bits, because perl copy won't.
93 chmod 0700, $makecopy;
94
95 my @make_orig = @make_command;
96 @make_command = ($makecopy);
97
98 # Ensure touching bye.mk causes re-exec.
99 &utouch(-600, 'bye.mk');
100 close(STDIN);
101 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
102 run_make_test("
103 include bye.mk
104 all:; \$(info hello)
105 \$(MAKE_RESTARTS)bye.mk: force; touch \$@ && chmod u-x $makecopy
106 force:
107 ",
108 "-f-", "touch bye.mk && chmod u-x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512);
109
110 @make_command = @make_orig;
111 unlink($makecopy);
112 rmdir($tmakedir);
113
114 # SV 63333. Test that make exits with an error message if we cannot store a
115 # makefile from stdin to a temporary file.
116 # Create a non-writable temporary directory.
117
118 my $tdir = 'test_tmp_dir';
119 mkdir($tdir, 0500);
120 $ENV{'TMPDIR'} = $tdir;
121 close(STDIN);
122 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
123
124 run_make_test(q!
125 all:; $(info hello, world)
126 !, '-f-', '/cannot store makefile from stdin to a temporary file. Stop./', 512);
127 rmdir($tdir);
128 }
129
130 # This close MUST come at the end of the test!!
131 close(STDIN);
132 unlink('input.mk', 'bye.mk');
133
134 # This tells the test driver that the perl test script executed properly.
135 1;