[PATCH v2 2/3] tests: add dup.test, dup2.test and dup3.test

Fei Jie feij.fnst at cn.fujitsu.com
Mon Mar 7 03:32:02 UTC 2016


* tests/dup.c: New file.
* tests/dup.test: New test.
* tests/dup2.c: New file.
* tests/dup2.test: New test.
* tests/dup3.c: New file.
* tests/dup3.test: New test.
* tests/.gitignore: Add dup, dup2 and dup3.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add dup.test, dup2.test and dup3.test.
---
 tests/.gitignore  |  3 +++
 tests/Makefile.am |  6 ++++++
 tests/dup.c       | 27 +++++++++++++++++++++++++++
 tests/dup.test    | 11 +++++++++++
 tests/dup2.c      | 28 ++++++++++++++++++++++++++++
 tests/dup2.test   | 11 +++++++++++
 tests/dup3.c      | 29 +++++++++++++++++++++++++++++
 tests/dup3.test   | 11 +++++++++++
 8 files changed, 126 insertions(+)
 create mode 100644 tests/dup.c
 create mode 100755 tests/dup.test
 create mode 100644 tests/dup2.c
 create mode 100755 tests/dup2.test
 create mode 100644 tests/dup3.c
 create mode 100755 tests/dup3.test

diff --git a/tests/.gitignore b/tests/.gitignore
index e0e83f1..0ad62fb 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -17,6 +17,9 @@ caps
 clock_nanosleep
 clock_xettime
 copy_file_range
+dup
+dup2
+dup3
 epoll_create1
 eventfd
 execve
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2d704ef..deb3ecb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -67,6 +67,9 @@ check_PROGRAMS = \
 	clock_nanosleep \
 	clock_xettime \
 	copy_file_range \
+	dup \
+	dup2 \
+	dup3 \
 	epoll_create1 \
 	eventfd \
 	execve \
@@ -231,6 +234,9 @@ TESTS = \
 	clock_xettime.test \
 	copy_file_range.test \
 	dumpio.test \
+	dup.test \
+	dup2.test \
+	dup3.test \
 	epoll_create1.test \
 	eventfd.test \
 	execve.test \
diff --git a/tests/dup.c b/tests/dup.c
new file mode 100644
index 0000000..bc79470
--- /dev/null
+++ b/tests/dup.c
@@ -0,0 +1,27 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_dup
+
+# include <errno.h>
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	const long int fd = (long int) 0xdeadbeefffffffff;
+	int rc = syscall(__NR_dup, fd);
+	printf("dup(%d) = %d %s (%m)\n",
+	       (int)fd, rc,
+	       errno == ENOSYS ? "ENOSYS" : "EBADF");
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_dup")
+
+#endif
diff --git a/tests/dup.test b/tests/dup.test
new file mode 100755
index 0000000..f33dd97
--- /dev/null
+++ b/tests/dup.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check dup syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -edup -a8 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
diff --git a/tests/dup2.c b/tests/dup2.c
new file mode 100644
index 0000000..19187c5
--- /dev/null
+++ b/tests/dup2.c
@@ -0,0 +1,28 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#ifdef __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_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_dup2")
+
+#endif
diff --git a/tests/dup2.test b/tests/dup2.test
new file mode 100755
index 0000000..d2e6bc7
--- /dev/null
+++ b/tests/dup2.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check dup2 syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -edup2 -a13 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
diff --git a/tests/dup3.c b/tests/dup3.c
new file mode 100644
index 0000000..24232dc
--- /dev/null
+++ b/tests/dup3.c
@@ -0,0 +1,29 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_dup3
+
+# include <errno.h>
+# include <fcntl.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_dup3, fd_old, fd_new, O_CLOEXEC);
+	printf("dup3(%d, %d, O_CLOEXEC) = %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_dup3")
+
+#endif
diff --git a/tests/dup3.test b/tests/dup3.test
new file mode 100755
index 0000000..61fc16e
--- /dev/null
+++ b/tests/dup3.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check dup3 syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -edup3 -a24 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1







More information about the Strace-devel mailing list