1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 */
5
6 /*\
7 * [Description]
8 *
9 * Verify that:
10 *
11 * sched_getparam(2) gets correct scheduling parameters for
12 * the specified process:
13 *
14 * - If pid is zero, sched_getparam(2) gets the scheduling parameters
15 * for the calling process.
16 * - If pid is not zero, sched_getparam(2) gets the scheduling
17 * parameters for the specified [pid] process.
18 */
19
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include "tst_test.h"
25 #include "tst_sched.h"
26
27 static pid_t pids[2] = {0, 0};
28
verify_sched_getparam(unsigned int n)29 static void verify_sched_getparam(unsigned int n)
30 {
31 pid_t child_pid;
32 struct sched_variant *tv = &sched_variants[tst_variant];
33 struct sched_param param = {
34 .sched_priority = 100,
35 };
36
37 child_pid = SAFE_FORK();
38 if (!child_pid) {
39 TST_EXP_PASS_SILENT(tv->sched_getparam(pids[n], ¶m),
40 "sched_getparam(%d)", pids[n]);
41 if (!TST_PASS)
42 exit(0);
43
44 /*
45 * For normal process, scheduling policy is SCHED_OTHER.
46 * For this scheduling policy, only allowed priority value is 0.
47 */
48 if (param.sched_priority)
49 tst_res(TFAIL,
50 "sched_getparam(%d) got wrong sched_priority %d, expected 0",
51 pids[n], param.sched_priority);
52 else
53 tst_res(TPASS, "sched_getparam(%d) got expected sched_priority 0", pids[n]);
54
55 exit(0);
56 }
57
58 tst_reap_children();
59 }
60
setup(void)61 static void setup(void)
62 {
63 struct sched_variant *tv = &sched_variants[tst_variant];
64
65 tst_res(TINFO, "Testing %s variant", tv->desc);
66
67 pids[1] = getpid();
68 }
69
70 static struct tst_test test = {
71 .forks_child = 1,
72 .setup = setup,
73 .test_variants = ARRAY_SIZE(sched_variants),
74 .tcnt = ARRAY_SIZE(pids),
75 .test = verify_sched_getparam,
76 };
77