1 /* Test for crashing bugs when trying to create too many timers. */ 2 3 #include <stdio.h> 4 #include <time.h> 5 #include <signal.h> 6 #include <sys/time.h> 7 #include <sys/resource.h> 8 #include <unistd.h> 9 10 #if _POSIX_THREADS 11 # include <pthread.h> 12 13 void thread(union sigval arg)14thread (union sigval arg) 15 { 16 puts ("Timeout"); 17 } 18 19 int do_test(void)20do_test (void) 21 { 22 int i, res; 23 timer_t timerId; 24 struct itimerspec itval; 25 struct sigevent sigev; 26 27 itval.it_interval.tv_sec = 2; 28 itval.it_interval.tv_nsec = 0; 29 itval.it_value.tv_sec = 2; 30 itval.it_value.tv_nsec = 0; 31 32 sigev.sigev_notify = SIGEV_THREAD; 33 sigev.sigev_notify_function = thread; 34 sigev.sigev_notify_attributes = NULL; 35 sigev.sigev_value.sival_ptr = (void *) &timerId; 36 37 for (i = 0; i < 100; i++) 38 { 39 printf ("cnt = %d\n", i); 40 41 if (timer_create (CLOCK_REALTIME, &sigev, &timerId) < 0) 42 { 43 perror ("timer_create"); 44 continue; 45 } 46 47 res = timer_settime (timerId, 0, &itval, NULL); 48 if (res < 0) 49 perror ("timer_settime"); 50 51 res = timer_delete (timerId); 52 if (res < 0) 53 perror ("timer_delete"); 54 } 55 56 return 0; 57 } 58 59 # define TEST_FUNCTION do_test () 60 #else 61 # define TEST_FUNCTION 0 62 #endif 63 64 #include "../test-skeleton.c" 65