tst-cond19.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (C) 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <errno.h>
  17. #include <pthread.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <time.h>
  21. static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  22. static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
  23. static int
  24. do_test (void)
  25. {
  26. int result = 0;
  27. struct timespec ts;
  28. if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
  29. {
  30. puts ("clock_gettime failed");
  31. return 1;
  32. }
  33. ts.tv_nsec = -1;
  34. int e = pthread_cond_timedwait (&cond, &mut, &ts);
  35. if (e == 0)
  36. {
  37. puts ("first cond_timedwait did not fail");
  38. result = 1;
  39. }
  40. else if (e != EINVAL)
  41. {
  42. puts ("first cond_timedwait did not return EINVAL");
  43. result = 1;
  44. }
  45. ts.tv_nsec = 2000000000;
  46. e = pthread_cond_timedwait (&cond, &mut, &ts);
  47. if (e == 0)
  48. {
  49. puts ("second cond_timedwait did not fail");
  50. result = 1;
  51. }
  52. else if (e != EINVAL)
  53. {
  54. puts ("second cond_timedwait did not return EINVAL");
  55. result = 1;
  56. }
  57. return result;
  58. }
  59. #define TEST_FUNCTION do_test ()
  60. #include "../test-skeleton.c"