1 /* Copyright (C) 2004-2022 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
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 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 #include <errno.h>
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <time.h>
23 
24 
25 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
26 static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
27 
28 
29 static int
do_test(void)30 do_test (void)
31 {
32   int result = 0;
33   struct timespec ts;
34 
35   if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
36     {
37       puts ("clock_gettime failed");
38       return 1;
39     }
40 
41   ts.tv_nsec = -1;
42 
43   int e = pthread_cond_timedwait (&cond, &mut, &ts);
44   if (e == 0)
45     {
46       puts ("first cond_timedwait did not fail");
47       result = 1;
48     }
49   else if (e != EINVAL)
50     {
51       puts ("first cond_timedwait did not return EINVAL");
52       result = 1;
53     }
54 
55   ts.tv_nsec = 2000000000;
56 
57   e = pthread_cond_timedwait (&cond, &mut, &ts);
58   if (e == 0)
59     {
60       puts ("second cond_timedwait did not fail");
61       result = 1;
62     }
63   else if (e != EINVAL)
64     {
65       puts ("second cond_timedwait did not return EINVAL");
66       result = 1;
67     }
68 
69   return result;
70 }
71 
72 
73 #define TEST_FUNCTION do_test ()
74 #include "../test-skeleton.c"
75