2023-06-02 17:02:09 +00:00
|
|
|
/* Test setting the monotonic clock.
|
2024-01-01 18:12:26 +00:00
|
|
|
Copyright (C) 2007-2024 Free Software Foundation, Inc.
|
2023-06-02 17:02:09 +00:00
|
|
|
This file is part of the GNU C Library.
|
2006-08-03 08:17:20 +00:00
|
|
|
|
2023-06-02 17:02:09 +00:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2006-08-03 08:17:20 +00:00
|
|
|
|
2023-06-02 17:02:09 +00:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2006-08-03 08:17:20 +00:00
|
|
|
|
2023-06-02 17:02:09 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <support/check.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2006-08-03 08:17:20 +00:00
|
|
|
|
2023-06-02 17:02:09 +00:00
|
|
|
int
|
2006-08-03 08:17:20 +00:00
|
|
|
do_test (void)
|
|
|
|
{
|
2023-06-02 17:02:09 +00:00
|
|
|
#if defined CLOCK_MONOTONIC && defined _POSIX_MONOTONIC_CLOCK
|
2006-08-03 08:17:20 +00:00
|
|
|
if (sysconf (_SC_MONOTONIC_CLOCK) <= 0)
|
2023-06-02 17:02:09 +00:00
|
|
|
FAIL_UNSUPPORTED ("_SC_MONOTONIC_CLOCK not supported");
|
2006-08-03 08:17:20 +00:00
|
|
|
|
|
|
|
struct timespec ts;
|
2023-06-02 17:02:09 +00:00
|
|
|
TEST_COMPARE (clock_gettime (CLOCK_MONOTONIC, &ts), 0);
|
2006-08-03 08:17:20 +00:00
|
|
|
|
|
|
|
/* Setting the monotonic clock must fail. */
|
2023-06-02 17:02:09 +00:00
|
|
|
TEST_VERIFY (clock_settime (CLOCK_MONOTONIC, &ts) == -1);
|
|
|
|
TEST_VERIFY (errno == EINVAL || errno == EPERM);
|
2006-08-03 08:17:20 +00:00
|
|
|
|
2023-06-02 17:02:09 +00:00
|
|
|
return 0;
|
2006-08-03 08:17:20 +00:00
|
|
|
#else
|
2023-06-02 17:02:09 +00:00
|
|
|
return EXIT_UNSUPPORTED;
|
2006-08-03 08:17:20 +00:00
|
|
|
#endif
|
2023-06-02 17:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <support/test-driver.c>
|