]> granicus.if.org Git - strace/commitdiff
tests: check (some) debugging output generated during nsyscalls test
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 20 Dec 2017 19:11:05 +0000 (20:11 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 20 Dec 2017 22:58:42 +0000 (22:58 +0000)
* 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.

tests/.gitignore
tests/Makefile.am
tests/nsyscalls-d.c [new file with mode: 0644]
tests/nsyscalls-d.test [new file with mode: 0755]
tests/nsyscalls-nd.test [new file with mode: 0755]
tests/nsyscalls.c

index 7838a5b0363183ff285f88d3cb1cb5b16141fe8d..20b0c9f2ebadc72eaaa0ce83e888ae8a1562d5a0 100644 (file)
@@ -264,6 +264,7 @@ nlattr_tcamsg
 nlattr_tcmsg
 nlattr_unix_diag_msg
 nsyscalls
+nsyscalls-d
 old_mmap
 oldfstat
 oldlstat
index 22a39d7544f6aa81ff059d190ebab1fc082757df..3def7304009bc3acee183eb7227c70fb2cb808ac 100644 (file)
@@ -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 (file)
index 0000000..1525dea
--- /dev/null
@@ -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 (executable)
index 0000000..f94e533
--- /dev/null
@@ -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 (executable)
index 0000000..7d2f1e1
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+debug_flag=
+. "${srcdir=.}"/nsyscalls-d.test
index 29f444a20e235b40f46c33b6989a69caea97303b..9d82a6456e782bf0da8262ba3d6a0849952562fe 100644 (file)
@@ -32,6 +32,7 @@
 #include "sysent.h"
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <asm/unistd.h>
 
@@ -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