[PATCH 2/3] tests: add dup.test

Fei Jie feij.fnst at cn.fujitsu.com
Fri Mar 4 09:10:47 UTC 2016


* tests/dup.c: New file.
* tests/dup.test: New test.
* tests/.gitignore: Add dup.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add dup.test.
---
 tests/.gitignore  |  1 +
 tests/Makefile.am |  2 ++
 tests/dup.c       | 33 +++++++++++++++++++++++++++++++++
 tests/dup.test    | 11 +++++++++++
 4 files changed, 47 insertions(+)
 create mode 100644 tests/dup.c
 create mode 100755 tests/dup.test

diff --git a/tests/.gitignore b/tests/.gitignore
index e0e83f1..9d8e9ef 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -17,6 +17,7 @@ caps
 clock_nanosleep
 clock_xettime
 copy_file_range
+dup
 epoll_create1
 eventfd
 execve
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2d704ef..e03f5fd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -67,6 +67,7 @@ check_PROGRAMS = \
 	clock_nanosleep \
 	clock_xettime \
 	copy_file_range \
+	dup \
 	epoll_create1 \
 	eventfd \
 	execve \
@@ -231,6 +232,7 @@ TESTS = \
 	clock_xettime.test \
 	copy_file_range.test \
 	dumpio.test \
+	dup.test \
 	epoll_create1.test \
 	eventfd.test \
 	execve.test \
diff --git a/tests/dup.c b/tests/dup.c
new file mode 100644
index 0000000..3508802
--- /dev/null
+++ b/tests/dup.c
@@ -0,0 +1,33 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#if defined __NR_dup && defined __NR_dup2
+
+# include <errno.h>
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	const long int fd_old = (long int) 0xdeadbeefffffffff;
+	const long int fd_new = (long int) 0xdeadbeeffffffffe;
+	int rc = syscall(__NR_dup, fd_old);
+	printf("dup(%d) = %d %s (%m)\n",
+	       (int)fd_old, rc,
+	       errno == ENOSYS ? "ENOSYS" : "EBADF");
+
+	rc = syscall(__NR_dup2, fd_old, fd_new);
+	printf("dup2(%d, %d) = %d %s (%m)\n",
+	       (int) fd_old, (int) fd_new, rc,
+	       errno == ENOSYS ? "ENOSYS" : "EBADF");
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_dup && __NR_dup2")
+
+#endif
diff --git a/tests/dup.test b/tests/dup.test
new file mode 100755
index 0000000..5e61416
--- /dev/null
+++ b/tests/dup.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check dup and dup2 syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -edup,dup2 -a8 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1







More information about the Strace-devel mailing list