]> granicus.if.org Git - strace/blob - tests/detach-sleeping.test
Update copyright headers
[strace] / tests / detach-sleeping.test
1 #!/bin/sh
2 #
3 # Ensure that strace can detach from sleeping processes.
4 #
5 # Copyright (c) 2013-2015 Dmitry V. Levin <ldv@altlinux.org>
6 # Copyright (c) 2014-2018 The strace developers.
7 # All rights reserved.
8 #
9 # SPDX-License-Identifier: GPL-2.0-or-later
10
11 . "${srcdir=.}/init.sh"
12
13 run_prog_skip_if_failed \
14         kill -0 $$
15
16 check_prog sleep
17
18 trap - TERM
19 sleep $TIMEOUT_DURATION &
20 kill -TERM $!
21 wait $!
22 expected_rc=$?
23
24 set -e
25
26 ../set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" &
27
28 while ! [ -s "$LOG" ]; do
29         kill -0 $! 2> /dev/null ||
30                 fail_ 'set_ptracer_any sleep failed'
31         $SLEEP_A_BIT
32 done
33
34 tracee_pid=$!
35
36 cleanup()
37 {
38         set +e
39         kill $tracee_pid
40         wait $tracee_pid 2> /dev/null
41         return 0
42 }
43
44 $STRACE -p $tracee_pid 2> "$LOG" &
45
46 while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do
47         kill -0 $! 2> /dev/null || {
48                 cleanup
49                 dump_log_and_fail_with "$STRACE -p failed to attach"
50         }
51         $SLEEP_A_BIT
52 done
53
54 kill -TERM $!
55 wait $! && rc=0 || rc=$?
56
57 grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
58         cleanup
59         dump_log_and_fail_with "$STRACE -p failed to detach"
60 }
61
62 [ "$rc" = "$expected_rc" ] || {
63         cleanup
64         dump_log_and_fail_with "$STRACE -p failed to terminate itself"
65 }
66
67 if [ -f /proc/self/status ]; then
68         $SLEEP_A_BIT
69         test -d /proc/$tracee_pid || {
70                 cleanup
71                 dump_log_and_fail_with 'tracee died after detach'
72         }
73         grep_pid_status "$tracee_pid" '^State:.*S (sleeping)' > /dev/null || {
74                 grep_pid_status "$tracee_pid" '^State:'
75                 cleanup
76                 dump_log_and_fail_with 'tracee is not sleeping after detach'
77         }
78 fi
79
80 cleanup
81 exit 0