]> granicus.if.org Git - strace/commitdiff
tests: robustify redirect.test against race conditions
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 6 Dec 2016 02:55:49 +0000 (02:55 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 6 Dec 2016 13:16:42 +0000 (13:16 +0000)
Introduce a synchronization mechanism between the tracee and its peer.

* tests/redirect.test: Change timeout file to $OUT.  Let the tracee
remove $LOG, wait for $LOG removal in its peer.

tests/redirect.test

index 07fbcdf099e0c4a32ac075d0761cd0f9898289af..fa0c53696c4723292aaf3900eea9098e24d18a3a 100755 (executable)
@@ -35,35 +35,44 @@ run_prog_skip_if_failed \
 check_prog sleep
 check_prog yes
 
+> "$OUT"
 > "$LOG"
-
 (
+       while [ -f "$LOG" ]; do
+               :
+       done
        $SLEEP_A_BIT &
        yes
        if kill -0 $! 2> /dev/null; then
                wait
        else
-               echo TIMEOUT >> $LOG
+               echo TIMEOUT >> "$OUT"
        fi
 ) | $STRACE -qq -enone -esignal=none \
-       sh -c "exec <&- >&-; $SLEEP_A_BIT; $SLEEP_A_BIT"
+       sh -c "exec <&- >&-; rm -f -- $LOG; $SLEEP_A_BIT; $SLEEP_A_BIT"
 
-if [ -s "$LOG" ]; then
+if [ -s "$OUT" ]; then
        fail_ "$STRACE failed to redirect standard input"
 fi
 
+> "$LOG"
 $STRACE -qq -enone -esignal=none \
-       sh -c "exec <&- >&-; $SLEEP_A_BIT; $SLEEP_A_BIT" |
+       sh -c "exec <&- >&-; rm -f -- $LOG; $SLEEP_A_BIT; $SLEEP_A_BIT" |
 (
+       while [ -f "$LOG" ]; do
+               :
+       done
        $SLEEP_A_BIT &
        cat > /dev/null
        if kill -0 $! 2> /dev/null; then
                wait
        else
-               echo TIMEOUT >> $LOG
+               echo TIMEOUT >> "$OUT"
        fi
 )
 
-if [ -s "$LOG" ]; then
+if [ -s "$OUT" ]; then
        fail_ "$STRACE failed to redirect standard output"
 fi
+
+rm -f -- "$OUT"