]>
Commit | Line | Data |
---|---|---|
afe4de7d MC |
1 | /* Test unsupported/bad clocks passed to pthread_cond_clockwait. |
2 | ||
dff8da6b | 3 | Copyright (C) 2019-2024 Free Software Foundation, Inc. |
afe4de7d MC |
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 | |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
afe4de7d MC |
19 | |
20 | #include <errno.h> | |
21 | #include <pthread.h> | |
22 | #include <stdio.h> | |
23 | #include <time.h> | |
24 | #include <unistd.h> | |
25 | #include <support/check.h> | |
26 | #include <support/timespec.h> | |
27 | #include <support/xthread.h> | |
28 | ||
29 | static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; | |
30 | static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; | |
31 | ||
32 | #define NOT_A_VALID_CLOCK 123456 | |
33 | ||
34 | static int | |
35 | do_test (void) | |
36 | { | |
37 | xpthread_mutex_lock (&mut); | |
38 | ||
39 | const struct timespec ts = make_timespec (0, 0); | |
40 | ||
41 | /* These clocks are meaningless to sem_clockwait. */ | |
42 | #if defined(CLOCK_PROCESS_CPUTIME_ID) | |
43 | TEST_COMPARE (pthread_cond_clockwait (&cond, &mut, | |
44 | CLOCK_PROCESS_CPUTIME_ID, &ts), EINVAL); | |
45 | #endif | |
46 | #if defined(CLOCK_THREAD_CPUTIME_ID) | |
47 | TEST_COMPARE (pthread_cond_clockwait (&cond, &mut, | |
48 | CLOCK_THREAD_CPUTIME_ID, &ts), EINVAL); | |
49 | #endif | |
50 | ||
51 | /* These clocks might be meaningful, but are currently unsupported | |
52 | by pthread_cond_clockwait. */ | |
53 | #if defined(CLOCK_REALTIME_COARSE) | |
54 | TEST_COMPARE (pthread_cond_clockwait (&cond, &mut, | |
55 | CLOCK_REALTIME_COARSE, &ts), EINVAL); | |
56 | #endif | |
57 | #if defined(CLOCK_MONOTONIC_RAW) | |
58 | TEST_COMPARE (pthread_cond_clockwait (&cond, &mut, | |
59 | CLOCK_MONOTONIC_RAW, &ts), EINVAL); | |
60 | #endif | |
61 | #if defined(CLOCK_MONOTONIC_COARSE) | |
62 | TEST_COMPARE (pthread_cond_clockwait (&cond, &mut, | |
63 | CLOCK_MONOTONIC_COARSE, &ts), EINVAL); | |
64 | #endif | |
65 | #if defined(CLOCK_BOOTTIME) | |
66 | TEST_COMPARE (pthread_cond_clockwait (&cond, &mut, | |
67 | CLOCK_BOOTTIME, &ts), EINVAL); | |
68 | #endif | |
69 | ||
70 | /* This is a completely invalid clock. */ | |
71 | TEST_COMPARE (pthread_cond_clockwait (&cond, &mut, | |
72 | NOT_A_VALID_CLOCK, &ts), EINVAL); | |
73 | ||
74 | return 0; | |
75 | } | |
76 | ||
77 | #include <support/test-driver.c> |