Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / output-sync
index a7534cb..13a54ca 100644 (file)
@@ -11,13 +11,6 @@ exists $FEATURES{'output-sync'} or return -1;
 $parallel_jobs or return -1;
 
 
-if ($vos) {
-  $sleep_command = "sleep -seconds";
-}
-else {
-  $sleep_command = "sleep";
-}
-
 # The following subdirectories with Makefiles are used in several
 # of the following tests.  The model is:
 #   foo/Makefile - has a "foo" target that waits for the bar target
@@ -45,14 +38,16 @@ sub output_sync_clean {
 # reliable.  If things are too fast, then sometimes a different job will steal
 # the output sync lock and the output is mis-ordered from what we expect.
 sub output_sync_wait {
-    return "while [ ! -f ../mksync.$_[0] ]; do :; done; rm -f ../mksync.$_[0].wait; $sleep_command 1";
+    return subst_make_string("#HELPER# -q wait ../mksync.$_[0] sleep 1");
 }
 sub output_sync_set {
-    return "date > ../mksync.$_[0]";
+    return subst_make_string("#HELPER# -q file ../mksync.$_[0]");
 }
 
 @syncfiles = qw(mksync.foo mksync.foo_start mksync.bar mksync.bar_start);
 
+$tmout = 30;
+
 output_sync_clean();
 mkdir('foo', 0777);
 mkdir('bar', 0777);
@@ -121,26 +116,30 @@ EOF
 close(MAKEFILE);
 
 # Test per-make synchronization.
+# Note we have to sleep again here after starting the foo makefile before
+# starting the bar makefile, otherwise the "entering/leaving" messages for the
+# submakes might be ordered differently than we expect.
+
 unlink(@syncfiles);
 run_make_test(qq!
 all: make-foo make-bar
 
 make-foo: ; \$(MAKE) -C foo
 
-make-bar: ; \$(MAKE) -C bar!,
+make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar!,
               '-j -Orecurse',
 "#MAKEPATH# -C foo
 #MAKE#[1]: Entering directory '#PWD#/foo'
 foo: start
 foo: end
 #MAKE#[1]: Leaving directory '#PWD#/foo'
-#MAKEPATH# -C bar
+#HELPER# -q sleep 1 ; #MAKEPATH# -C bar
 #MAKE#[1]: Entering directory '#PWD#/bar'
 bar: start
 bar: end
 baz: start
 baz: end
-#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);
+#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout);
 
 # Test per-target synchronization.
 # Note we have to sleep again here after starting the foo makefile before
@@ -156,10 +155,10 @@ all: make-foo make-bar
 
 make-foo: ; \$(MAKE) -C foo
 
-make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar!,
+make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar!,
               '-j --output-sync=target',
 "#MAKEPATH# -C foo
-$sleep_command 1 ; #MAKEPATH# -C bar
+#HELPER# -q sleep 1 ; #MAKEPATH# -C bar
 #MAKE#[1]: Entering directory '#PWD#/bar'
 bar: start
 bar: end
@@ -171,19 +170,19 @@ foo: end
 #MAKE#[1]: Entering directory '#PWD#/bar'
 baz: start
 baz: end
-#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);
+#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout);
 
 # Rerun but this time suppress the directory tracking
 unlink(@syncfiles);
 run_make_test(undef, '-j --output-sync=target x=',
               "#MAKEPATH# -C foo
-$sleep_command 1 ; #MAKEPATH# -C bar
+#HELPER# -q sleep 1 ; #MAKEPATH# -C bar
 bar: start
 bar: end
 foo: start
 foo: end
 baz: start
-baz: end\n", 0, 6);
+baz: end\n", 0, $tmout);
 
 # Test that messages from make itself are enclosed with
 # "Entering/Leaving directory" messages.
@@ -193,10 +192,10 @@ all: make-foo-fail make-bar-bar
 
 make-foo-fail: ; \$(MAKE) -C foo foo-fail
 
-make-bar-bar: ; $sleep_command 1 ; \$(MAKE) -C bar bar!,
+make-bar-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar bar!,
               '-j -O',
 "#MAKEPATH# -C foo foo-fail
-$sleep_command 1 ; #MAKEPATH# -C bar bar
+#HELPER# -q sleep 1 ; #MAKEPATH# -C bar bar
 #MAKE#[1]: Entering directory '#PWD#/bar'
 bar: start
 bar: end
@@ -204,11 +203,9 @@ bar: end
 #MAKE#[1]: Entering directory '#PWD#/foo'
 foo-fail: start
 foo-fail: end
-Makefile:20: recipe for target 'foo-fail' failed
-#MAKE#[1]: *** [foo-fail] Error 1
+#MAKE#[1]: *** [Makefile:23: foo-fail] Error 1
 #MAKE#[1]: Leaving directory '#PWD#/foo'
-#MAKEFILE#:4: recipe for target 'make-foo-fail' failed
-#MAKE#: *** [make-foo-fail] Error 2\n",
+#MAKE#: *** [#MAKEFILE#:4: make-foo-fail] Error 2\n",
 512);
 
 # Test the per-job synchronization.
@@ -223,10 +220,10 @@ all: make-foo make-bar
 
 make-foo: ; \$(MAKE) -C foo foo-job
 
-make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar bar-job!,
+make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar bar-job!,
               '-j --output-sync=line',
 "#MAKEPATH# -C foo foo-job
-$sleep_command 1 ; #MAKEPATH# -C bar bar-job
+#HELPER# -q sleep 1 ; #MAKEPATH# -C bar bar-job
 #MAKE#[1]: Entering directory '#PWD#/foo'
 foo: start
 #MAKE#[1]: Leaving directory '#PWD#/foo'
@@ -238,8 +235,7 @@ bar: end
 #MAKE#[1]: Leaving directory '#PWD#/bar'
 #MAKE#[1]: Entering directory '#PWD#/foo'
 foo: end
-#MAKE#[1]: Leaving directory '#PWD#/foo'\n", 0, 6);
-
+#MAKE#[1]: Leaving directory '#PWD#/foo'\n", 0, $tmout);
 
 # Remove temporary directories and contents.
 output_sync_clean();
@@ -326,7 +322,7 @@ run_make_test(qq!
 all: t1
 t1: ; -\@\$(MAKE) -f $m1
 !,
-              "-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n$m1:3: *** d1 failed.  Stop.\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKEFILE#:3: recipe for target 't1' failed\n#MAKE#: [t1] Error 2 (ignored)\n");
+              "-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n$m1:3: *** d1 failed.  Stop.\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKE#: [#MAKEFILE#:3: t1] Error 2 (ignored)\n");
 
 rmfiles($m1);
 
@@ -337,5 +333,39 @@ foo: $(OBJS) ; echo $(or $(filter %.o,$^),$(error fail))
 !,
               '-O', "#MAKEFILE#:2: *** fail.  Stop.\n", 512);
 
+# SV 47365: Make sure exec failure error messages are shown
+# Needs to be ported to Windows
+if ($port_type ne 'W32') {
+    run_make_test(q!
+all:: ; @./foo bar baz
+!,
+              '-O', "#MAKE#: ./foo: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:2: all] Error 127\n", 512);
+}
+
+if ($port_type eq 'UNIX') {
+# 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 temporary files, even when a signal is received.
+# The general test_driver postprocessing will ensure the temporary file used
+# to synchronize output and the jobserver fifo are both removed.
+# sleep is needed to let make write its "... Terminated" message to the log
+# file.
+run_make_test(q!
+pid:=$(shell echo $$PPID)
+all:; @kill -TERM $(pid) && sleep 16
+!, '-O -j2', '/#MAKE#: \*\*\* \[#MAKEFILE#:3: all] Terminated/', POSIX::SIGTERM);
+}
+
+unlink($fout);
+}
+
 # This tells the test driver that the perl test script executed properly.
 1;