]> granicus.if.org Git - strace/blobdiff - tests/options-syntax.test
tests: extend TEST_NETLINK_OBJECT macro
[strace] / tests / options-syntax.test
index 456631148da2ce1c461023f9445ec7b42c8398d0..7cfc579b5defa42c2eb8c836e82eaddd9c8ff186 100755 (executable)
@@ -3,6 +3,7 @@
 # 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
@@ -39,6 +40,16 @@ check_exit_status_and_stderr()
                        "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()
@@ -50,6 +61,15 @@ __EOF__
        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
@@ -67,6 +87,34 @@ check_e "Invalid process id: 'a'" -p 1,a
 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
@@ -79,8 +127,20 @@ check_h 'piping the output and -ff are mutually exclusive' -o '!' -ff 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:'"
@@ -123,5 +183,3 @@ done
 [ -z "$args" ] ||
        dump_log_and_fail_with \
                "strace $args failed to print expected diagnostics"
-
-rm -f "$EXP"