summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2017-12-20 20:11:05 +0100
committerDmitry V. Levin <ldv@altlinux.org>2017-12-20 22:58:42 +0000
commit51e1f187f063d024f2c13a994b68fce2f448f08e (patch)
tree5f29baf29cd0141a11389b03aacd85cec602dc33
parentbfbfdf5e37eed3bdd95bb2e7cc715519c3023e52 (diff)
downloadstrace-51e1f187f063d024f2c13a994b68fce2f448f08e.tar.gz
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.
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/nsyscalls-d.c2
-rwxr-xr-xtests/nsyscalls-d.test24
-rwxr-xr-xtests/nsyscalls-nd.test4
-rw-r--r--tests/nsyscalls.c36
6 files changed, 69 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 7838a5b03..20b0c9f2e 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 22a39d754..3def73040 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 000000000..1525dea0b
--- /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 000000000..f94e533ff
--- /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 000000000..7d2f1e1f3
--- /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 29f444a20..9d82a6456 100644
--- a/tests/nsyscalls.c
+++ b/tests/nsyscalls.c
@@ -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