1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) M. Koehrer <mathias_koehrer@arcor.de>, 2009
4 * Copyright (C) 2017 Cyril Hrubis <chrubis@suse.cz>
5 */
6
7 #include <stdio.h>
8 #include <time.h>
9 #include <unistd.h>
10 #include <sys/syscall.h>
11
12 #include "tst_test.h"
13 #include "lapi/syscalls.h"
14
15 #define NSEC_IN_SEC 1000000000
16
17 const clockid_t CLOCK_TO_USE = CLOCK_MONOTONIC;
clock_nanosleep2(clockid_t clock_id,int flags,const struct timespec * req,struct timespec * rem)18 static int clock_nanosleep2(clockid_t clock_id, int flags,
19 const struct timespec *req, struct timespec *rem)
20 {
21 return tst_syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
22 }
23
verify_clock_nanosleep2(void)24 static void verify_clock_nanosleep2(void)
25 {
26 struct timespec ts;
27
28 clock_gettime(CLOCK_TO_USE, &ts);
29 ts.tv_nsec += NSEC_IN_SEC/10;
30 if (ts.tv_nsec >= NSEC_IN_SEC) {
31 ts.tv_sec += 1;
32 ts.tv_nsec %= NSEC_IN_SEC;
33 }
34
35 TEST(clock_nanosleep2(CLOCK_TO_USE, TIMER_ABSTIME, &ts, NULL));
36
37 if (TST_RET)
38 tst_res(TFAIL | TTERRNO, "clock_nanosleep2() failed");
39 else
40 tst_res(TPASS, "clock_nanosleep2() passed");
41 }
42
43 static struct tst_test test = {
44 .test_all = verify_clock_nanosleep2,
45 };
46