• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
4  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
5  */
6 
7 /*
8  * Test Description:
9  *  This is a timer sample test that timer slack is 200us.
10  */
11 
12 #include <errno.h>
13 #include <sys/prctl.h>
14 #include "lapi/prctl.h"
15 #include "tst_timer_test.h"
16 
sample_fn(int clk_id,long long usec)17 int sample_fn(int clk_id, long long usec)
18 {
19 	struct timespec t = tst_timespec_from_us(usec);
20 
21 	tst_timer_start(clk_id);
22 	TEST(nanosleep(&t, NULL));
23 	tst_timer_stop();
24 	tst_timer_sample();
25 
26 	if (TST_RET != 0) {
27 		tst_res(TFAIL | TTERRNO,
28 			"nanosleep() returned %li", TST_RET);
29 		return 1;
30 	}
31 
32 	return 0;
33 }
34 
setup(void)35 static void setup(void)
36 {
37 	TEST(prctl(PR_SET_TIMERSLACK, 200000));
38 	if (TST_RET != 0)
39 		tst_brk(TBROK | TTERRNO,
40 			"prctl set timerslack 200us failed");
41 }
42 
43 static struct tst_test test = {
44 	.setup = setup,
45 	.scall = "prctl()",
46 	.sample = sample_fn,
47 };
48