diff options
author | Lukasz Majewski <lukma@denx.de> | 2021-01-18 16:53:26 +0100 |
---|---|---|
committer | Lukasz Majewski <lukma@denx.de> | 2021-03-08 22:41:28 +0100 |
commit | a1565550075255370f8e6c88dc9c4ad3fd7281ab (patch) | |
tree | e9e1f2ce1d50cca15135faea0aa9a7f20fc7e33a /support/xclock_settime.c | |
parent | 496e36f2251f28961ce269548b5f3adb6546ef01 (diff) | |
download | glibc-a1565550075255370f8e6c88dc9c4ad3fd7281ab.zip glibc-a1565550075255370f8e6c88dc9c4ad3fd7281ab.tar.gz glibc-a1565550075255370f8e6c88dc9c4ad3fd7281ab.tar.bz2 |
support: Provide xclock_settime test helper function
The xclock_settime is a wrapper function on the clock_settime syscall
to be used in the test code.
It checks if the GLIBC_TEST_ALLOW_TIME_SETTING env variable is defined
in the environment in which test is executed. If it is not - the test
ends as unsupported. Otherwise, the clock-settime is executed and return
value is assessed.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'support/xclock_settime.c')
-rw-r--r-- | support/xclock_settime.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/support/xclock_settime.c b/support/xclock_settime.c new file mode 100644 index 0000000..25e717d --- /dev/null +++ b/support/xclock_settime.c @@ -0,0 +1,34 @@ +/* clock_settime with error checking. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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. + + 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. + + 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 <stdlib.h> +#include <support/check.h> +#include <support/xtime.h> + +void +xclock_settime (clockid_t clockid, + const struct timespec *ts) +{ + if (getenv (SETTIME_ENV_NAME) == NULL) + FAIL_UNSUPPORTED ("clock_settime is executed only when "\ + SETTIME_ENV_NAME" is set\n"); + + int ret = clock_settime (clockid, ts); + if (ret < 0) + FAIL_EXIT1 ("clock_settime (%d): %m", clockid); +} |