• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sched.h>
25 #include "tst_test.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_param param = {
33 		.sched_priority = 100,
34 	};
35 
36 	child_pid = SAFE_FORK();
37 	if (!child_pid) {
38 		TST_EXP_PASS_SILENT(sched_getparam(pids[n], &param),
39 				    "sched_getparam(%d)", pids[n]);
40 		if (!TST_PASS)
41 			exit(0);
42 
43 		/*
44 		 * For normal process, scheduling policy is SCHED_OTHER.
45 		 * For this scheduling policy, only allowed priority value is 0.
46 		 */
47 		if (param.sched_priority)
48 			tst_res(TFAIL,
49 				"sched_getparam(%d) got wrong sched_priority %d, expected 0",
50 				pids[n], param.sched_priority);
51 		else
52 			tst_res(TPASS, "sched_getparam(%d) got expected sched_priority 0", pids[n]);
53 
54 		exit(0);
55 	}
56 
57 	tst_reap_children();
58 }
59 
setup(void)60 static void setup(void)
61 {
62 	pids[1] = getpid();
63 }
64 
65 static struct tst_test test = {
66 	.forks_child = 1,
67 	.setup = setup,
68 	.tcnt = ARRAY_SIZE(pids),
69 	.test = verify_sched_getparam,
70 };
71