# Check strace options syntax.
#
# Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+# Copyright (c) 2016-2017 The strace developers.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
"strace $* failed to print expected diagnostics"
}
+check_exit_status_and_stderr_using_grep()
+{
+ $STRACE "$@" 2> "$LOG" &&
+ dump_log_and_fail_with \
+ "strace $* failed to handle the error properly"
+ match_grep "$LOG" "$EXP" ||
+ dump_log_and_fail_with \
+ "strace $* failed to print expected diagnostics"
+}
+
strace_exp="${STRACE##* }"
check_e()
check_exit_status_and_stderr "$@"
}
+check_e_using_grep()
+{
+ local pattern="$1"; shift
+ cat > "$EXP" << __EOF__
+$strace_exp: $pattern
+__EOF__
+ check_exit_status_and_stderr_using_grep "$@"
+}
+
check_h()
{
local pattern="$1"; shift
check_e "Syscall 'chdir' for -b isn't supported" -b chdir
check_e "Syscall 'chdir' for -b isn't supported" -b execve -b chdir
+check_e "invalid system call '-1'" -e-1
+check_e "invalid system call '-2'" -e -2
+check_e "invalid system call '-3'" -etrace=-3
+check_e "invalid system call '-4'" -e trace=-4
+check_e "invalid system call '-5'" -e trace=1,-5
+check_e "invalid system call '/non_syscall'" -e trace=/non_syscall
+check_e "invalid system call '2147483647'" -e 2147483647
+check_e "invalid system call '2147483648'" -e 2147483648
+check_e "invalid system call '4294967295'" -e 4294967295
+check_e "invalid system call '4294967296'" -e 4294967296
+
+check_e "invalid descriptor '-1'" -eread=-1
+check_e "invalid descriptor '-42'" -ewrite=-42
+check_e "invalid descriptor '2147483648'" -eread=2147483648
+check_e "invalid descriptor '4294967296'" -ewrite=4294967296
+check_e "invalid descriptor 'foo'" -eread=foo
+check_e "invalid descriptor ''" -ewrite=
+check_e "invalid descriptor ','" -eread=,
+check_e "invalid descriptor '!'" -ewrite='!'
+check_e "invalid descriptor '!'" -eread='0,!'
+check_e "invalid descriptor '!,'" -ewrite='!,'
+
+check_e_using_grep 'regcomp: \+id: [[:alpha:]].+' -e trace='/+id'
+check_e_using_grep 'regcomp: \*id: [[:alpha:]].+' -e trace='/*id'
+check_e_using_grep 'regcomp: \{id: [[:alpha:]].+' -e trace='/{id'
+check_e_using_grep 'regcomp: \(id: [[:alpha:]].+' -e trace='/(id'
+check_e_using_grep 'regcomp: \[id: [[:alpha:]].+' -e trace='/[id'
+
check_h 'must have PROG [ARGS] or -p PID'
check_h 'PROG [ARGS] must be specified with -D' -D -p $$
check_h '-c and -C are mutually exclusive' -c -C true
check_h "invalid -a argument: '-42'" -a -42
check_h "invalid -O argument: '-42'" -O -42
check_h "invalid -s argument: '-42'" -s -42
+check_h "invalid -s argument: '1073741824'" -s 1073741824
check_h "invalid -I argument: '5'" -I 5
+cat > "$EXP" << '__EOF__'
+strace: must have PROG [ARGS] or -p PID
+Try 'strace -h' for more information.
+__EOF__
+../zeroargc "$strace_exp" /bin/true 2> "$LOG" &&
+ dump_log_and_fail_with \
+ 'zeroargc strace failed to handle the error properly'
+match_diff "$LOG" "$EXP" ||
+ dump_log_and_fail_with \
+ 'zeroargc strace failed to print expected diagnostics'
+
if [ -n "${UID-}" ]; then
if [ "${UID-}" = 0 ]; then
umsg="Cannot find user ':nosuchuser:'"
[ -z "$args" ] ||
dump_log_and_fail_with \
"strace $args failed to print expected diagnostics"
-
-rm -f "$EXP"