tst-timer2.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_notify_function = thread;
  28. sigev.sigev_notify_attributes = NULL;
  29. sigev.sigev_value.sival_ptr = (void *) &timerId;
  30. for (i = 0; i < 100; i++)
  31. {
  32. printf ("cnt = %d\n", i);
  33. if (timer_create (CLOCK_REALTIME, &sigev, &timerId) < 0)
  34. {
  35. perror ("timer_create");
  36. continue;
  37. }
  38. res = timer_settime (timerId, 0, &itval, NULL);
  39. if (res < 0)
  40. perror ("timer_settime");
  41. res = timer_delete (timerId);
  42. if (res < 0)
  43. perror ("timer_delete");
  44. }
  45. return 0;
  46. }
  47. # define TEST_FUNCTION do_test ()
  48. #else
  49. # define TEST_FUNCTION 0
  50. #endif
  51. #include "../test-skeleton.c"