tst-timer2.c 1.2 KB

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