From 502b10c2ab6bb273bf280ba355fa30869b955d56 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 9 Mar 2019 17:41:49 -0800 Subject: timeout: --foreground, --preserve-status, and --signal. --signal is simply a synonym for the exiting -s. --foreground disables functionality we didn't yet have: putting the child into a new process group. I've added the functionality and the flag to disable it. --preserve-status also makes it clear that our exit statuses didn't match the coreutils version. In addition to callers that use --preserve-status to get away from this madness, I also have callers that check for specific exit values. This patch implements --preserve-status but also fixes all the other exit statuses. (The "125" exit value is broken for toybox in the same way that `toybox grep --whoops ; echo $?` is. To fix this, we'd need some way to signal that command-line parsing failures should exit with a different value than the usual 1 --- 2 for grep, 125 for timeout. I've done as much as grep manages, and left a TODO.) Also add timeout tests. I couldn't think of an easy test for --foreground, so I tested that manually with strace. Also add some newlines to the `toybox --help` output to make it easier to find the different sections, and expand the section on durations to call out that fractions are supported as a matter of policy. As long as timeout and sleep have text describing the duration syntax, make them the same. (Personally I'd remove both in favor of the `toybox --help` output, but as long as they're duplicated, keep them consistent.) Also remove the SLEEP_FLOAT variant --- xparsetime means that sleep no longer requires floating point to support sub-second resolution. --- tests/timeout.test | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/timeout.test (limited to 'tests') diff --git a/tests/timeout.test b/tests/timeout.test new file mode 100644 index 00000000..5ca7cc90 --- /dev/null +++ b/tests/timeout.test @@ -0,0 +1,19 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# timeout's exit value is complicated! +testcmd "times out" '.1 sleep 100 ; echo $?' '124\n' '' '' +testcmd "failure" '-s MONKEY .1 sleep 100 2>/dev/null ; echo $?' '125\n' '' '' +testcmd "can't execute" '.1 / 2>/dev/null ; echo $?' '126\n' '' '' +testcmd "can't find" '.1 /does/not/exist 2>/dev/null ; echo $?' '127\n' '' '' +testcmd "custom signal" '-s 3 .1 sleep 100; echo $?' '124\n' '' '' +testcmd "killed" '-s 9 .1 sleep 100; echo $?' '137\n' '' '' +testcmd "TERM" '-s TERM .1 sleep 100; echo $?' '124\n' '' '' +testcmd "exit 0" '.1 true ; echo $?' '0\n' '' '' +testcmd "exit 1" '.1 false ; echo $?' '1\n' '' '' + +testcmd "--preserve-status" '--preserve-status .1 sleep 100 ; echo $?' '143\n' '' '' +testcmd "--preserve-status killed" '--preserve-status -s 9 .1 sleep 100 ; echo $?' '137\n' '' '' -- cgit v1.2.3