xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/nanosleep/nanosleep01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  *  07/2001 Ported by Wayne Boyer
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (C) 2015-2017 Cyril Hrubis <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker /*
9*49cdfc7eSAndroid Build Coastguard Worker  * Test Description:
10*49cdfc7eSAndroid Build Coastguard Worker  *  nanosleep() should return with value 0 and the process should be
11*49cdfc7eSAndroid Build Coastguard Worker  *  suspended for time specified by timespec structure.
12*49cdfc7eSAndroid Build Coastguard Worker  */
13*49cdfc7eSAndroid Build Coastguard Worker 
14*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include "tst_timer_test.h"
16*49cdfc7eSAndroid Build Coastguard Worker 
sample_fn(int clk_id,long long usec)17*49cdfc7eSAndroid Build Coastguard Worker int sample_fn(int clk_id, long long usec)
18*49cdfc7eSAndroid Build Coastguard Worker {
19*49cdfc7eSAndroid Build Coastguard Worker 	struct timespec t = tst_timespec_from_us(usec);
20*49cdfc7eSAndroid Build Coastguard Worker 
21*49cdfc7eSAndroid Build Coastguard Worker 	tst_timer_start(clk_id);
22*49cdfc7eSAndroid Build Coastguard Worker 	TEST(nanosleep(&t, NULL));
23*49cdfc7eSAndroid Build Coastguard Worker 	tst_timer_stop();
24*49cdfc7eSAndroid Build Coastguard Worker 	tst_timer_sample();
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET != 0) {
27*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL | TTERRNO,
28*49cdfc7eSAndroid Build Coastguard Worker 			"nanosleep() returned %li", TST_RET);
29*49cdfc7eSAndroid Build Coastguard Worker 		return 1;
30*49cdfc7eSAndroid Build Coastguard Worker 	}
31*49cdfc7eSAndroid Build Coastguard Worker 
32*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
33*49cdfc7eSAndroid Build Coastguard Worker }
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
36*49cdfc7eSAndroid Build Coastguard Worker 	.scall = "nanosleep()",
37*49cdfc7eSAndroid Build Coastguard Worker 	.sample = sample_fn,
38*49cdfc7eSAndroid Build Coastguard Worker };
39