Module Name: src
Committed By: drochner
Date: Thu Apr 2 12:58:45 UTC 2009
Modified Files:
src/regress/lib/libpthread: Makefile
Added Files:
src/regress/lib/libpthread/find: Makefile findthreads.c findthreads.sh
Log Message:
add a test which exercises libpthread's ability to remember the
threads which were created, doing some random mallocs in between
so that threads are not equidistant in the address space
(bug fixed in libpthread/pthread.c rev. 1.109)
To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/regress/lib/libpthread/Makefile
cvs rdiff -u -r0 -r1.1 src/regress/lib/libpthread/find/Makefile \
src/regress/lib/libpthread/find/findthreads.c \
src/regress/lib/libpthread/find/findthreads.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/regress/lib/libpthread/Makefile
diff -u src/regress/lib/libpthread/Makefile:1.31 src/regress/lib/libpthread/Makefile:1.32
--- src/regress/lib/libpthread/Makefile:1.31 Sat Jan 20 19:40:06 2007
+++ src/regress/lib/libpthread/Makefile Thu Apr 2 12:58:44 2009
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.31 2007/01/20 19:40:06 ad Exp $
+# $NetBSD: Makefile,v 1.32 2009/04/02 12:58:44 drochner Exp $
.include <bsd.own.mk>
@@ -20,6 +20,7 @@
cancel2 \
cond1 cond2 cond3 cond4 cond5 cond6 condcancel1 \
exit1 \
+ find \
fork \
fpu \
kill1 \
Added files:
Index: src/regress/lib/libpthread/find/Makefile
diff -u /dev/null src/regress/lib/libpthread/find/Makefile:1.1
--- /dev/null Thu Apr 2 12:58:45 2009
+++ src/regress/lib/libpthread/find/Makefile Thu Apr 2 12:58:44 2009
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2009/04/02 12:58:44 drochner Exp $
+
+WARNS=4
+
+PROG= findthreads
+LDADD= -lpthread
+
+NOMAN=
+
+regress:
+ sh ${.CURDIR}/findthreads.sh
+
+.include <bsd.prog.mk>
Index: src/regress/lib/libpthread/find/findthreads.c
diff -u /dev/null src/regress/lib/libpthread/find/findthreads.c:1.1
--- /dev/null Thu Apr 2 12:58:45 2009
+++ src/regress/lib/libpthread/find/findthreads.c Thu Apr 2 12:58:44 2009
@@ -0,0 +1,58 @@
+/* $NetBSD: findthreads.c,v 1.1 2009/04/02 12:58:44 drochner Exp $ */
+
+#include <err.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/resource.h>
+
+static void *
+f(void *arg)
+{
+
+ sleep(1000);
+ return 0;
+}
+
+#define NUM 100
+int
+main(int argc, char **argv)
+{
+ pthread_t thr[NUM];
+ int seed, i, j, res, errors;
+ char nam[20];
+ struct rlimit sl;
+
+ if (argc > 1)
+ seed = atoi(argv[1]);
+ else
+ seed = time(0);
+ srandom(seed);
+ getrlimit(RLIMIT_STACK, &sl);
+
+ errors = 0;
+ for (i = 0; i < NUM; i++) {
+ res = pthread_create(&thr[i], 0, f, 0);
+ if (res)
+ errx(1, "pthread_create: %s", strerror(res));
+ for (j = 0; j <= i; j++) {
+ res = pthread_getname_np(thr[j], nam, sizeof(nam));
+ if (res) {
+ warnx("getname(%d/%d): %s\n", i, j,
+ strerror(res));
+ errors++;
+ }
+ }
+ if (errors)
+ break;
+ malloc((random() & 7) * sl.rlim_cur);
+ }
+ if (errors) {
+ printf("%d errors\n", errors);
+ if (argc <= 1)
+ printf("seed was %d\n", seed);
+ }
+ return (!!errors);
+}
Index: src/regress/lib/libpthread/find/findthreads.sh
diff -u /dev/null src/regress/lib/libpthread/find/findthreads.sh:1.1
--- /dev/null Thu Apr 2 12:58:45 2009
+++ src/regress/lib/libpthread/find/findthreads.sh Thu Apr 2 12:58:44 2009
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+s=0
+while expr $s \< 100 >/dev/null; do
+ ./findthreads $s || exit 1
+ s=`expr $s + 1`
+done