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:
10 *
11 * - sched_rr_get_interval() fails with errno set to EINVAL for an
12 * invalid pid
13 *
14 * - sched_rr_get_interval() fails with errno set to ESRCH if the
15 * process with specified pid does not exists
16 *
17 * - sched_rr_get_interval() fails with errno set to EFAULT if the
18 * address specified as &tp is invalid
19 */
20
21 #include "time64_variants.h"
22 #include "tst_timer.h"
23 #include "tst_sched.h"
24
25 static pid_t unused_pid;
26 static pid_t inval_pid = -1;
27 static pid_t zero_pid;
28
29 static struct tst_ts tp;
30 static void *bad_addr;
31
32 struct test_cases_t {
33 pid_t *pid;
34 struct tst_ts *tp;
35 int exp_errno;
36 } test_cases[] = {
37 { &inval_pid, &tp, EINVAL},
38 { &unused_pid, &tp, ESRCH},
39 { &zero_pid, NULL, EFAULT}
40 };
41
42 static struct time64_variants variants[] = {
43 { .sched_rr_get_interval = libc_sched_rr_get_interval, .ts_type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
44
45 #if (__NR_sched_rr_get_interval != __LTP__NR_INVALID_SYSCALL)
46 { .sched_rr_get_interval = sys_sched_rr_get_interval, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
47 #endif
48
49 #if (__NR_sched_rr_get_interval_time64 != __LTP__NR_INVALID_SYSCALL)
50 { .sched_rr_get_interval = sys_sched_rr_get_interval64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
51 #endif
52 };
53
setup(void)54 static void setup(void)
55 {
56 struct time64_variants *tv = &variants[tst_variant];
57 struct sched_param p = { 1 };
58
59 tst_res(TINFO, "Testing variant: %s", tv->desc);
60
61 bad_addr = tst_get_bad_addr(NULL);
62 tp.type = tv->ts_type;
63
64 if ((sys_sched_setscheduler(0, SCHED_RR, &p)) == -1)
65 tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
66
67 unused_pid = tst_get_unused_pid();
68 }
69
run(unsigned int i)70 static void run(unsigned int i)
71 {
72 struct time64_variants *tv = &variants[tst_variant];
73 struct test_cases_t *tc = &test_cases[i];
74 struct timerspec *ts;
75
76 if (tc->exp_errno == EFAULT
77 && tv->sched_rr_get_interval == libc_sched_rr_get_interval) {
78 tst_res(TCONF, "EFAULT skipped for libc_variant");
79 return;
80 }
81
82 if (tc->exp_errno == EFAULT)
83 ts = bad_addr;
84 else
85 ts = tst_ts_get(tc->tp);
86
87 TST_EXP_FAIL(tv->sched_rr_get_interval(*tc->pid, ts), tc->exp_errno,
88 "sched_rr_get_interval(%i, %p)", *tc->pid, ts);
89 }
90
91 static struct tst_test test = {
92 .test = run,
93 .tcnt = ARRAY_SIZE(test_cases),
94 .test_variants = ARRAY_SIZE(variants),
95 .setup = setup,
96 .needs_root = 1,
97 };
98