summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2003-02-04 21:21:01 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2003-02-04 21:21:01 +0000
commit0691abffebb064ad7318896c4ee8b0a26b049654 (patch)
treeff956bc200bae80efa1407104226ba8715d3da43
parente31598a61967d6a43e6e20f72aae01f47ca44a67 (diff)
Add test to compare threaded vs non-threaded fd handling.
Test not enabled (yet).
-rw-r--r--regress/lib/libpthread/stdfiles/Makefile35
-rw-r--r--regress/lib/libpthread/stdfiles/stdfiles.c127
2 files changed, 162 insertions, 0 deletions
diff --git a/regress/lib/libpthread/stdfiles/Makefile b/regress/lib/libpthread/stdfiles/Makefile
new file mode 100644
index 00000000000..e60fed7aac7
--- /dev/null
+++ b/regress/lib/libpthread/stdfiles/Makefile
@@ -0,0 +1,35 @@
+# $OpenBSD: Makefile,v 1.1 2003/02/04 21:21:00 marc Exp $
+#
+
+PROG= stdfiles
+
+PROG2= stdfiles2
+OBJS2= stdfiles.o
+
+CLEANFILES+= ${PROG2} threads no-threads
+
+REGRESS_TARGETS=diff
+
+# run program after linking with pthreads
+#
+threads: ${PROG}
+ ./${PROG} > threads
+
+# build the same program, but not linked with pthreads
+#
+${PROG2}: ${LIBCRT0} ${OBJS} ${LIBC} ${CRTBEGIN} ${CRTEND} ${DPADD}
+ ${CC} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${OBJS}
+
+# run the non-pthread version
+#
+no-threads: ${PROG2}
+ ./${PROG2} > no-threads
+
+# compare the thread output to the non-thread output, should be the same
+#
+diff: threads no-threads
+ diff -u threads no-threads
+
+.PHONY: threads no-threads diff
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/stdfiles/stdfiles.c b/regress/lib/libpthread/stdfiles/stdfiles.c
new file mode 100644
index 00000000000..456032ffe43
--- /dev/null
+++ b/regress/lib/libpthread/stdfiles/stdfiles.c
@@ -0,0 +1,127 @@
+/* $snafu: stdfiles.c,v 1.3 2003/02/03 21:22:26 marc Exp $ */
+/* PUBLIC DOMAIN Oct 2002 <marc@snafu.org> */
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+/*
+ * test what happens to blocking/non-blocking mode on stdout/stderr when
+ * it is changed on stdin. A comment in the pthreads code implies that
+ * all three files are linked. Check it out.
+ */
+
+int
+main(int argc, char *argv[])
+{
+ int dup_stdout;
+ int stdin_flags;
+ int stdout_flags;
+ int dup_flags;
+ int stderr_flags;
+ int new_flags;
+ int new_fd;
+
+ /* dup stdout for the fun of it. */
+ dup_stdout = dup(STDOUT_FILENO);
+
+ /* read std in/out/err flags */
+ stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
+ assert(stdin_flags != -1);
+ stdout_flags = fcntl(STDOUT_FILENO, F_GETFL, 0);
+ assert(stdout_flags != -1);
+ dup_flags = fcntl(dup_stdout, F_GETFL, 0);
+ assert(dup_flags != -1);
+ stderr_flags = fcntl(STDERR_FILENO, F_GETFL, 0);
+ assert(stderr_flags != -1);
+ printf("starting flags: in = %x, out = %x, dup = %x, err = %x\n",
+ stdin_flags, stdout_flags, dup_flags, stderr_flags);
+
+ /* set stdin to non-blocking mode and see if stdout/stderr change */
+ new_flags = stdin_flags | O_NONBLOCK;
+ printf("forcing stdin to O_NONBLOCK (flags %x)\n", new_flags);
+ assert(fcntl(STDIN_FILENO, F_SETFL, new_flags) != -1);
+
+ new_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
+ assert(new_flags != -1);
+ if (new_flags != stdin_flags) {
+ printf("stdin flags changed %x -> %x\n", stdin_flags,
+ new_flags);
+ stdin_flags = new_flags;
+ }
+
+ new_flags = fcntl(STDOUT_FILENO, F_GETFL, 0);
+ assert(new_flags != -1);
+ if (new_flags != stdout_flags) {
+ printf("stdout flags changed %x -> %x\n", stdout_flags,
+ new_flags);
+ stdout_flags = new_flags;
+ }
+
+ new_flags = fcntl(dup_stdout, F_GETFL, 0);
+ assert(new_flags != -1);
+ if (new_flags != dup_flags) {
+ printf("dup_stdout flags changed %x -> %x\n", dup_flags,
+ new_flags);
+ dup_flags = new_flags;
+ }
+
+ new_flags = fcntl(STDERR_FILENO, F_GETFL, 0);
+ assert(new_flags != -1);
+ if (new_flags != stderr_flags) {
+ printf("stderr flags changed %x -> %x\n", stderr_flags,
+ new_flags);
+ stderr_flags = new_flags;
+ }
+
+ /*
+ * Close stderr and open /dev/tty. See what it's flags
+ * are. Set the file to non blocking.
+ */
+ printf("close stderr and open /dev/tty\n");
+ assert(close(STDERR_FILENO) != -1);
+ new_fd = open("/dev/tty", O_RDWR|O_CREAT, 0666);
+ assert(new_fd == STDERR_FILENO);
+ new_flags = fcntl(STDERR_FILENO, F_GETFL, 0);
+ assert(new_flags != -1);
+ printf("/dev/tty [STDERR_FILENO] flags are %x\n", new_flags);
+ stderr_flags = new_flags | O_NONBLOCK;
+ printf("forcing /dev/tty to O_NONBLOCK (flags %x)\n", stderr_flags);
+ assert(fcntl(STDERR_FILENO, F_SETFL, stdin_flags) != -1);
+
+ /* now turn off non blocking mode on stdin */
+ stdin_flags &= ~O_NONBLOCK;
+ printf("turning off O_NONBLOCK on stdin (flags %x)\n", stdin_flags);
+ assert(fcntl(STDIN_FILENO, F_SETFL, stdin_flags) != -1);
+
+ new_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
+ assert(new_flags != -1);
+ assert(new_flags == stdin_flags);
+
+ new_flags = fcntl(STDOUT_FILENO, F_GETFL, 0);
+ assert(new_flags != -1);
+ if (new_flags != stdout_flags) {
+ printf("stdout flags changed %x -> %x\n", stdout_flags,
+ new_flags);
+ stdout_flags = new_flags;
+ }
+
+ new_flags = fcntl(dup_stdout, F_GETFL, 0);
+ assert(new_flags != -1);
+ if (new_flags != dup_flags) {
+ printf("dup_stdout flags changed %x -> %x\n", dup_flags,
+ new_flags);
+ dup_flags = new_flags;
+ }
+
+ new_flags = fcntl(STDERR_FILENO, F_GETFL, 0);
+ assert(new_flags != -1);
+ if (new_flags != stderr_flags) {
+ printf("stderr flags changed %x -> %x\n", stderr_flags,
+ new_flags);
+ stderr_flags = new_flags;
+ }
+
+ return 0;
+}