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