Module Name:    src
Committed By:   rillig
Date:           Thu Nov 12 21:54:52 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: opt-debug-jobs.exp opt-debug-jobs.mk

Log Message:
make(1): avoid race condition in test opt-debug-jobs

Thanks sjg for finding this and suggesting the fix.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/opt-debug-jobs.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/opt-debug-jobs.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/unit-tests/opt-debug-jobs.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-jobs.exp:1.6 src/usr.bin/make/unit-tests/opt-debug-jobs.exp:1.7
--- src/usr.bin/make/unit-tests/opt-debug-jobs.exp:1.6	Sun Nov  8 00:54:06 2020
+++ src/usr.bin/make/unit-tests/opt-debug-jobs.exp	Thu Nov 12 21:54:52 2020
@@ -10,6 +10,8 @@ echo ":  variable"
 echo ": 'single' and \"double\" quotes"
 { : 'single' and "double" quotes 
 } || exit $?
+{ sleep 1 
+} || exit $?
 Running all
 	Command: sh 
 JobExec(all): pid <pid> added to jobs table

Index: src/usr.bin/make/unit-tests/opt-debug-jobs.mk
diff -u src/usr.bin/make/unit-tests/opt-debug-jobs.mk:1.4 src/usr.bin/make/unit-tests/opt-debug-jobs.mk:1.5
--- src/usr.bin/make/unit-tests/opt-debug-jobs.mk:1.4	Mon Oct  5 19:27:48 2020
+++ src/usr.bin/make/unit-tests/opt-debug-jobs.mk	Thu Nov 12 21:54:52 2020
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-jobs.mk,v 1.4 2020/10/05 19:27:48 rillig Exp $
+# $NetBSD: opt-debug-jobs.mk,v 1.5 2020/11/12 21:54:52 rillig Exp $
 #
 # Tests for the -dj command line option, which adds debug logging about
 # running jobs in multiple shells.
@@ -24,3 +24,10 @@ all:
 	# This allows to copy and paste the whole command, without having
 	# to unescape anything.
 	: 'single' and "double" quotes
+
+	# Avoid a race condition in the debug output.  Without sleeping,
+	# it is not guaranteed that the two lines "exited/stopped" and
+	# "JobFinish" are output earlier than the stdout of the actual shell
+	# commands.  The '@' prefix avoids that this final command gets into
+	# another race condition with the "exited/stopped" line.
+	@sleep 1

Reply via email to