tst-cond19.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <pthread.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  21. static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
  22. static int
  23. do_test (void)
  24. {
  25. int result = 0;
  26. struct timespec ts;
  27. if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
  28. {
  29. puts ("clock_gettime failed");
  30. return 1;
  31. }
  32. ts.tv_nsec = -1;
  33. int e = pthread_cond_timedwait (&cond, &mut, &ts);
  34. if (e == 0)
  35. {
  36. puts ("first cond_timedwait did not fail");
  37. result = 1;
  38. }
  39. else if (e != EINVAL)
  40. {
  41. puts ("first cond_timedwait did not return EINVAL");
  42. result = 1;
  43. }
  44. ts.tv_nsec = 2000000000;
  45. e = pthread_cond_timedwait (&cond, &mut, &ts);
  46. if (e == 0)
  47. {
  48. puts ("second cond_timedwait did not fail");
  49. result = 1;
  50. }
  51. else if (e != EINVAL)
  52. {
  53. puts ("second cond_timedwait did not return EINVAL");
  54. result = 1;
  55. }
  56. return result;
  57. }
  58. #define TEST_FUNCTION do_test ()
  59. #include "../test-skeleton.c"