[PATCH 2/4] tests: add ptrace.test

Fei Jie feij.fnst at cn.fujitsu.com
Wed May 11 07:07:27 UTC 2016


* tests/ptrace.c: New file.
* tests/ptrace.test: New test.
* tests/.gitignore: Add ptrace.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add ptrace.test.
---
 tests/.gitignore  |  1 +
 tests/Makefile.am |  2 ++
 tests/ptrace.c    | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/ptrace.test |  6 ++++++
 4 files changed, 55 insertions(+)
 create mode 100644 tests/ptrace.c
 create mode 100755 tests/ptrace.test

diff --git a/tests/.gitignore b/tests/.gitignore
index 745b7a1..96533fb 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -152,6 +152,7 @@ pread64-pwrite64
 preadv
 preadv-pwritev
 pselect6
+ptrace
 pwritev
 read-write
 readdir
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c836e49..ce26306 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -205,6 +205,7 @@ check_PROGRAMS = \
 	preadv \
 	preadv-pwritev \
 	pselect6 \
+	ptrace \
 	pwritev \
 	read-write \
 	readdir \
@@ -484,6 +485,7 @@ DECODER_TESTS = \
 	preadv-pwritev.test \
 	preadv.test \
 	pselect6.test \
+	ptrace.test \
 	pwritev.test \
 	read-write.test \
 	readdir.test \
diff --git a/tests/ptrace.c b/tests/ptrace.c
new file mode 100644
index 0000000..df7ae0e
--- /dev/null
+++ b/tests/ptrace.c
@@ -0,0 +1,46 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_ptrace
+
+# include <stdio.h>
+# include <unistd.h>
+# include <sys/ptrace.h>
+# include <signal.h>
+
+# define PTRACE_INVALID 99
+# define PTRACE_O_INVALID (1 << 18)
+# define NT_INVALID 0x111
+
+int
+main(void)
+{
+	long rc = syscall(__NR_ptrace, PTRACE_INVALID, -1, NULL, NULL);
+	printf("ptrace(%#x /* PTRACE_??? */, -1, NULL, NULL) = %ld %s (%m)\n",
+	       PTRACE_INVALID, rc, errno2name());
+
+	rc = syscall(__NR_ptrace, PTRACE_ATTACH, -1, NULL, NULL);
+	printf("ptrace(PTRACE_ATTACH, -1, NULL, NULL) = %ld %s (%m)\n",
+	       rc, errno2name());
+
+	rc = syscall(__NR_ptrace, PTRACE_SETOPTIONS, -1, NULL, PTRACE_O_INVALID);
+	printf("ptrace(PTRACE_SETOPTIONS, -1, NULL, %#x /* PTRACE_O_??? */) = %ld %s (%m)\n",
+	       PTRACE_O_INVALID, rc, errno2name());
+
+	rc = syscall(__NR_ptrace, PTRACE_GETREGSET, -1, NT_INVALID, NULL);
+	printf("ptrace(PTRACE_GETREGSET, -1, %#x /* NT_??? */, NULL) = %ld %s (%m)\n",
+	       NT_INVALID, rc, errno2name());
+
+	rc = syscall(__NR_ptrace, PTRACE_CONT, -1, NULL, 0);
+	printf("ptrace(PTRACE_CONT, -1, NULL, SIG_0) = %ld %s (%m)\n",
+	       rc, errno2name());
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_ptrace")
+
+#endif
diff --git a/tests/ptrace.test b/tests/ptrace.test
new file mode 100755
index 0000000..15e4d5d
--- /dev/null
+++ b/tests/ptrace.test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check ptrace syscall decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a37
-- 
1.8.3.1







More information about the Strace-devel mailing list