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 descriptor '-1'" -eread=-1
71 check_e "invalid descriptor '-42'" -ewrite=-42
72 check_e "invalid descriptor '2147483648'" -eread=2147483648
73 check_e "invalid descriptor '4294967296'" -ewrite=4294967296
74 check_e "invalid descriptor 'foo'" -eread=foo
75 check_e "invalid descriptor ''" -ewrite=
76 check_e "invalid descriptor ','" -eread=,
77 check_e "invalid descriptor '!'" -ewrite='!'
78 check_e "invalid descriptor '!'" -eread='0,!'
79 check_e "invalid descriptor '!,'" -ewrite='!,'
81 check_h 'must have PROG [ARGS] or -p PID'
82 check_h 'PROG [ARGS] must be specified with -D' -D -p $$
83 check_h '-c and -C are mutually exclusive' -c -C true
84 check_h '-c and -C are mutually exclusive' -C -c true
85 check_h '(-c or -C) and -ff are mutually exclusive' -c -ff true
86 check_h '(-c or -C) and -ff are mutually exclusive' -C -ff true
87 check_h '-w must be given with (-c or -C)' -w true
88 check_h 'piping the output and -ff are mutually exclusive' -o '|' -ff true
89 check_h 'piping the output and -ff are mutually exclusive' -o '!' -ff true
90 check_h "invalid -a argument: '-42'" -a -42
91 check_h "invalid -O argument: '-42'" -O -42
92 check_h "invalid -s argument: '-42'" -s -42
93 check_h "invalid -I argument: '5'" -I 5
95 if [ -n "${UID-}" ]; then
96 if [ "${UID-}" = 0 ]; then
97 umsg="Cannot find user ':nosuchuser:'"
99 umsg='You must be root to use the -u option'
102 check_e "$umsg" -u :nosuchuser: true
104 for c in i r t T y; do
105 check_e "-$c has no effect with -c
106 $strace_exp: $umsg" -u :nosuchuser: -c -$c true
108 check_e "-i has no effect with -c
109 $strace_exp: -r has no effect with -c
110 $strace_exp: -t has no effect with -c
111 $strace_exp: -T has no effect with -c
112 $strace_exp: -y has no effect with -c
113 $strace_exp: $umsg" -u :nosuchuser: -cirtTy true
115 check_e "-tt has no effect with -r
116 $strace_exp: $umsg" -u :nosuchuser: -r -tt true
120 $STRACE $args 2> "$LOG" &&
121 dump_log_and_fail_with \
122 "strace $args failed to handle the error properly"
124 for cmd in PTRACE_SEIZE PTRACE_ATTACH; do
125 cat > "$EXP" << __EOF__
126 $strace_exp: attach: ptrace($cmd, 2147483647): No such process
128 diff -- "$EXP" "$LOG" ||
135 dump_log_and_fail_with \
136 "strace $args failed to print expected diagnostics"