aboutsummaryrefslogtreecommitdiff
path: root/testcases/kernel/syscalls/sched_setparam/sched_setparam03.c
blob: ffa92a3bf9eb39dbb5d7cfe253dea39a62832d36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2021, BELLSOFT. All rights reserved.
 * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
 * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
 */

/*\
 * [Description]
 *
 * Checks functionality for sched_setparam(2) for pid != 0
 *
 * This test forks a child and changes its parent's scheduling priority.
 */

#include <stdlib.h>

#include "tst_test.h"
#include "tst_sched.h"

static void run(void)
{
	struct sched_variant *tv = &sched_variants[tst_variant];
	struct sched_param p5 = { .sched_priority = 5 };
	struct sched_param p;
	pid_t child_pid;

	child_pid = SAFE_FORK();

	if (!child_pid) {
		TST_EXP_PASS_SILENT(tv->sched_setparam(getppid(), &p5));
		exit(0);
	}
	tst_reap_children();

	TST_EXP_PASS_SILENT(tv->sched_getparam(0, &p));

	if (p.sched_priority == p5.sched_priority)
		tst_res(TPASS, "got expected priority %d", p.sched_priority);
	else
		tst_res(TFAIL, "got priority %d, expected 5", p.sched_priority);
}

void setup(void)
{
	struct sched_variant *tv = &sched_variants[tst_variant];
	struct sched_param p = { .sched_priority = 1 };

	tst_res(TINFO, "Testing %s variant", tv->desc);

	if (tv->sched_setscheduler(0, SCHED_FIFO, &p))
		tst_brk(TBROK | TERRNO, "sched_setscheduler(0, SCHED_FIFO, 1)");
}

static struct tst_test test = {
	.forks_child = 1,
	.needs_root = 1,
	.setup = setup,
	.test_variants = ARRAY_SIZE(sched_variants),
	.test_all = run,
};