diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-30 21:16:05 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-31 10:04:27 +0000 |
commit | 7513861d3dbe627d42bdff830f0e4969d7e6080d (patch) | |
tree | 797147f77ba310d1f7cadb832718697ffe1a229f | |
parent | 26f0789372e9776cef4854549bc024f7adf4aae8 (diff) | |
download | strace-7513861d3dbe627d42bdff830f0e4969d7e6080d.tar.gz |
tests: fix race condition in strace-DD.test
Apparently, $SLEEP_A_BIT might be insufficient for the tracer
to complete.
* tests/strace-DD.test: Find out the tracer pid and wait for the tracer
completion before checking its log.
Suggested-by: Eugene Syromyatnikov <evgsyr@gmail.com>
Fixes: v5.4~106 "tests: check -DD and -DDD options"
-rwxr-xr-x | tests/strace-DD.test | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/strace-DD.test b/tests/strace-DD.test index 4c4fde1ea..6819b51f1 100755 --- a/tests/strace-DD.test +++ b/tests/strace-DD.test @@ -12,23 +12,53 @@ [ "$STRACE" = "$STRACE_EXE" ] || skip_ 'Not applicable: $STRACE != $STRACE_EXE' +run_prog_skip_if_failed \ + kill -0 $$ + +status_file=/proc/self/status +get_tracer_pid() +{ + sed '/^TracerPid:[[:space:]]*/!d;s///' "$@" +} +[ "$(get_tracer_pid "$status_file")" -ge 0 ] || + framework_skip_ "$status_file is not available" + check_prog timeout run_prog ../sleep 0 test_D() { - local exp args + local exp args tracee_pid tracer_pid rc exp="$1"; shift - set -- -e signal=none -e trace=nanosleep "$@" ../sleep 2 + set -- -e signal=none -e trace=nanosleep "$@" -- \ + sh -c 'echo $$ > tracee_pid && exec ../sleep 2' args="$*" set -- timeout -s XCPU 1 $STRACE -o "$LOG" "$@" > "$LOG" - "$@" && rc=0 || rc=$? + > tracee_pid + + "$@" & + + while [ ! -s tracee_pid ]; do + kill -0 $! || + break + done + tracee_pid="$(cat tracee_pid)" + + while tracer_pid="$(get_tracer_pid "/proc/$tracee_pid/status")"; do + [ "$tracer_pid" = 0 ] || + break + done + + wait $! && rc=0 || rc=$? [ "$rc" = 124 ] || dump_log_and_fail_with \ "$* failed with unexpected exit code $rc" - $SLEEP_A_BIT + + while kill -0 "$tracer_pid" 2> /dev/null; do + $SLEEP_A_BIT + done match_diff "$LOG" "$exp" } |