1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 * AUTHOR : Saji Kumar.V.R <[email protected]>
5 */
6 /*\
7 * [Description]
8 *
9 * Verify that for a process with scheduling policy SCHED_FIFO,
10 * sched_rr_get_interval() writes zero into timespec structure
11 * for tv_sec & tv_nsec.
12 */
13
14 #include "time64_variants.h"
15 #include "tst_timer.h"
16 #include "tst_sched.h"
17
18 static struct tst_ts tp;
19
20 static struct time64_variants variants[] = {
21 { .sched_rr_get_interval = libc_sched_rr_get_interval, .ts_type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
22
23 #if (__NR_sched_rr_get_interval != __LTP__NR_INVALID_SYSCALL)
24 { .sched_rr_get_interval = sys_sched_rr_get_interval, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
25 #endif
26
27 #if (__NR_sched_rr_get_interval_time64 != __LTP__NR_INVALID_SYSCALL)
28 { .sched_rr_get_interval = sys_sched_rr_get_interval64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
29 #endif
30 };
31
setup(void)32 static void setup(void)
33 {
34 struct time64_variants *tv = &variants[tst_variant];
35 struct sched_param p = { 1 };
36
37 tst_res(TINFO, "Testing variant: %s", tv->desc);
38
39 tp.type = tv->ts_type;
40
41 if ((sys_sched_setscheduler(0, SCHED_FIFO, &p)) == -1)
42 tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
43 }
44
run(void)45 static void run(void)
46 {
47 struct time64_variants *tv = &variants[tst_variant];
48
49 tst_ts_set_sec(&tp, 99);
50 tst_ts_set_nsec(&tp, 99);
51
52 TEST(tv->sched_rr_get_interval(0, tst_ts_get(&tp)));
53
54 if (!TST_RET && tst_ts_valid(&tp) == -1) {
55 tst_res(TPASS, "sched_rr_get_interval() passed");
56 } else {
57 tst_res(TFAIL | TTERRNO,
58 "sched_rr_get_interval() returned %ld, tp.tv_sec = %lld, tp.tv_nsec = %lld",
59 TST_RET, tst_ts_get_sec(tp), tst_ts_get_nsec(tp));
60 }
61 }
62
63 static struct tst_test test = {
64 .test_all = run,
65 .test_variants = ARRAY_SIZE(variants),
66 .setup = setup,
67 .needs_root = 1,
68 };
69