From: Eugene Syromyatnikov Date: Wed, 20 Dec 2017 19:11:05 +0000 (+0100) Subject: tests: check (some) debugging output generated during nsyscalls test X-Git-Tag: v4.21~260 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51e1f187f063d024f2c13a994b68fce2f448f08e;p=strace tests: check (some) debugging output generated during nsyscalls test * tests/nsyscalls-d.c: New file. * tests/.gitignore: Add it. * tests/nsyscalls-d.test: New test, variant of nsyscalls.test with debug output check. * tests/nsyscalls-nd.test: Likewise. * tests/nsyscalls.c: Add expected debug output. * tests/Makefile.am (check_PROGRAMS): Add nsyscalls-d. (DECODER_TESTS): Add nsyscalls-d.test and nsyscalls-nd.test. --- diff --git a/tests/.gitignore b/tests/.gitignore index 7838a5b0..20b0c9f2 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -264,6 +264,7 @@ nlattr_tcamsg nlattr_tcmsg nlattr_unix_diag_msg nsyscalls +nsyscalls-d old_mmap oldfstat oldlstat diff --git a/tests/Makefile.am b/tests/Makefile.am index 22a39d75..3def7304 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -117,6 +117,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ netlink_netlink_diag \ netlink_unix_diag \ nsyscalls \ + nsyscalls-d \ pc \ perf_event_open_nonverbose \ perf_event_open_unabbrev \ @@ -221,6 +222,8 @@ DECODER_TESTS = \ net.test \ netlink_sock_diag.test \ nsyscalls.test \ + nsyscalls-d.test \ + nsyscalls-nd.test \ oldselect.test \ personality.test \ pipe.test \ diff --git a/tests/nsyscalls-d.c b/tests/nsyscalls-d.c new file mode 100644 index 00000000..1525dea0 --- /dev/null +++ b/tests/nsyscalls-d.c @@ -0,0 +1,2 @@ +#define DEBUG_PRINT 1 +#include "nsyscalls.c" diff --git a/tests/nsyscalls-d.test b/tests/nsyscalls-d.test new file mode 100755 index 00000000..f94e533f --- /dev/null +++ b/tests/nsyscalls-d.test @@ -0,0 +1,24 @@ +#!/bin/sh + +# Check decoding of out-of-range syscalls along with debug ouput + +. "${srcdir=.}/init.sh" + +: ${debug_flag=-d} +NAME=nsyscalls-d + +if [ "$MIPS_ABI" = "o32" ]; then + syscall=syscall +else + syscall=none +fi + +run_strace $debug_flag -e trace=$syscall ../$NAME "$STRACE_EXE" 9 \ + 2> "$LOG-err-all" > "$EXP" 9> "$EXP-err" + +[ -n "$debug_flag" ] || > "$EXP-err" + +grep "invalid syscall" "$LOG-err-all" > "$LOG-err" + +match_diff "$EXP" "$LOG" +match_diff "$EXP-err" "$LOG-err" diff --git a/tests/nsyscalls-nd.test b/tests/nsyscalls-nd.test new file mode 100755 index 00000000..7d2f1e1f --- /dev/null +++ b/tests/nsyscalls-nd.test @@ -0,0 +1,4 @@ +#!/bin/sh + +debug_flag= +. "${srcdir=.}"/nsyscalls-d.test diff --git a/tests/nsyscalls.c b/tests/nsyscalls.c index 29f444a2..9d82a645 100644 --- a/tests/nsyscalls.c +++ b/tests/nsyscalls.c @@ -32,6 +32,7 @@ #include "sysent.h" #include #include +#include #include #include @@ -43,6 +44,10 @@ static const struct_sysent syscallent[] = { #include "sysent_shorthand_undefs.h" +#ifndef DEBUG_PRINT +# define DEBUG_PRINT 0 +#endif + #if defined __X32_SYSCALL_BIT && defined __NR_read \ && (__X32_SYSCALL_BIT & __NR_read) != 0 # define SYSCALL_BIT __X32_SYSCALL_BIT @@ -50,6 +55,11 @@ static const struct_sysent syscallent[] = { # define SYSCALL_BIT 0 #endif +#if DEBUG_PRINT +static const char *strace_name; +static FILE *debug_out; +#endif + static void test_syscall(const unsigned long nr) { @@ -64,6 +74,12 @@ test_syscall(const unsigned long nr) long rc = syscall(nr | SYSCALL_BIT, a[0], a[1], a[2], a[3], a[4], a[5]); + +#if DEBUG_PRINT + fprintf(debug_out, "%s: pid %d invalid syscall %ld\n", + strace_name, getpid(), nr); +#endif + #ifdef LINUX_MIPSO32 printf("syscall(%#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx)" " = %ld ENOSYS (%m)\n", nr | SYSCALL_BIT, @@ -82,8 +98,26 @@ test_syscall(const unsigned long nr) } int -main(void) +main(int argc, char *argv[]) { +#if DEBUG_PRINT + if (argc < 3) + error_msg_and_fail("Not enough arguments. " + "Usage: %s STRACE_NAME DEBUG_OUT_FD", + argv[0]); + + strace_name = argv[1]; + + errno = 0; + int debug_out_fd = strtol(argv[2], NULL, 0); + if (errno) + error_msg_and_fail("Not a number: %s", argv[2]); + + debug_out = fdopen(debug_out_fd, "a"); + if (!debug_out) + perror_msg_and_fail("fdopen: %d", debug_out_fd); +#endif + test_syscall(ARRAY_SIZE(syscallent)); #ifdef SYS_socket_subcall