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 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 48#include <errno.h> 49#include <sched.h> 50#include <stdio.h> 51#include "test.h" 52 53char *TCID = "sched_getscheduler01"; 54int TST_TOTAL = 3; 55 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 */ 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} 72}; 73 74int main(int ac, char **av) 75{ 76 int lc; 77 int i; 78 struct sched_param param; 79 80 tst_parse_opts(ac, av, NULL, NULL); 81 82 setup(); 83 84 for (lc = 0; TEST_LOOPING(lc); lc++) { 85 86 tst_count = 0; 87 88 for (i = 0; i < TST_TOTAL; i++) { 89 90 param.sched_priority = TC[i].prio; 91 92 if (sched_setscheduler(0, TC[i].policy, ¶m) == -1) 93 tst_brkm(TBROK, cleanup, 94 "sched_setscheduler failed"); 95 96 TEST(sched_getscheduler(0)); 97 98 if (TEST_RETURN == -1) { 99 tst_resm(TFAIL, "call failed unexpectedly"); 100 continue; 101 } 102 103 if (TEST_RETURN != TC[i].policy) 104 tst_resm(TFAIL, 105 "policy value returned is not " 106 "correct"); 107 else 108 tst_resm(TPASS, 109 "policy value returned is correct"); 110 } 111 } 112 113 cleanup(); 114 tst_exit(); 115} 116 117void setup(void) 118{ 119 120 tst_require_root(); 121 122 tst_sig(NOFORK, DEF_HANDLER, cleanup); 123 124 TEST_PAUSE; 125} 126 127void cleanup(void) 128{ 129} 130