• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
12  *
13  * This test changes the scheduling priority for current process
14  * and verifies it by calling sched_getparam().
15  */
16 
17 #include "tst_test.h"
18 #include "tst_sched.h"
19 
20 #define FIFO_OR_RR_PRIO 5
21 #define OTHER_PRIO 0
22 
23 static struct test_cases_t {
24 	char *desc;
25 	int policy;
26 	int priority;
27 	int param;
28 } tcases[] = {
29 	{
30 	"Test with policy SCHED_FIFO", SCHED_FIFO, FIFO_OR_RR_PRIO, 1}, {
31 	"Test with policy SCHED_RR", SCHED_RR, FIFO_OR_RR_PRIO, 1}, {
32 	"Test with SCHED_OTHER", SCHED_OTHER, OTHER_PRIO, 0}
33 };
34 
run(unsigned int n)35 static void run(unsigned int n)
36 {
37 	struct test_cases_t *tc = &tcases[n];
38 	struct sched_variant *tv = &sched_variants[tst_variant];
39 	struct sched_param p = { .sched_priority = tc->param };
40 
41 	TST_EXP_PASS_SILENT(tv->sched_setscheduler(0, tc->policy, &p));
42 
43 	p.sched_priority = tc->priority;
44 	TST_EXP_PASS_SILENT(tv->sched_setparam(0, &p));
45 
46 	p.sched_priority = -1;
47 	TST_EXP_PASS_SILENT(tv->sched_getparam(0, &p));
48 
49 	if (p.sched_priority == tc->priority) {
50 		tst_res(TPASS, "got expected priority %d", p.sched_priority);
51 	} else {
52 		tst_res(TFAIL, "unexpected priority value %d, expected %d",
53 			p.sched_priority, tc->priority);
54 	}
55 }
56 
setup(void)57 static void setup(void)
58 {
59 	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
60 }
61 
62 static struct tst_test test = {
63 	.needs_root = 1,
64 	.setup = setup,
65 	.test = run,
66 	.test_variants = ARRAY_SIZE(sched_variants),
67 	.tcnt = ARRAY_SIZE(tcases),
68 };
69