Add a regression test for sleeping past the time when time_t wraps; the
program should start sleeping, not throw a libpthread assertion failure.
This commit is contained in:
parent
1990d26431
commit
5f1f443991
15
regress/lib/libpthread/sleep1/Makefile
Normal file
15
regress/lib/libpthread/sleep1/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
# $NetBSD: Makefile,v 1.1 2005/04/19 16:36:34 nathanw Exp $
|
||||
|
||||
WARNS=3
|
||||
|
||||
PROG= sleep1
|
||||
SRCS= sleep1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sleep1
|
||||
|
||||
.include <bsd.prog.mk>
|
61
regress/lib/libpthread/sleep1/sleep1.c
Normal file
61
regress/lib/libpthread/sleep1/sleep1.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* $NetBSD: sleep1.c,v 1.1 2005/04/19 16:36:34 nathanw Exp $ */
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
void *threadfunc(void *);
|
||||
void handler(int);
|
||||
|
||||
/*
|
||||
* More than enough to cross the border from the present time until time_t
|
||||
* wraps in 2038.
|
||||
*/
|
||||
#define LONGTIME 2000000000
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
struct itimerval it;
|
||||
struct sigaction act;
|
||||
|
||||
printf("Testing sleeps unreasonably far into the future.\n");
|
||||
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
sigaction(SIGALRM, &act, NULL);
|
||||
|
||||
pthread_create(&thread, NULL, threadfunc, NULL);
|
||||
|
||||
timerclear(&it.it_interval);
|
||||
timerclear(&it.it_value);
|
||||
it.it_value.tv_sec = 1;
|
||||
setitimer(ITIMER_REAL, &it, NULL);
|
||||
|
||||
pthread_join(thread, NULL);
|
||||
|
||||
printf("Passed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
sleep(LONGTIME);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
handler(int sig)
|
||||
{
|
||||
/*
|
||||
* Nothing to do; invoking the handler is enough to interrupt
|
||||
* the sleep.
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user