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)
This commit is contained in:
parent
103beeac7d
commit
6e71fa2242
|
@ -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 @@ SUBDIR+= atexit \
|
|||
cancel2 \
|
||||
cond1 cond2 cond3 cond4 cond5 cond6 condcancel1 \
|
||||
exit1 \
|
||||
find \
|
||||
fork \
|
||||
fpu \
|
||||
kill1 \
|
||||
|
|
|
@ -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>
|
|
@ -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);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
s=0
|
||||
while expr $s \< 100 >/dev/null; do
|
||||
./findthreads $s || exit 1
|
||||
s=`expr $s + 1`
|
||||
done
|
Loading…
Reference in New Issue