plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 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 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | #include <errno.h> |
Garrett Cooper | f9e342d | 2011-01-27 02:57:25 -0800 | [diff] [blame] | 49 | #include <sched.h> |
| 50 | #include <stdio.h> |
Garrett Cooper | e8530df | 2010-12-21 11:37:57 -0800 | [diff] [blame] | 51 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 53 | char *TCID = "sched_getscheduler01"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | int TST_TOTAL = 3; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | |
| 56 | void setup(void); |
| 57 | void cleanup(void); |
| 58 | |
| 59 | struct test_case_t { |
| 60 | int prio; |
| 61 | int policy; |
| 62 | } TC[] = { |
| 63 | /* set scheduling policy to SCHED_RR */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 64 | { |
| 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} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
plars | 0e8c9f2 | 2002-02-26 17:53:04 +0000 | [diff] [blame] | 74 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 76 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 77 | const char *msg; /* message returned by parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | |
plars | 0e8c9f2 | 2002-02-26 17:53:04 +0000 | [diff] [blame] | 79 | int i; |
| 80 | struct sched_param param; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 81 | |
Garrett Cooper | f9e342d | 2011-01-27 02:57:25 -0800 | [diff] [blame] | 82 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 83 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | |
| 85 | setup(); |
| 86 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 88 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 89 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | for (i = 0; i < TST_TOTAL; i++) { |
| 92 | |
plars | 0e8c9f2 | 2002-02-26 17:53:04 +0000 | [diff] [blame] | 93 | param.sched_priority = TC[i].prio; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | |
Garrett Cooper | f9e342d | 2011-01-27 02:57:25 -0800 | [diff] [blame] | 95 | if (sched_setscheduler(0, TC[i].policy, ¶m) == -1) |
| 96 | tst_brkm(TBROK, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 97 | "sched_setscheduler failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | |
| 99 | TEST(sched_getscheduler(0)); |
| 100 | |
| 101 | if (TEST_RETURN == -1) { |
| 102 | tst_resm(TFAIL, "call failed unexpectedly"); |
| 103 | continue; |
| 104 | } |
| 105 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 106 | 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"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 116 | cleanup(); |
Garrett Cooper | bad5f23 | 2011-01-27 02:35:36 -0800 | [diff] [blame] | 117 | tst_exit(); |
Garrett Cooper | f9e342d | 2011-01-27 02:57:25 -0800 | [diff] [blame] | 118 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 120 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | { |
Garrett Cooper | f9e342d | 2011-01-27 02:57:25 -0800 | [diff] [blame] | 122 | |
| 123 | tst_require_root(NULL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 125 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 126 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 127 | TEST_PAUSE; |
| 128 | } |
| 129 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 130 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | { |
Garrett Cooper | bad5f23 | 2011-01-27 02:35:36 -0800 | [diff] [blame] | 132 | } |