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