Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): fix test for interrupted co...



details:   https://anonhg.NetBSD.org/src/rev/0c34d20d8ad9
branches:  trunk
changeset: 937905:0c34d20d8ad9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Aug 28 18:16:22 2020 +0000

description:
make(1): fix test for interrupted command execution

In the first version of this test, I had completely misunderstood the
whole topic.

To test the interrupt, the make process has to be interrupted, not the
shell.  This generates the correct message that the target is removed.

The filename for .PHONY targets is removed even though .PHONY targets
usually don't correspond to a file.  The message is only printed if
there actually is a corresponding file.  That's why this message does
not appear when interrupting "make clean".

Finally, since files get created and removed during a single run of
make, the file cache needs to be disabled.  This is done by prefixing
the filenames with "././", see Dir_FindFile.

diffstat:

 usr.bin/make/unit-tests/cmd-interrupt.exp |  20 +++---------
 usr.bin/make/unit-tests/cmd-interrupt.mk  |  47 ++++++++++++++++++++----------
 2 files changed, 37 insertions(+), 30 deletions(-)

diffs (96 lines):

diff -r 4229fc8f8ffc -r 0c34d20d8ad9 usr.bin/make/unit-tests/cmd-interrupt.exp
--- a/usr.bin/make/unit-tests/cmd-interrupt.exp Fri Aug 28 17:27:21 2020 +0000
+++ b/usr.bin/make/unit-tests/cmd-interrupt.exp Fri Aug 28 18:16:22 2020 +0000
@@ -1,17 +1,9 @@
-make  -r -k  -f cmd-interrupt.mk cmd-interrupt-ordinary || true
 > cmd-interrupt-ordinary
-kill -INT $$
-*** Signal 2 (continuing)
-
-Stop.
-make: stopped in unit-tests
-ok
-make  -r -k  -f cmd-interrupt.mk cmd-interrupt-phony || true
+make: *** cmd-interrupt-ordinary removed
+interrupt-ordinary: ok
 > cmd-interrupt-phony
-kill -INT $$
-*** Signal 2 (continuing)
-
-Stop.
-make: stopped in unit-tests
-ok
+make: *** cmd-interrupt-phony removed
+interrupt-phony: ok
+> cmd-interrupt-precious
+interrupt-precious: ok
 exit status 0
diff -r 4229fc8f8ffc -r 0c34d20d8ad9 usr.bin/make/unit-tests/cmd-interrupt.mk
--- a/usr.bin/make/unit-tests/cmd-interrupt.mk  Fri Aug 28 17:27:21 2020 +0000
+++ b/usr.bin/make/unit-tests/cmd-interrupt.mk  Fri Aug 28 18:16:22 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cmd-interrupt.mk,v 1.1 2020/08/28 15:40:53 rillig Exp $
+# $NetBSD: cmd-interrupt.mk,v 1.2 2020/08/28 18:16:22 rillig Exp $
 #
 # Tests for interrupting a command.
 #
@@ -7,29 +7,44 @@
 # would be newer than all of its sources and would therefore not be
 # tried again in the next run.
 #
-# For .PHONY targets, there is usually no corresponding file and therefore
-# nothing that could be removed.  These .PHONY targets need to ensure for
-# themselves that interrupting them does not leave an inconsistent state
-# behind.
+# This happens for ordinary targets as well as for .PHONY targets, even
+# though the .PHONY targets usually do not correspond to a file.
+#
+# To protect the target from being removed, the target has to be marked with
+# the special source .PRECIOUS.  These targets need to ensure for themselves
+# that interrupting them does not leave an inconsistent state behind.
+#
+# See also:
+#      CompatDeleteTarget
 
-SELF:= ${.PARSEDIR}/${.PARSEFILE}
+all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-after
 
-_!=    rm -f cmd-interrupt-ordinary cmd-interrupt-phony
+clean-before clean-after: .PHONY
+       @rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious
 
-all: interrupt-ordinary interrupt-phony
+interrupt-ordinary: .PHONY
+       @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-ordinary || true
+       # The ././ is necessary to work around the file cache.
+       @echo ${.TARGET}: ${exists(././cmd-interrupt-ordinary) :? error : ok }
 
-interrupt-ordinary:
-       ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-ordinary || true
-       @echo ${exists(cmd-interrupt-ordinary) :? error : ok }
+interrupt-phony: .PHONY
+       @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-phony || true
+       # The ././ is necessary to work around the file cache.
+       @echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? error : ok }
 
-interrupt-phony:
-       ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-phony || true
-       @echo ${exists(cmd-interrupt-phony) :? ok : error }
+interrupt-precious: .PRECIOUS
+       @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-precious || true
+       # The ././ is necessary to work around the file cache.
+       @echo ${.TARGET}: ${exists(././cmd-interrupt-precious) :? ok : error }
 
 cmd-interrupt-ordinary:
        > ${.TARGET}
-       kill -INT $$$$
+       @kill -INT ${.MAKE.PID}
 
 cmd-interrupt-phony: .PHONY
        > ${.TARGET}
-       kill -INT $$$$
+       @kill -INT ${.MAKE.PID}
+
+cmd-interrupt-precious: .PRECIOUS
+       > ${.TARGET}
+       @kill -INT ${.MAKE.PID}



Home | Main Index | Thread Index | Old Index