• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) M. Koehrer <mathias_koehrer@arcor.de>, 2009                  *
3  * Copyright (C) 2017 Cyril Hrubis <chrubis@suse.cz>                          *
4  *                                                                            *
5  * This program is free software;  you can redistribute it and/or modify      *
6  * it under the terms of the GNU General Public License as published by       *
7  * the Free Software Foundation; either version 2 of the License, or          *
8  * (at your option) any later version.                                        *
9  *                                                                            *
10  * This program 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                  *
13  * the GNU General Public License for more details.                           *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program;  if not, write to the Free Software Foundation,   *
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           *
18  *                                                                            *
19  ******************************************************************************/
20 /*
21  * This tests the clock_nanosleep2() syscall.
22  */
23 #include <stdio.h>
24 #include <time.h>
25 #include <unistd.h>
26 #include <sys/syscall.h>
27 
28 #include "tst_test.h"
29 #include "linux_syscall_numbers.h"
30 
31 #define NSEC_IN_SEC 1000000000
32 
33 const clockid_t CLOCK_TO_USE = CLOCK_MONOTONIC;
clock_nanosleep2(clockid_t clock_id,int flags,const struct timespec * req,struct timespec * rem)34 static int clock_nanosleep2(clockid_t clock_id, int flags,
35 			    const struct timespec *req, struct timespec *rem)
36 {
37 	return tst_syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
38 }
39 
verify_clock_nanosleep2(void)40 static void verify_clock_nanosleep2(void)
41 {
42 	struct timespec ts;
43 
44 	clock_gettime(CLOCK_TO_USE, &ts);
45 	ts.tv_nsec += NSEC_IN_SEC/10;
46 	if (ts.tv_nsec >= NSEC_IN_SEC) {
47 		ts.tv_sec += 1;
48 		ts.tv_nsec %= NSEC_IN_SEC;
49 	}
50 
51 	TEST(clock_nanosleep2(CLOCK_TO_USE, TIMER_ABSTIME, &ts, NULL));
52 
53 	if (TEST_RETURN)
54 		tst_res(TFAIL | TTERRNO, "clock_nanosleep2() failed");
55 	else
56 		tst_res(TPASS, "clock_nanosleep2() passed");
57 }
58 
59 static struct tst_test test = {
60 	.tid = "clock_nanosleep2_01",
61 	.test_all = verify_clock_nanosleep2,
62 };
63