blob: 454f2e4bd84c43c60dd7c62097b5aa07bf35c6e4 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 */
16/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000017 *
vapierd13d74b2006-02-11 07:24:00 +000018 * TEST IDENTIFIER : sched_setparam02
subrata_modak4bb656a2009-02-26 12:02:09 +000019 *
vapierd13d74b2006-02-11 07:24:00 +000020 * EXECUTED BY : root / superuser
subrata_modak4bb656a2009-02-26 12:02:09 +000021 *
vapierd13d74b2006-02-11 07:24:00 +000022 * TEST TITLE : Checks functionality for sched_setparam(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000023 *
vapierd13d74b2006-02-11 07:24:00 +000024 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000025 *
vapierd13d74b2006-02-11 07:24:00 +000026 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000027 *
vapierd13d74b2006-02-11 07:24:00 +000028 * SIGNALS
29 * Uses SIGUSR1 to pause before test if option set.
30 * (See the parse_opts(3) man page).
31 *
32 * DESCRIPTION
33 * This test changes the scheduling priority for current process
34 * and verifies it by calling sched_getparam().
subrata_modak4bb656a2009-02-26 12:02:09 +000035 *
vapierd13d74b2006-02-11 07:24:00 +000036 * Setup:
37 * Setup signal handling.
38 * Pause for SIGUSR1 if option specified.
39 * Change scheduling policy to SCHED_FIFO
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
vapierd13d74b2006-02-11 07:24:00 +000041 * Test:
42 * Loop if the proper options are given.
43 * Execute system call
44 * If scheduling priority is set properly,
45 * TEST passed
46 * else
47 * TEST failed
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
vapierd13d74b2006-02-11 07:24:00 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
vapierd13d74b2006-02-11 07:24:00 +000052 * USAGE: <for command-line>
53 * sched_setparam02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
54 * where, -c n : Run n copies concurrently.
55 * -e : Turn on errno logging.
56 * -h : Show help screen
57 * -f : Turn off functional testing
58 * -i n : Execute test n times.
59 * -I x : Execute test for x seconds.
60 * -p : Pause for SIGUSR1 before starting
61 * -P x : Pause for x seconds between iterations.
62 * -t : Turn on syscall timing.
63 *
64 ****************************************************************/
65
66#include <errno.h>
67#include <sched.h>
68#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000069
70#define FIFO_OR_RR_PRIO 5
71#define OTHER_PRIO 0
72
73static void setup();
74static void cleanup();
75static int verify_priority(int);
76
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020077char *TCID = "sched_setparam02";
vapierd13d74b2006-02-11 07:24:00 +000078
79static struct sched_param param;
80static struct sched_param param1 = { 1 };
81
82static struct test_cases_t {
83 char *desc;
84 int policy;
85 int priority;
86} testcases[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000087 {
88 "Test with policy SCHED_FIFO", SCHED_FIFO, FIFO_OR_RR_PRIO}, {
89 "Test with policy SCHED_RR", SCHED_RR, FIFO_OR_RR_PRIO}, {
90 "Test with SCHED_OTHER", SCHED_OTHER, OTHER_PRIO}
vapierd13d74b2006-02-11 07:24:00 +000091};
92
93int TST_TOTAL = sizeof(testcases) / sizeof(testcases[0]);
94
subrata_modak56207ce2009-03-23 13:35:39 +000095int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000096{
97
Cyril Hrubis89af32a2012-10-24 16:39:11 +020098 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020099 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +0000100
Garrett Cooper53740502010-12-16 00:04:01 -0800101 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800102 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000103
vapierd13d74b2006-02-11 07:24:00 +0000104 setup();
105
vapierd13d74b2006-02-11 07:24:00 +0000106 for (lc = 0; TEST_LOOPING(lc); lc++) {
107
Caspar Zhangd59a6592013-03-07 14:59:12 +0800108 tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000109
vapierd13d74b2006-02-11 07:24:00 +0000110 for (i = 0; i < TST_TOTAL; ++i) {
111
112 if (i == 2) {
113 param1.sched_priority = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000114 } else {
vapierd13d74b2006-02-11 07:24:00 +0000115 param1.sched_priority = 1;
116 }
117 if ((sched_setscheduler(0, testcases[i].policy,
118 &param1)) == -1) {
119 tst_brkm(TBROK, cleanup, "sched_setscheduler()"
subrata_modak56207ce2009-03-23 13:35:39 +0000120 " failed");
vapierd13d74b2006-02-11 07:24:00 +0000121 }
122 param.sched_priority = testcases[i].priority;
subrata_modak4bb656a2009-02-26 12:02:09 +0000123 /*
vapierd13d74b2006-02-11 07:24:00 +0000124 * Call sched_setparam(2) with pid=0 sothat it will
125 * set the scheduling parameters for the calling process
126 */
127 TEST(sched_setparam(0, &param));
128
129 if ((TEST_RETURN == 0) && (verify_priority(i))) {
130 tst_resm(TPASS, "%s Passed", testcases[i].desc);
131 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800132 tst_resm(TFAIL | TTERRNO,
133 "%s Failed. sched_setparam()"
134 " returned %ld", testcases[i].desc,
135 TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +0000136 }
137 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800138 }
vapierd13d74b2006-02-11 07:24:00 +0000139
140 /* cleanup and exit */
141 cleanup();
142
Garrett Cooper53740502010-12-16 00:04:01 -0800143 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000144
Garrett Cooper2c282152010-12-16 00:55:50 -0800145}
vapierd13d74b2006-02-11 07:24:00 +0000146
147/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400148void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000149{
Garrett Cooper2c282152010-12-16 00:55:50 -0800150
vapierd13d74b2006-02-11 07:24:00 +0000151 tst_sig(NOFORK, DEF_HANDLER, cleanup);
152
vapierd13d74b2006-02-11 07:24:00 +0000153 TEST_PAUSE;
154
Garrett Cooper2c282152010-12-16 00:55:50 -0800155}
vapierd13d74b2006-02-11 07:24:00 +0000156
157/*
158 *cleanup() - performs all ONE TIME cleanup for this test at
159 * completion or premature exit.
160 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400161void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000162{
Garrett Cooper2c282152010-12-16 00:55:50 -0800163}
vapierd13d74b2006-02-11 07:24:00 +0000164
165/*
166 * verify_priority() - This function checks whether the priority is
167 * set correctly
168 */
subrata_modak56207ce2009-03-23 13:35:39 +0000169int verify_priority(int i)
vapierd13d74b2006-02-11 07:24:00 +0000170{
171 struct sched_param p;
172
173 if ((sched_getparam(0, &p)) == 0) {
174 if (p.sched_priority == testcases[i].priority) {
175 return 1;
176 } else {
177 tst_resm(TWARN, "sched_getparam() returned priority"
subrata_modak56207ce2009-03-23 13:35:39 +0000178 " value as %d", p.sched_priority);
vapierd13d74b2006-02-11 07:24:00 +0000179 return 0;
180 }
181 }
182
183 tst_resm(TWARN, "sched_getparam() failed");
184 return 0;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700185}