X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=test%2Ftestlib.sh.in;h=c63d27d13858ae659cf6f8fc7bd66138bb8a2717;hb=4203f7c88d5f17dc10075d371ca97aa6359ba71b;hp=c65bdde8777610f8288fda9551f1710e4dcd497d;hpb=5bccbe14e20d375300b2c195090152ed86a9e437;p=tinc diff --git a/test/testlib.sh.in b/test/testlib.sh.in index c65bdde8..c63d27d1 100644 --- a/test/testlib.sh.in +++ b/test/testlib.sh.in @@ -185,21 +185,11 @@ expect_code() { # Runs its arguments with timeout(1) or gtimeout(1) if either are installed. # Usage: try_limit_time 10 command --with --args if type timeout >/dev/null; then - if is_busybox; then - # busybox does not support --foreground - try_limit_time() { - time=$1 - shift - timeout "$time" "$@" - } - else - # BSD and GNU timeout do not require special handling - try_limit_time() { - time=$1 - shift - timeout --foreground "$time" "$@" - } - fi + try_limit_time() { + time=$1 + shift + timeout "$time" "$@" + } else try_limit_time() { echo >&2 "timeout was not found, running without time limits!" @@ -386,19 +376,26 @@ wait_script() { # group by enabling job control, but this results in weird behavior when # running tests in parallel on some interactive shells # (e.g. when /bin/sh is symlinked to dash). + fifo=$(mktemp) + rm -f "$fifo" + mkfifo "$fifo" + + # This weird thing is required to support old versions of ksh on NetBSD 8.2 and the like. + (tail -n +"$line" -f "$script_log" >"$fifo") & + new_line=$( try_limit_time 60 sh -c " - fifo=\$$.fifo - cleanup() { rm -f \$fifo; } - cleanup && trap cleanup EXIT - - mkfifo \$$.fifo - tail -n '+$line' -f '$script_log' >\$fifo & - grep -n -m '$count' '^$script,' <\$fifo - kill \$! + grep -n -m $count '^$script,' <'$fifo' " | awk -F: 'END { print $1 }' ) + # Try to stop the background tail, ignoring possible failure (some tails + # detect EOF, some don't, so it may have already exited), but do wait on + # it (which is required at least by old ksh). + kill $! || true + wait || true + rm -f "$fifo" + # Remember the next line number for future reference. We'll use it if # wait_script is called again with same $peer and $script. read -r "${line_var?}" <