Convert test/select.c into a regular test.
* test/Makefile (PROGS): Remove select.
* test/.gitignore: Likewise.
* test/select.c: Rewrite to ...
* tests/select.c: ... new file.
* tests/select.awk: New file.
* tests/select.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add select.
(TESTS): Add select.test.
(EXTRA_DIST): Add select.awk.
* tests/.gitignore: Add select.
threaded_execve
mtd
ubi
-select
sigreturn
PROGS = \
vfork fork sig skodic clone leaderkill childthread \
sigkill_rain wait_must_be_interruptible threaded_execve \
- mtd ubi select sigreturn
+ mtd ubi sigreturn
all: $(PROGS)
+++ /dev/null
-/* dave@treblig.org */
-#include <sys/select.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-char buffer[1024*1024*2];
-
-int main()
-{
- fd_set rds;
- struct timeval timeout;
-
- FD_ZERO(&rds);
- FD_SET(2, &rds);
- /* Start with a nice simple select */
- select(3, &rds, &rds, &rds, NULL);
-
- /* Now the crash case that trinity found, negative nfds
- * but with a pointer to a large chunk of valid memory.
- */
- FD_ZERO((fd_set*)buffer);
- FD_SET(2,(fd_set*)buffer);
- select(-1, (fd_set *)buffer, NULL, NULL, NULL);
-
- /* Another variant, with nfds exceeding allowed limit. */
- timeout.tv_sec = 0;
- timeout.tv_usec = 100;
- select(FD_SETSIZE + 1, (fd_set *)buffer, NULL, NULL, &timeout);
-
- return 0;
-}
netlink_inet_diag
netlink_unix_diag
scm_rights
+select
set_ptracer_any
sigaction
stack-fcall
netlink_inet_diag \
netlink_unix_diag \
scm_rights \
+ select \
set_ptracer_any \
sigaction \
stack-fcall \
ipc_shm.test \
ipc_sem.test \
scm_rights-fd.test \
+ select.test \
sigaction.test \
stat.test \
stat32-v.test \
mmsg.expected \
net-yy-accept.awk \
net-yy-connect.awk \
+ select.awk \
sigaction.awk \
uid.awk \
unix-yy-accept.awk \
--- /dev/null
+BEGIN {
+ r[1] = "^select\\(2, \\[0 1\\], \\[0 1\\], \\[0 1\\], NULL\\) += 1 \\(\\)$"
+ r[2] = "^select\\(-1, NULL, 0x[0-9a-f]+, NULL, NULL\\) += -1 "
+ r[3] = "^select\\(1025, \\[0\\], \\[\\], NULL, \\{0, 100\\}\\) += 0 \\(Timeout\\)$"
+ r[4] = "^\\+\\+\\+ exited with 0 \\+\\+\\+$"
+ lines = 4
+ fail = 0
+}
+
+NR > lines { exit 1 }
+
+{
+ if (match($0, r[NR]))
+ next
+
+ print "Line " NR " does not match."
+ fail = 1
+}
+
+END {
+ if (fail == 0 && NR != lines) {
+ fail = 1
+ print "Expected " lines " lines, found " NR " line(s)."
+ }
+ exit fail
+}
--- /dev/null
+/*
+ * Based on test by Dr. David Alan Gilbert <dave@treblig.org>
+ */
+#include <assert.h>
+#include <unistd.h>
+#include <sys/select.h>
+
+static fd_set set[0x1000000 / sizeof(fd_set)];
+
+int main()
+{
+ int fds[2];
+ struct timeval timeout = { .tv_sec = 0, .tv_usec = 100 };
+
+ (void) close(0);
+ (void) close(1);
+ assert(pipe(fds) == 0);
+
+ /*
+ * Start with a nice simple select.
+ */
+ FD_ZERO(set);
+ FD_SET(0, set);
+ FD_SET(1, set);
+ assert(select(2, set, set, set, NULL) == 1);
+
+ /*
+ * Now the crash case that trinity found, negative nfds
+ * but with a pointer to a large chunk of valid memory.
+ */
+ FD_ZERO(set);
+ FD_SET(1,set);
+ assert(select(-1, NULL, set, NULL, NULL) == -1);
+
+ /*
+ * Another variant, with nfds exceeding FD_SETSIZE limit.
+ */
+ FD_ZERO(set);
+ FD_SET(0,set);
+ assert(select(FD_SETSIZE + 1, set, set + 1, NULL, &timeout) == 0);
+
+ return 0;
+}
--- /dev/null
+#!/bin/sh
+
+# Check select syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+check_prog awk
+
+./select ||
+ framework_skip_ 'select syscall does not behave as expected'
+
+args="-eselect ./select"
+$STRACE -o "$LOG" $args || {
+ cat "$LOG"
+ fail_ "$STRACE $args failed"
+}
+
+awk -f "$srcdir"/select.awk "$LOG" || {
+ cat "$LOG"
+ fail_ 'unexpected output'
+}
+
+exit 0