3 # Check strace options syntax.
5 # Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 . "${srcdir=.}/init.sh"
32 check_exit_status_and_stderr()
34 $STRACE "$@" 2> "$LOG" &&
35 dump_log_and_fail_with \
36 "strace $* failed to handle the error properly"
37 match_diff "$LOG" "$EXP" ||
38 dump_log_and_fail_with \
39 "strace $* failed to print expected diagnostics"
42 strace_exp="${STRACE##* }"
46 local pattern="$1"; shift
47 cat > "$EXP" << __EOF__
50 check_exit_status_and_stderr "$@"
55 local pattern="$1"; shift
56 cat > "$EXP" << __EOF__
58 Try '$strace_exp -h' for more information.
60 check_exit_status_and_stderr "$@"
63 check_e "Invalid process id: '0'" -p 0
64 check_e "Invalid process id: '-42'" -p -42
65 check_e "Invalid process id: '$$.'" -p $$.
66 check_e "Invalid process id: 'a'" -p 1,a
67 check_e "Syscall 'chdir' for -b isn't supported" -b chdir
68 check_e "Syscall 'chdir' for -b isn't supported" -b execve -b chdir
70 check_e "invalid system call '-1'" -e-1
71 check_e "invalid system call '-2'" -e -2
72 check_e "invalid system call '-3'" -etrace=-3
73 check_e "invalid system call '-4'" -e trace=-4
74 check_e "invalid system call '-5'" -e trace=1,-5
75 check_e "invalid system call '2147483647'" -e 2147483647
76 check_e "invalid system call '2147483648'" -e 2147483648
77 check_e "invalid system call '4294967295'" -e 4294967295
78 check_e "invalid system call '4294967296'" -e 4294967296
80 check_e "invalid descriptor '-1'" -eread=-1
81 check_e "invalid descriptor '-42'" -ewrite=-42
82 check_e "invalid descriptor '2147483648'" -eread=2147483648
83 check_e "invalid descriptor '4294967296'" -ewrite=4294967296
84 check_e "invalid descriptor 'foo'" -eread=foo
85 check_e "invalid descriptor ''" -ewrite=
86 check_e "invalid descriptor ','" -eread=,
87 check_e "invalid descriptor '!'" -ewrite='!'
88 check_e "invalid descriptor '!'" -eread='0,!'
89 check_e "invalid descriptor '!,'" -ewrite='!,'
91 check_h 'must have PROG [ARGS] or -p PID'
92 check_h 'PROG [ARGS] must be specified with -D' -D -p $$
93 check_h '-c and -C are mutually exclusive' -c -C true
94 check_h '-c and -C are mutually exclusive' -C -c true
95 check_h '(-c or -C) and -ff are mutually exclusive' -c -ff true
96 check_h '(-c or -C) and -ff are mutually exclusive' -C -ff true
97 check_h '-w must be given with (-c or -C)' -w true
98 check_h 'piping the output and -ff are mutually exclusive' -o '|' -ff true
99 check_h 'piping the output and -ff are mutually exclusive' -o '!' -ff true
100 check_h "invalid -a argument: '-42'" -a -42
101 check_h "invalid -O argument: '-42'" -O -42
102 check_h "invalid -s argument: '-42'" -s -42
103 check_h "invalid -I argument: '5'" -I 5
105 if [ -n "${UID-}" ]; then
106 if [ "${UID-}" = 0 ]; then
107 umsg="Cannot find user ':nosuchuser:'"
109 umsg='You must be root to use the -u option'
112 check_e "$umsg" -u :nosuchuser: true
114 for c in i r t T y; do
115 check_e "-$c has no effect with -c
116 $strace_exp: $umsg" -u :nosuchuser: -c -$c true
118 check_e "-i has no effect with -c
119 $strace_exp: -r has no effect with -c
120 $strace_exp: -t has no effect with -c
121 $strace_exp: -T has no effect with -c
122 $strace_exp: -y has no effect with -c
123 $strace_exp: $umsg" -u :nosuchuser: -cirtTy true
125 check_e "-tt has no effect with -r
126 $strace_exp: $umsg" -u :nosuchuser: -r -tt true
130 $STRACE $args 2> "$LOG" &&
131 dump_log_and_fail_with \
132 "strace $args failed to handle the error properly"
134 for cmd in PTRACE_SEIZE PTRACE_ATTACH; do
135 cat > "$EXP" << __EOF__
136 $strace_exp: attach: ptrace($cmd, 2147483647): No such process
138 diff -- "$EXP" "$LOG" ||
145 dump_log_and_fail_with \
146 "strace $args failed to print expected diagnostics"