1/* Test unsupported/bad clocks passed to pthread_mutex_clocklock.
2
3 Copyright (C) 2019-2024 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 <pthread.h>
22#include <stdio.h>
23#include <time.h>
24#include <unistd.h>
25#include <support/check.h>
26
27static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
28
29static void test_bad_clockid (clockid_t clockid)
30{
31 const struct timespec ts = {0,0};
32 TEST_COMPARE (pthread_mutex_clocklock (&mut, clockid, &ts), EINVAL);
33}
34
35#define NOT_A_VALID_CLOCK 123456
36
37static int
38do_test (void)
39{
40 /* These clocks are meaningless to pthread_mutex_clocklock. */
41#if defined(CLOCK_PROCESS_CPUTIME_ID)
42 test_bad_clockid (CLOCK_PROCESS_CPUTIME_ID);
43#endif
44#if defined(CLOCK_THREAD_CPUTIME_ID)
45 test_bad_clockid (CLOCK_PROCESS_CPUTIME_ID);
46#endif
47
48 /* These clocks might be meaningful, but are currently unsupported by
49 pthread_mutex_clocklock. */
50#if defined(CLOCK_REALTIME_COARSE)
51 test_bad_clockid (CLOCK_REALTIME_COARSE);
52#endif
53#if defined(CLOCK_MONOTONIC_RAW)
54 test_bad_clockid (CLOCK_MONOTONIC_RAW);
55#endif
56#if defined(CLOCK_MONOTONIC_COARSE)
57 test_bad_clockid (CLOCK_MONOTONIC_COARSE);
58#endif
59#if defined(CLOCK_BOOTTIME)
60 test_bad_clockid (CLOCK_BOOTTIME);
61#endif
62
63 /* This is a completely invalid clock. */
64 test_bad_clockid (NOT_A_VALID_CLOCK);
65
66 return 0;
67}
68
69#include <support/test-driver.c>
70

source code of glibc/sysdeps/pthread/tst-mutex11.c