[PATCH v4 2/2] tests: add dup.test, dup2.test and dup3.test
Fei Jie
feij.fnst at cn.fujitsu.com
Thu Mar 10 02:41:31 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 | 16 ++++++++++++++++
tests/dup.test | 11 +++++++++++
tests/dup2.c | 28 ++++++++++++++++++++++++++++
tests/dup2.test | 11 +++++++++++
tests/dup3.c | 29 +++++++++++++++++++++++++++++
tests/dup3.test | 11 +++++++++++
8 files changed, 115 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 ca392cb..9159962 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -19,6 +19,9 @@ chmod
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 5f9d67e..08fa5e4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -69,6 +69,9 @@ check_PROGRAMS = \
clock_nanosleep \
clock_xettime \
copy_file_range \
+ dup \
+ dup2 \
+ dup3 \
epoll_create1 \
eventfd \
execve \
@@ -235,6 +238,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..7497269
--- /dev/null
+++ b/tests/dup.c
@@ -0,0 +1,16 @@
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+ const int fd = -1;
+ int rc = dup(fd);
+ printf("dup(%d) = %d %s (%m)\n",
+ fd, rc,
+ errno == ENOSYS ? "ENOSYS" : "EBADF");
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
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..0705af6
--- /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..b57f05a
--- /dev/null
+++ b/tests/dup3.c
@@ -0,0 +1,29 @@
+#include "tests.h"
+#include <fcntl.h>
+#include <sys/syscall.h>
+
+#if defined __NR_dup3 && defined O_CLOEXEC
+
+# 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_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 && && O_CLOEXEC")
+
+#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