From 9cef2d534a9a3696abc40b790b12e7561e5489f4 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 11 Jun 2020 00:19:03 +0200 Subject: [PATCH] shtests: make tests more interruptable with Ctrl+C Sometimes you have to put ^C on rapid repeat to get out of running the tests. This is because each test scripts is launch as a child shell (not a subshell) in the foreground, which thus handle the ^C. It then exits with a status indicating SIGINT, but the shtest script wasn't handling this and just kept going. src/cmd/ksh93/tests/shtests: - For reasons I don't understand yet, interrupting tests with ^C tends to make them exit with status 130 (128+2) instead of what I would expect for ksh93, 258 (256+2). Not a big deal: POSIX specifies that any exit > 128 signifies a signal in any case, and 'kill -l' works even on those values. But the checks need changing to '> 128'. - Check each result for SIGINT, and issue SIGINT to self if found. (cherry picked from commit d0dfb37c6c71ac7b157060249125e0959130927d) --- src/cmd/ksh93/tests/shtests | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/ksh93/tests/shtests b/src/cmd/ksh93/tests/shtests index 4731c9061..bff94ab41 100755 --- a/src/cmd/ksh93/tests/shtests +++ b/src/cmd/ksh93/tests/shtests @@ -346,7 +346,7 @@ do [[ $i == *.sh ]] || i+='.sh' then valxml $valxml (( e += $? )) fi - if (( e > 256 && ++total_e )) + if (( e > 128 && ++total_e )) then E="(killed by SIG$(kill -l "$e"))" elif (( e == 1 && ++total_e )) then E="1 error" @@ -357,6 +357,9 @@ do [[ $i == *.sh ]] || i+='.sh' then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T $E ]" else echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $E ]" fi + case $E in + *INT\)) kill -s INT $$ ;; # if test was ^C'd, don't keep going but pass down SIGINT + esac done fi if (( compile )) @@ -367,7 +370,7 @@ do [[ $i == *.sh ]] || i+='.sh' then if $valgrind $SHELL $trace $c then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 errors ]" else e=$? - if (( e > 256 && ++total_e )) + if (( e > 128 && ++total_e )) then E="(killed by SIG$(kill -l "$e"))" elif (( e == 1 && ++total_e )) then E="1 error" @@ -375,6 +378,9 @@ do [[ $i == *.sh ]] || i+='.sh' (( total_e += e )) fi echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $E ]" + case $E in + *INT\)) kill -s INT $$ ;; # if test was ^C'd, don't keep going but pass down SIGINT + esac fi else e=$? (( ++total_e ))