1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2021, BELLSOFT. All rights reserved.
4 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
5 * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Checks functionality for sched_setparam(2) for pid != 0
12 *
13 * This test forks a child and changes its parent's scheduling priority.
14 */
15
16 #include <stdlib.h>
17
18 #include "tst_test.h"
19 #include "tst_sched.h"
20
run(void)21 static void run(void)
22 {
23 struct sched_variant *tv = &sched_variants[tst_variant];
24 struct sched_param p5 = { .sched_priority = 5 };
25 struct sched_param p;
26 pid_t child_pid;
27
28 child_pid = SAFE_FORK();
29
30 if (!child_pid) {
31 TST_EXP_PASS_SILENT(tv->sched_setparam(getppid(), &p5));
32 exit(0);
33 }
34 tst_reap_children();
35
36 TST_EXP_PASS_SILENT(tv->sched_getparam(0, &p));
37
38 if (p.sched_priority == p5.sched_priority)
39 tst_res(TPASS, "got expected priority %d", p.sched_priority);
40 else
41 tst_res(TFAIL, "got priority %d, expected 5", p.sched_priority);
42 }
43
setup(void)44 void setup(void)
45 {
46 struct sched_variant *tv = &sched_variants[tst_variant];
47 struct sched_param p = { .sched_priority = 1 };
48
49 tst_res(TINFO, "Testing %s variant", tv->desc);
50
51 if (tv->sched_setscheduler(0, SCHED_FIFO, &p))
52 tst_brk(TBROK | TERRNO, "sched_setcheduler(0, SCHED_FIFO, 1)");
53 }
54
55 static struct tst_test test = {
56 .forks_child = 1,
57 .needs_root = 1,
58 .setup = setup,
59 .test_variants = ARRAY_SIZE(sched_variants),
60 .test_all = run,
61 };
62