xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/prctl/prctl09.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) 2019 FUJITSU LIMITED. All rights reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Author: Yang Xu <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  * This is a timer sample test that timer slack is 200us.
11*49cdfc7eSAndroid Build Coastguard Worker  */
12*49cdfc7eSAndroid Build Coastguard Worker 
13*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include <sys/prctl.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/prctl.h"
16*49cdfc7eSAndroid Build Coastguard Worker #include "tst_timer_test.h"
17*49cdfc7eSAndroid Build Coastguard Worker 
sample_fn(int clk_id,long long usec)18*49cdfc7eSAndroid Build Coastguard Worker static int sample_fn(int clk_id, long long usec)
19*49cdfc7eSAndroid Build Coastguard Worker {
20*49cdfc7eSAndroid Build Coastguard Worker 	struct timespec t = tst_timespec_from_us(usec);
21*49cdfc7eSAndroid Build Coastguard Worker 
22*49cdfc7eSAndroid Build Coastguard Worker 	tst_timer_start(clk_id);
23*49cdfc7eSAndroid Build Coastguard Worker 	TEST(nanosleep(&t, NULL));
24*49cdfc7eSAndroid Build Coastguard Worker 	tst_timer_stop();
25*49cdfc7eSAndroid Build Coastguard Worker 	tst_timer_sample();
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET != 0) {
28*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL | TTERRNO,
29*49cdfc7eSAndroid Build Coastguard Worker 			"nanosleep() returned %li", TST_RET);
30*49cdfc7eSAndroid Build Coastguard Worker 		return 1;
31*49cdfc7eSAndroid Build Coastguard Worker 	}
32*49cdfc7eSAndroid Build Coastguard Worker 
33*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
34*49cdfc7eSAndroid Build Coastguard Worker }
35*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)36*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
37*49cdfc7eSAndroid Build Coastguard Worker {
38*49cdfc7eSAndroid Build Coastguard Worker 	TEST(prctl(PR_SET_TIMERSLACK, 200000));
39*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET != 0)
40*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK | TTERRNO,
41*49cdfc7eSAndroid Build Coastguard Worker 			"prctl set timerslack 200us failed");
42*49cdfc7eSAndroid Build Coastguard Worker }
43*49cdfc7eSAndroid Build Coastguard Worker 
44*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
45*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
46*49cdfc7eSAndroid Build Coastguard Worker 	.scall = "prctl()",
47*49cdfc7eSAndroid Build Coastguard Worker 	.sample = sample_fn,
48*49cdfc7eSAndroid Build Coastguard Worker };
49