1 /* Test for clock_adjtime
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <support/check.h>
23 #include <support/timespec.h>
26 # define ADJTIME_CALL(__clock, __timex) clock_adjtime (__clock, __timex)
32 struct timespec tv_then
, tv_now
;
35 /* Check if altering target time is allowed. */
36 if (getenv (SETTIME_ENV_NAME
) == NULL
)
37 FAIL_UNSUPPORTED ("clock_adjtime is executed only when "\
38 SETTIME_ENV_NAME
" is set\n");
40 tv_then
= xclock_now (CLOCK_REALTIME
);
42 /* Setup time value to adjust - 1 sec. */
43 delta
.time
.tv_sec
= 1;
44 delta
.time
.tv_usec
= 0;
45 delta
.modes
= ADJ_SETOFFSET
;
47 int ret
= ADJTIME_CALL (CLOCK_REALTIME
, &delta
);
49 FAIL_EXIT1 ("clock_adjtime failed: %m\n");
51 tv_now
= xclock_now (CLOCK_REALTIME
);
53 /* Check if clock_adjtime adjusted the system time. */
54 struct timespec r
= timespec_sub (tv_now
, tv_then
);
55 TEST_COMPARE (support_timespec_check_in_range
56 ((struct timespec
) { 1, 0 }, r
, 0.9, 1.1), 1);
61 #include <support/test-driver.c>