• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2021, BELLSOFT. All rights reserved.
4  * Copyright (c) International Business Machines  Corp., 2001
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Testcase to check sched_getscheduler() returns correct return value.
11  *
12  * [Algorithm]
13  *
14  * Call sched_setcheduler() to set the scheduling policy of the current
15  * process. Then call sched_getscheduler() to ensure that this is same
16  * as what set by the previous call to sched_setscheduler().
17  *
18  * Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for
19  * sched_setscheduler().
20  *
21  */
22 
23 #include <errno.h>
24 #include <stdio.h>
25 
26 #include "tst_test.h"
27 #include "tst_sched.h"
28 
29 struct test_cases_t {
30 	int priority;
31 	int policy;
32 } tcases[] = {
33 	{1, SCHED_RR},
34 	{0, SCHED_OTHER},
35 	{1, SCHED_FIFO}
36 };
37 
run(unsigned int n)38 static void run(unsigned int n)
39 {
40 	struct sched_variant *tv = &sched_variants[tst_variant];
41 	struct test_cases_t *tc = &tcases[n];
42 	struct sched_param p = { .sched_priority = tc->priority };
43 
44 	TST_EXP_PASS_SILENT(tv->sched_setscheduler(0, tc->policy, &p));
45 
46 	if (!TST_PASS)
47 		return;
48 
49 	TEST(tv->sched_getscheduler(0));
50 	if (TST_RET == tc->policy)
51 		tst_res(TPASS, "got expected policy %d", tc->policy);
52 	else
53 		tst_res(TFAIL | TERRNO, "got policy %ld, expected %d", TST_RET, tc->policy);
54 }
55 
setup(void)56 static void setup(void)
57 {
58 	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
59 }
60 
61 static struct tst_test test = {
62 	.needs_root = 1,
63 	.setup = setup,
64 	.test_variants = ARRAY_SIZE(sched_variants),
65 	.tcnt = ARRAY_SIZE(tcases),
66 	.test = run,
67 };
68