Add a regression test for CV teardown under spurious wakeups (currently fails).

This commit is contained in:
nathanw 2004-07-07 21:53:10 +00:00
parent bd6daf04d5
commit 1c5109c418
3 changed files with 94 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.19 2004/05/21 16:08:47 christos Exp $
# $NetBSD: Makefile,v 1.20 2004/07/07 21:53:10 nathanw Exp $
.include <bsd.own.mk>
@ -16,7 +16,7 @@ ARCHSUBDIR= ${MACHINE_CPU}
.if defined(ARCHSUBDIR)
SUBDIR+= atexit barrier1 cancel2 cond1 cond2 cond3 cond4 cond5 condcancel1 \
exit1 fork mutex1 mutex2 mutex3 mutex4 name once1 once2 \
conddestroy1 exit1 fork mutex1 mutex2 mutex3 mutex4 name once1 once2 \
preempt1 resolv sem sigalarm sigmask1 siglongjmp1 sigsuspend
.endif

View File

@ -0,0 +1,15 @@
# $NetBSD: Makefile,v 1.1 2004/07/07 21:53:10 nathanw Exp $
WARNS=1
PROG= conddestroy1
SRCS= conddestroy1.c
LDADD= -lpthread
NOMAN=
regress:
./conddestroy1
.include <bsd.prog.mk>

View File

@ -0,0 +1,77 @@
/* $NetBSD: conddestroy1.c,v 1.1 2004/07/07 21:53:10 nathanw Exp $ */
#include <signal.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void handler(int);
void *threadroutine(void *);
pthread_mutex_t mt;
pthread_cond_t cv;
void
handler(int sig)
{
/* Dummy */
return;
}
void *
threadroutine(void *arg)
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
pthread_mutex_lock(&mt);
/*
* Explicitly not a loop; we want to see if the cv is properly
* torn down in a spurious wakeup (generated here by SIGALRM).
*/
pthread_cond_wait(&cv, &mt);
pthread_mutex_unlock(&mt);
return NULL;
}
int
main(void)
{
pthread_t th;
sigset_t set;
struct sigaction act;
printf("Testing CV teardown under spurious wakeups.\n");
sigfillset(&set);
pthread_sigmask(SIG_BLOCK, &set, NULL);
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGALRM, &act, NULL);
pthread_mutex_init(&mt, NULL);
pthread_cond_init(&cv, NULL);
pthread_create(&th, NULL, threadroutine, NULL);
alarm(1);
pthread_join(th, NULL);
pthread_cond_destroy(&cv);
pthread_mutex_destroy(&mt);
printf("Passed.\n");
return 0;
}