]> granicus.if.org Git - strace/blob - tests/detach-stopped.test
tests: rename all tests so that their names end in .test suffix
[strace] / tests / detach-stopped.test
1 #!/bin/sh
2
3 # Ensure that strace can detach from stopped processes.
4
5 . "${srcdir=.}/init.sh"
6
7 check_prog sleep
8 check_prog grep
9
10 set -e
11
12 rm -f $LOG
13 ./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > $LOG &
14
15 while ! [ -s $LOG ]; do
16         kill -0 $! 2> /dev/null ||
17                 fail_ 'set_ptracer_any sleep failed'
18         $SLEEP_A_BIT
19 done
20
21 tracee_pid=$!
22 kill -STOP $tracee_pid
23
24 cleanup()
25 {
26         set +e
27         kill $tracee_pid
28         kill -CONT $tracee_pid
29         wait $tracee_pid 2> /dev/null
30 }
31
32 rm -f $LOG
33 $STRACE -p $tracee_pid 2> $LOG &
34
35 while ! grep -F "Process $tracee_pid attached" $LOG > /dev/null; do
36         kill -0 $! 2> /dev/null ||
37                 { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
38         $SLEEP_A_BIT
39 done
40
41 while ! grep -F -e '--- stopped by ' $LOG > /dev/null; do
42         kill -0 $! 2> /dev/null ||
43                 { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
44         $SLEEP_A_BIT
45 done
46
47 kill -INT $!
48 wait $!
49
50 grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
51         { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
52
53 if [ -f /proc/self/status ]; then
54         $SLEEP_A_BIT
55         test -d /proc/$tracee_pid ||
56                 { cat $LOG; cleanup; fail_ 'tracee died after detach'; }
57         grep '^State:.*T (stopped)' < /proc/$tracee_pid/status > /dev/null || {
58                 cat $LOG
59                 grep '^State:' < /proc/$tracee_pid/status
60                 cleanup
61                 fail_ 'tracee is not group-stopped after detach'
62         }
63 fi
64
65 cleanup
66 exit 0