tests: add dup.test, dup2.test, and dup3.test
authorFei Jie <feij.fnst@cn.fujitsu.com>
Thu, 10 Mar 2016 02:41:31 +0000 (10:41 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 10 Mar 2016 02:41:31 +0000 (02:41 +0000)
* 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
tests/Makefile.am
tests/dup.c [new file with mode: 0644]
tests/dup.test [new file with mode: 0755]
tests/dup2.c [new file with mode: 0644]
tests/dup2.test [new file with mode: 0755]
tests/dup3.c [new file with mode: 0644]
tests/dup3.test [new file with mode: 0755]

index 148f933cf68c9001a55fce25e5015482cbf5e324..e08aa97a0be46d500d3dd561dac269d44d9bdae2 100644 (file)
@@ -19,6 +19,9 @@ chmod
 clock_nanosleep
 clock_xettime
 copy_file_range
+dup
+dup2
+dup3
 epoll_create1
 eventfd
 execve
index 50902a65139e090de6bd2a16a83e3d1cdbb6df0e..f6d1c827dec731b98d46dbd5dda6c3cdfbb31f0c 100644 (file)
@@ -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 (file)
index 0000000..7497269
--- /dev/null
@@ -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 (executable)
index 0000000..f33dd97
--- /dev/null
@@ -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 (file)
index 0000000..0705af6
--- /dev/null
@@ -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 (executable)
index 0000000..d2e6bc7
--- /dev/null
@@ -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 (file)
index 0000000..b57f05a
--- /dev/null
@@ -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 (executable)
index 0000000..61fc16e
--- /dev/null
@@ -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"