1 /* Test unsupported/bad clocks passed to sem_clockwait.
2 
3    Copyright (C) 2019-2022 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5 
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10 
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15 
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <https://www.gnu.org/licenses/>.  */
19 
20 #include <errno.h>
21 #include <semaphore.h>
22 #include <stdio.h>
23 #include <time.h>
24 #include <unistd.h>
25 #include <sys/time.h>
26 #include <support/check.h>
27 #include <support/timespec.h>
28 
29 
30 #define NOT_A_VALID_CLOCK 123456
31 
32 static int
do_test(void)33 do_test (void)
34 {
35   sem_t s;
36   TEST_COMPARE (sem_init (&s, 0, 1), 0);
37 
38   const struct timespec ts = make_timespec (0, 0);
39 
40   /* These clocks are meaningless to sem_clockwait.  */
41 #if defined(CLOCK_PROCESS_CPUTIME_ID)
42   TEST_COMPARE (sem_clockwait (&s, CLOCK_PROCESS_CPUTIME_ID, &ts), -1);
43   TEST_COMPARE (errno, EINVAL);
44 #endif
45 #if defined(CLOCK_THREAD_CPUTIME_ID)
46   TEST_COMPARE (sem_clockwait (&s, CLOCK_THREAD_CPUTIME_ID, &ts), -1);
47   TEST_COMPARE (errno, EINVAL);
48 #endif
49 
50   /* These clocks might be meaningful, but are currently unsupported
51      by pthread_cond_clockwait.  */
52 #if defined(CLOCK_REALTIME_COARSE)
53   TEST_COMPARE (sem_clockwait (&s, CLOCK_REALTIME_COARSE, &ts), -1);
54   TEST_COMPARE (errno, EINVAL);
55 #endif
56 #if defined(CLOCK_MONOTONIC_RAW)
57   TEST_COMPARE (sem_clockwait (&s, CLOCK_MONOTONIC_RAW, &ts), -1);
58   TEST_COMPARE (errno, EINVAL);
59 #endif
60 #if defined(CLOCK_MONOTONIC_COARSE)
61   TEST_COMPARE (sem_clockwait (&s, CLOCK_MONOTONIC_COARSE, &ts), -1);
62   TEST_COMPARE (errno, EINVAL);
63 #endif
64 #if defined(CLOCK_BOOTTIME)
65   TEST_COMPARE (sem_clockwait (&s, CLOCK_BOOTTIME, &ts), -1);
66   TEST_COMPARE (errno, EINVAL);
67 #endif
68 
69   /* This is a completely invalid clock.  */
70   TEST_COMPARE (sem_clockwait (&s, NOT_A_VALID_CLOCK, &ts), -1);
71   TEST_COMPARE (errno, EINVAL);
72 
73   return 0;
74 }
75 
76 #include <support/test-driver.c>
77