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 check_exit_status_and_stderr_using_grep()
44 $STRACE "$@" 2> "$LOG" &&
45 dump_log_and_fail_with \
46 "strace $* failed to handle the error properly"
47 match_grep "$LOG" "$EXP" ||
48 dump_log_and_fail_with \
49 "strace $* failed to print expected diagnostics"
52 strace_exp="${STRACE##* }"
56 local pattern="$1"; shift
57 cat > "$EXP" << __EOF__
60 check_exit_status_and_stderr "$@"
65 local pattern="$1"; shift
66 cat > "$EXP" << __EOF__
69 check_exit_status_and_stderr_using_grep "$@"
74 local pattern="$1"; shift
75 cat > "$EXP" << __EOF__
77 Try '$strace_exp -h' for more information.
79 check_exit_status_and_stderr "$@"
82 check_e "Invalid process id: '0'" -p 0
83 check_e "Invalid process id: '-42'" -p -42
84 check_e "Invalid process id: '$$.'" -p $$.
85 check_e "Invalid process id: 'a'" -p 1,a
86 check_e "Syscall 'chdir' for -b isn't supported" -b chdir
87 check_e "Syscall 'chdir' for -b isn't supported" -b execve -b chdir
89 check_e "invalid system call '-1'" -e-1
90 check_e "invalid system call '-2'" -e -2
91 check_e "invalid system call '-3'" -etrace=-3
92 check_e "invalid system call '-4'" -e trace=-4
93 check_e "invalid system call '-5'" -e trace=1,-5
94 check_e "invalid system call '/non_syscall'" -e trace=/non_syscall
95 check_e "invalid system call '2147483647'" -e 2147483647
96 check_e "invalid system call '2147483648'" -e 2147483648
97 check_e "invalid system call '4294967295'" -e 4294967295
98 check_e "invalid system call '4294967296'" -e 4294967296
100 check_e "invalid descriptor '-1'" -eread=-1
101 check_e "invalid descriptor '-42'" -ewrite=-42
102 check_e "invalid descriptor '2147483648'" -eread=2147483648
103 check_e "invalid descriptor '4294967296'" -ewrite=4294967296
104 check_e "invalid descriptor 'foo'" -eread=foo
105 check_e "invalid descriptor ''" -ewrite=
106 check_e "invalid descriptor ','" -eread=,
107 check_e "invalid descriptor '!'" -ewrite='!'
108 check_e "invalid descriptor '!'" -eread='0,!'
109 check_e "invalid descriptor '!,'" -ewrite='!,'
111 check_e_using_grep 'regcomp: \+id: [[:alpha:]].+' -e trace='/+id'
112 check_e_using_grep 'regcomp: \*id: [[:alpha:]].+' -e trace='/*id'
113 check_e_using_grep 'regcomp: \{id: [[:alpha:]].+' -e trace='/{id'
114 check_e_using_grep 'regcomp: \(id: [[:alpha:]].+' -e trace='/(id'
115 check_e_using_grep 'regcomp: \[id: [[:alpha:]].+' -e trace='/[id'
117 check_h 'must have PROG [ARGS] or -p PID'
118 check_h 'PROG [ARGS] must be specified with -D' -D -p $$
119 check_h '-c and -C are mutually exclusive' -c -C true
120 check_h '-c and -C are mutually exclusive' -C -c true
121 check_h '(-c or -C) and -ff are mutually exclusive' -c -ff true
122 check_h '(-c or -C) and -ff are mutually exclusive' -C -ff true
123 check_h '-w must be given with (-c or -C)' -w true
124 check_h 'piping the output and -ff are mutually exclusive' -o '|' -ff true
125 check_h 'piping the output and -ff are mutually exclusive' -o '!' -ff true
126 check_h "invalid -a argument: '-42'" -a -42
127 check_h "invalid -O argument: '-42'" -O -42
128 check_h "invalid -s argument: '-42'" -s -42
129 check_h "invalid -I argument: '5'" -I 5
131 if [ -n "${UID-}" ]; then
132 if [ "${UID-}" = 0 ]; then
133 umsg="Cannot find user ':nosuchuser:'"
135 umsg='You must be root to use the -u option'
138 check_e "$umsg" -u :nosuchuser: true
140 for c in i r t T y; do
141 check_e "-$c has no effect with -c
142 $strace_exp: $umsg" -u :nosuchuser: -c -$c true
144 check_e "-i has no effect with -c
145 $strace_exp: -r has no effect with -c
146 $strace_exp: -t has no effect with -c
147 $strace_exp: -T has no effect with -c
148 $strace_exp: -y has no effect with -c
149 $strace_exp: $umsg" -u :nosuchuser: -cirtTy true
151 check_e "-tt has no effect with -r
152 $strace_exp: $umsg" -u :nosuchuser: -r -tt true
156 $STRACE $args 2> "$LOG" &&
157 dump_log_and_fail_with \
158 "strace $args failed to handle the error properly"
160 for cmd in PTRACE_SEIZE PTRACE_ATTACH; do
161 cat > "$EXP" << __EOF__
162 $strace_exp: attach: ptrace($cmd, 2147483647): No such process
164 diff -- "$EXP" "$LOG" ||
171 dump_log_and_fail_with \
172 "strace $args failed to print expected diagnostics"