]> granicus.if.org Git - strace/commitdiff
tests: add pselect6.test
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 15 Sep 2015 02:14:38 +0000 (02:14 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 15 Sep 2015 02:14:38 +0000 (02:14 +0000)
* tests/pselect6.c: New file.
* tests/pselect6.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add pselect6.
(TESTS): Add pselect6.test.
* tests/.gitignore: Add pselect6.

tests/.gitignore
tests/Makefile.am
tests/pselect6.c [new file with mode: 0644]
tests/pselect6.test [new file with mode: 0755]

index 624aaae6fb56dd87d9709a977ab79ac258b56352..6f3aefecb4ec79d504cfe847ed9fd4b751b0ca89 100644 (file)
@@ -27,6 +27,7 @@ oldselect
 pc
 pipe
 ppoll
+pselect6
 readlink
 readlinkat
 rt_sigqueueinfo
index 5ae29e489228b7e92c6977b529b46b70ed7c9a20..dbe4310e35fac162974de9407b61a9c56beb1004 100644 (file)
@@ -40,6 +40,7 @@ check_PROGRAMS = \
        pc \
        pipe \
        ppoll \
+       pselect6 \
        readlink \
        readlinkat \
        rt_sigqueueinfo \
@@ -110,6 +111,7 @@ TESTS = \
        ipc_shm.test \
        ipc_sem.test \
        mq.test \
+       pselect6.test \
        readlink.test \
        readlinkat.test \
        rt_sigqueueinfo.test \
diff --git a/tests/pselect6.c b/tests/pselect6.c
new file mode 100644 (file)
index 0000000..445d933
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Based on test by Dr. David Alan Gilbert <dave@treblig.org>
+ */
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/select.h>
+
+#ifndef NSIG
+# warning NSIG is not defined, using 32
+# define NSIG 32
+#endif
+
+static fd_set set[3][0x1000000 / sizeof(fd_set)];
+
+int main(int ac, char **av)
+{
+       int fds[2];
+       struct timespec timeout = { .tv_sec = 0, .tv_nsec = 100 };
+       sigset_t mask;
+
+       sigemptyset(&mask);
+       sigaddset(&mask, SIGHUP);
+       sigaddset(&mask, SIGCHLD);
+
+       assert(pipe(fds) == 0);
+
+       /*
+        * Start with a nice simple pselect.
+        */
+       FD_SET(fds[0], set[0]);
+       FD_SET(fds[1], set[0]);
+       FD_SET(fds[0], set[1]);
+       FD_SET(fds[1], set[1]);
+       FD_SET(1, set[2]);
+       FD_SET(2, set[2]);
+       assert(pselect(fds[1] + 1, set[0], set[1], set[2], NULL, NULL) == 1);
+       printf("pselect6(%d, [%d %d], [%d %d], [1 2], NULL, {NULL, %u}) "
+              "= 1 (out [%d])\n",
+              fds[1] + 1, fds[0], fds[1],
+              fds[0], fds[1],
+              NSIG / 8, fds[1]);
+
+       /*
+        * Now the crash case that trinity found, negative nfds
+        * but with a pointer to a large chunk of valid memory.
+        */
+       FD_ZERO(set[0]);
+       FD_SET(fds[1],set[0]);
+       assert(pselect(-1, NULL, set[0], NULL, NULL, &mask) == -1);
+       printf("pselect6(-1, NULL, %p, NULL, NULL, {[HUP CHLD], %u}) "
+              "= -1 EINVAL (Invalid argument)\n", set[0], NSIG / 8);
+
+       /*
+        * Another variant, with nfds exceeding FD_SETSIZE limit.
+        */
+       FD_ZERO(set[0]);
+       FD_SET(fds[0],set[0]);
+       FD_ZERO(set[1]);
+       assert(pselect(FD_SETSIZE + 1, set[0], set[1], NULL, &timeout, &mask) == 0);
+       printf("pselect6(%d, [%d], [], NULL, {0, 100}, {[HUP CHLD], %u}) "
+              "= 0 (Timeout)\n", FD_SETSIZE + 1, fds[0], NSIG / 8);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
diff --git a/tests/pselect6.test b/tests/pselect6.test
new file mode 100755 (executable)
index 0000000..46713f1
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# Check pselect6 syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -e pselect6 $args > "$OUT"
+match_diff "$OUT" "$LOG"
+
+rm -f "$OUT"
+
+exit 0