This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
A testcase for linuxthreads
- To: GNU C Library <libc-alpha at sourceware dot cygnus dot com>
- Subject: A testcase for linuxthreads
- From: "H . J . Lu" <hjl at valinux dot com>
- Date: Wed, 10 Jan 2001 14:13:04 -0800
Here is a testcase for linuxthreads. tstwrapperobj.so is not linked
with libpthread. But it is re-entrant. It should be able to be used
with threaded and non-threaded programs. However, only "test" works.
"test64" fails. It is because open64 has different versions in libc.so
and libpthread.so. I know some people don't think it is a bug. I don't
believe tstwrapperobj.so has to be linked with libpthread in order to
make it thread-safe. The same problem exists with pread, __pread64,
pread64, pwrite, __pwrite64, pwrite64 and lseek64.
--
H.J. Lu (hjl@valinux.com)
---
2001-01-10 H.J. Lu <hjl@gnu.org>
* Makefile (tests): Add tstwrapper for shared library build.
($(objpfx)tstwrapper): New target.
($(objpfx)tstwrapperobj.so): New target.
(tstwrapper-ENV): Set to TMPDIR=$(objpfx).
* tstwrapper.c: New file.
* tstwrapperobj.c: New file.
Index: Makefile
===================================================================
RCS file: /work/cvs/gnu/glibc/linuxthreads/Makefile,v
retrieving revision 1.1.1.11
diff -u -p -r1.1.1.11 Makefile
--- Makefile 2000/09/05 16:55:50 1.1.1.11
+++ Makefile 2001/01/10 21:51:01
@@ -50,6 +50,7 @@ tests = ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8
ifeq (yes,$(build-shared))
tests-nodelete-yes = unload
+tests += tstwrapper
endif
include ../Rules
@@ -71,6 +72,10 @@ ifeq ($(build-shared),yes)
$(addprefix $(objpfx),$(tests)): $(objpfx)libpthread.so
$(addprefix $(objpfx),$(librt-tests)): $(common-objpfx)rt/librt.so
$(objpfx)unload: $(common-objpfx)dlfcn/libdl.so
+$(objpfx)tstwrapper: $(objpfx)tstwrapperobj.so
+$(objpfx)tstwrapperobj.so: $(objpfx)tstwrapperobj.os
+ $(build-module)
+tstwrapper-ENV = TMPDIR=$(objpfx)
else
$(addprefix $(objpfx),$(tests)): $(objpfx)libpthread.a
$(addprefix $(objpfx),$(librt-tests)): $(common-objpfx)rt/librt.a
--- /dev/null Thu Aug 24 02:00:32 2000
+++ tstwrapper.c Wed Jan 10 13:59:19 2001
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <pthread.h>
+
+extern void test (const char *p);
+extern void test64 (const char *p);
+
+static void *foo(void *arg);
+static void print_it(void *);
+
+int
+main(int argc, char ** argv)
+{
+ pthread_t thread, thread64;
+ const char *tmpdir;
+ const char *fifo = "fifo";
+
+ tmpdir = getenv ("TMPDIR");
+ if (tmpdir && tmpdir[0] != '\0')
+ chdir (tmpdir);
+
+ unlink (fifo);
+
+ if (mkfifo (fifo, 0600))
+ {
+ printf ("mkfifo (%s) failed: %m\n", fifo);
+ return 1;
+ }
+
+ pthread_create (&thread, NULL, foo, (void *) test);
+ pthread_cancel (thread);
+ pthread_join (thread, NULL);
+
+ pthread_create (&thread64, NULL, foo, (void *) test64);
+ pthread_cancel (thread64);
+ pthread_join (thread64, NULL);
+
+ if (unlink (fifo))
+ {
+ printf ("unlink (%s) failed: %m\n", fifo);
+ return 1;
+ }
+
+ /* Exit the program */
+ return 0;
+}
+
+static void
+print_it(void *arg)
+{
+ pthread_t tid;
+ const char *func = arg == (void *) test ? "test" : "test64";
+
+ /* Get the calling thread's ID */
+ tid = pthread_self ();
+
+ printf ("Thread %lx (%s) was canceled.\n", tid, func);
+ fflush (stdout);
+}
+
+static void *
+foo (void *arg)
+{
+ void (*t) (const char *) = (void (*) (const char *)) arg;
+
+ pthread_cleanup_push (print_it, (void *) t);
+ t ("fifo");
+ pthread_cleanup_pop (0);
+
+ return (void *)0;
+}
--- /dev/null Thu Aug 24 02:00:32 2000
+++ tstwrapperobj.c Wed Jan 10 13:59:41 2001
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+void
+test (const char *fifo)
+{
+ int wfd;
+
+ wfd = open (fifo, O_WRONLY);
+ if (wfd < 0)
+ {
+ printf ("open (%s) for write failed: %m\n", fifo);
+ return;
+ }
+
+ close (wfd);
+}
+
+void
+test64 (const char *fifo)
+{
+ int wfd;
+
+ wfd = open64 (fifo, O_WRONLY);
+ if (wfd < 0)
+ {
+ printf ("open (%s) for write failed: %m\n", fifo);
+ return;
+ }
+
+ close (wfd);
+}