From: Fei Jie Date: Thu, 10 Mar 2016 02:41:31 +0000 (+0800) Subject: tests: add dup.test, dup2.test, and dup3.test X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab917ae5af552dccc42c42327776b2562643b71e;p=strace tests: add dup.test, dup2.test, and dup3.test * 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. --- diff --git a/tests/.gitignore b/tests/.gitignore index 148f933c..e08aa97a 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 50902a65..f6d1c827 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 00000000..74972698 --- /dev/null +++ b/tests/dup.c @@ -0,0 +1,16 @@ +#include +#include +#include + +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 00000000..f33dd978 --- /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 00000000..0705af69 --- /dev/null +++ b/tests/dup2.c @@ -0,0 +1,28 @@ +#include "tests.h" +#include + +#ifdef __NR_dup2 + +# include +# include +# include + +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 00000000..d2e6bc7d --- /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 00000000..b57f05a6 --- /dev/null +++ b/tests/dup3.c @@ -0,0 +1,29 @@ +#include "tests.h" +#include +#include + +#if defined __NR_dup3 && defined O_CLOEXEC + +# include +# include +# include + +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 00000000..61fc16e1 --- /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"