blob: 2da787426bf359b02207463e2592c07c778cf34d [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * sched_getscheduler01.C
23 *
24 * DESCRIPTION
25 * Testcase to check sched_getscheduler() returns correct return value
26 *
27 * ALGORTIHM
28 * Call sched_setcheduler() to set the scheduling policy of the current
29 * process. Then call sched_getscheduler() to ensure that this is same
30 * as what set by the previous call to sched_setscheduler().
31 *
32 * Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for
33 * sched_setscheduler().
34 *
35 * USAGE: <for command-line>
36 * sched_getscheduler01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
37 * where, -c n : Run n copies concurrently.
38 * -f : Turn off functionality Testing.
39 * -i n : Execute test n times.
40 * -I x : Execute test for x seconds.
41 * -P x : Pause for x seconds between iterations.
42 * -t : Turn on syscall timing.
43 *
44 * RESTRICTION
45 * Must run test as root.
46 */
47
plars865695b2001-08-27 22:15:12 +000048#include <errno.h>
Garrett Cooperf9e342d2011-01-27 02:57:25 -080049#include <sched.h>
50#include <stdio.h>
Garrett Coopere8530df2010-12-21 11:37:57 -080051#include "test.h"
plars865695b2001-08-27 22:15:12 +000052
subrata_modak56207ce2009-03-23 13:35:39 +000053char *TCID = "sched_getscheduler01";
plars865695b2001-08-27 22:15:12 +000054int TST_TOTAL = 3;
plars865695b2001-08-27 22:15:12 +000055
56void setup(void);
57void cleanup(void);
58
59struct test_case_t {
60 int prio;
61 int policy;
62} TC[] = {
63 /* set scheduling policy to SCHED_RR */
Wanlong Gao354ebb42012-12-07 10:10:04 +080064 {
65 1, SCHED_RR},
66 /* set scheduling policy to SCHED_OTHER */
67 {
68 0, SCHED_OTHER},
69 /* set scheduling policy to SCHED_FIFO */
70 {
71 1, SCHED_FIFO}
plars865695b2001-08-27 22:15:12 +000072};
73
plars0e8c9f22002-02-26 17:53:04 +000074int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000075{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020076 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020077 const char *msg; /* message returned by parse_opts */
plars865695b2001-08-27 22:15:12 +000078
plars0e8c9f22002-02-26 17:53:04 +000079 int i;
80 struct sched_param param;
subrata_modakbdbaec52009-02-26 12:14:51 +000081
Garrett Cooperf9e342d2011-01-27 02:57:25 -080082 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080083 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000084
85 setup();
86
plars865695b2001-08-27 22:15:12 +000087 for (lc = 0; TEST_LOOPING(lc); lc++) {
88
Caspar Zhangd59a6592013-03-07 14:59:12 +080089 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000090
plars865695b2001-08-27 22:15:12 +000091 for (i = 0; i < TST_TOTAL; i++) {
92
plars0e8c9f22002-02-26 17:53:04 +000093 param.sched_priority = TC[i].prio;
plars865695b2001-08-27 22:15:12 +000094
Garrett Cooperf9e342d2011-01-27 02:57:25 -080095 if (sched_setscheduler(0, TC[i].policy, &param) == -1)
96 tst_brkm(TBROK, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +080097 "sched_setscheduler failed");
plars865695b2001-08-27 22:15:12 +000098
99 TEST(sched_getscheduler(0));
100
101 if (TEST_RETURN == -1) {
102 tst_resm(TFAIL, "call failed unexpectedly");
103 continue;
104 }
105
Cyril Hrubise38b9612014-06-02 17:20:57 +0200106 if (TEST_RETURN != TC[i].policy)
107 tst_resm(TFAIL,
108 "policy value returned is not "
109 "correct");
110 else
111 tst_resm(TPASS,
112 "policy value returned is correct");
plars865695b2001-08-27 22:15:12 +0000113 }
114 }
plars865695b2001-08-27 22:15:12 +0000115
Cyril Hrubise38b9612014-06-02 17:20:57 +0200116 cleanup();
Garrett Cooperbad5f232011-01-27 02:35:36 -0800117 tst_exit();
Garrett Cooperf9e342d2011-01-27 02:57:25 -0800118}
plars865695b2001-08-27 22:15:12 +0000119
Mike Frysingerc57fba52014-04-09 18:56:30 -0400120void setup(void)
plars865695b2001-08-27 22:15:12 +0000121{
Garrett Cooperf9e342d2011-01-27 02:57:25 -0800122
123 tst_require_root(NULL);
plars865695b2001-08-27 22:15:12 +0000124
plars865695b2001-08-27 22:15:12 +0000125 tst_sig(NOFORK, DEF_HANDLER, cleanup);
126
plars865695b2001-08-27 22:15:12 +0000127 TEST_PAUSE;
128}
129
Mike Frysingerc57fba52014-04-09 18:56:30 -0400130void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000131{
Garrett Cooperbad5f232011-01-27 02:35:36 -0800132}