1865695bbc89088b9526ea9045410e5afb70a985cplars/* 2865695bbc89088b9526ea9045410e5afb70a985cplars * 3865695bbc89088b9526ea9045410e5afb70a985cplars * Copyright (c) International Business Machines Corp., 2001 4865695bbc89088b9526ea9045410e5afb70a985cplars * 5865695bbc89088b9526ea9045410e5afb70a985cplars * This program is free software; you can redistribute it and/or modify 6865695bbc89088b9526ea9045410e5afb70a985cplars * it under the terms of the GNU General Public License as published by 7865695bbc89088b9526ea9045410e5afb70a985cplars * the Free Software Foundation; either version 2 of the License, or 8865695bbc89088b9526ea9045410e5afb70a985cplars * (at your option) any later version. 9865695bbc89088b9526ea9045410e5afb70a985cplars * 10865695bbc89088b9526ea9045410e5afb70a985cplars * This program is distributed in the hope that it will be useful, 11865695bbc89088b9526ea9045410e5afb70a985cplars * but WITHOUT ANY WARRANTY; without even the implied warranty of 12865695bbc89088b9526ea9045410e5afb70a985cplars * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13865695bbc89088b9526ea9045410e5afb70a985cplars * the GNU General Public License for more details. 14865695bbc89088b9526ea9045410e5afb70a985cplars * 15865695bbc89088b9526ea9045410e5afb70a985cplars * You should have received a copy of the GNU General Public License 16865695bbc89088b9526ea9045410e5afb70a985cplars * along with this program; if not, write to the Free Software 174548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18865695bbc89088b9526ea9045410e5afb70a985cplars */ 19865695bbc89088b9526ea9045410e5afb70a985cplars 20865695bbc89088b9526ea9045410e5afb70a985cplars/* 21865695bbc89088b9526ea9045410e5afb70a985cplars * NAME 22865695bbc89088b9526ea9045410e5afb70a985cplars * sched_getscheduler01.C 23865695bbc89088b9526ea9045410e5afb70a985cplars * 24865695bbc89088b9526ea9045410e5afb70a985cplars * DESCRIPTION 25865695bbc89088b9526ea9045410e5afb70a985cplars * Testcase to check sched_getscheduler() returns correct return value 26865695bbc89088b9526ea9045410e5afb70a985cplars * 27865695bbc89088b9526ea9045410e5afb70a985cplars * ALGORTIHM 28865695bbc89088b9526ea9045410e5afb70a985cplars * Call sched_setcheduler() to set the scheduling policy of the current 29865695bbc89088b9526ea9045410e5afb70a985cplars * process. Then call sched_getscheduler() to ensure that this is same 30865695bbc89088b9526ea9045410e5afb70a985cplars * as what set by the previous call to sched_setscheduler(). 31865695bbc89088b9526ea9045410e5afb70a985cplars * 32865695bbc89088b9526ea9045410e5afb70a985cplars * Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for 33865695bbc89088b9526ea9045410e5afb70a985cplars * sched_setscheduler(). 34865695bbc89088b9526ea9045410e5afb70a985cplars * 35865695bbc89088b9526ea9045410e5afb70a985cplars * USAGE: <for command-line> 36865695bbc89088b9526ea9045410e5afb70a985cplars * sched_getscheduler01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] 37865695bbc89088b9526ea9045410e5afb70a985cplars * where, -c n : Run n copies concurrently. 38865695bbc89088b9526ea9045410e5afb70a985cplars * -f : Turn off functionality Testing. 39865695bbc89088b9526ea9045410e5afb70a985cplars * -i n : Execute test n times. 40865695bbc89088b9526ea9045410e5afb70a985cplars * -I x : Execute test for x seconds. 41865695bbc89088b9526ea9045410e5afb70a985cplars * -P x : Pause for x seconds between iterations. 42865695bbc89088b9526ea9045410e5afb70a985cplars * -t : Turn on syscall timing. 43865695bbc89088b9526ea9045410e5afb70a985cplars * 44865695bbc89088b9526ea9045410e5afb70a985cplars * RESTRICTION 45865695bbc89088b9526ea9045410e5afb70a985cplars * Must run test as root. 46865695bbc89088b9526ea9045410e5afb70a985cplars */ 47865695bbc89088b9526ea9045410e5afb70a985cplars 48865695bbc89088b9526ea9045410e5afb70a985cplars#include <errno.h> 49f9e342dc738dc41f4ac77b46edacc5755a3e728dGarrett Cooper#include <sched.h> 50f9e342dc738dc41f4ac77b46edacc5755a3e728dGarrett Cooper#include <stdio.h> 51e8530df4da095b0ea36a9ff8118ab5ce906b3e84Garrett Cooper#include "test.h" 52865695bbc89088b9526ea9045410e5afb70a985cplars 5356207cec7732e09c216c751c0b5f88a242bacae6subrata_modakchar *TCID = "sched_getscheduler01"; 54865695bbc89088b9526ea9045410e5afb70a985cplarsint TST_TOTAL = 3; 55865695bbc89088b9526ea9045410e5afb70a985cplars 56865695bbc89088b9526ea9045410e5afb70a985cplarsvoid setup(void); 57865695bbc89088b9526ea9045410e5afb70a985cplarsvoid cleanup(void); 58865695bbc89088b9526ea9045410e5afb70a985cplars 59865695bbc89088b9526ea9045410e5afb70a985cplarsstruct test_case_t { 60865695bbc89088b9526ea9045410e5afb70a985cplars int prio; 61865695bbc89088b9526ea9045410e5afb70a985cplars int policy; 62865695bbc89088b9526ea9045410e5afb70a985cplars} TC[] = { 63865695bbc89088b9526ea9045410e5afb70a985cplars /* set scheduling policy to SCHED_RR */ 64354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao { 65354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao 1, SCHED_RR}, 66354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* set scheduling policy to SCHED_OTHER */ 67354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao { 68354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao 0, SCHED_OTHER}, 69354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* set scheduling policy to SCHED_FIFO */ 70354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao { 71354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao 1, SCHED_FIFO} 72865695bbc89088b9526ea9045410e5afb70a985cplars}; 73865695bbc89088b9526ea9045410e5afb70a985cplars 740e8c9f20bfc4b15212e3057b50d08346ebf63c58plarsint main(int ac, char **av) 75865695bbc89088b9526ea9045410e5afb70a985cplars{ 7689af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis int lc; 770e8c9f20bfc4b15212e3057b50d08346ebf63c58plars int i; 780e8c9f20bfc4b15212e3057b50d08346ebf63c58plars struct sched_param param; 79bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 80d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis tst_parse_opts(ac, av, NULL, NULL); 81865695bbc89088b9526ea9045410e5afb70a985cplars 82865695bbc89088b9526ea9045410e5afb70a985cplars setup(); 83865695bbc89088b9526ea9045410e5afb70a985cplars 84865695bbc89088b9526ea9045410e5afb70a985cplars for (lc = 0; TEST_LOOPING(lc); lc++) { 85865695bbc89088b9526ea9045410e5afb70a985cplars 86d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang tst_count = 0; 87865695bbc89088b9526ea9045410e5afb70a985cplars 88865695bbc89088b9526ea9045410e5afb70a985cplars for (i = 0; i < TST_TOTAL; i++) { 89865695bbc89088b9526ea9045410e5afb70a985cplars 900e8c9f20bfc4b15212e3057b50d08346ebf63c58plars param.sched_priority = TC[i].prio; 91865695bbc89088b9526ea9045410e5afb70a985cplars 92f9e342dc738dc41f4ac77b46edacc5755a3e728dGarrett Cooper if (sched_setscheduler(0, TC[i].policy, ¶m) == -1) 93f9e342dc738dc41f4ac77b46edacc5755a3e728dGarrett Cooper tst_brkm(TBROK, cleanup, 94354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "sched_setscheduler failed"); 95865695bbc89088b9526ea9045410e5afb70a985cplars 96865695bbc89088b9526ea9045410e5afb70a985cplars TEST(sched_getscheduler(0)); 97865695bbc89088b9526ea9045410e5afb70a985cplars 98865695bbc89088b9526ea9045410e5afb70a985cplars if (TEST_RETURN == -1) { 99865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TFAIL, "call failed unexpectedly"); 100865695bbc89088b9526ea9045410e5afb70a985cplars continue; 101865695bbc89088b9526ea9045410e5afb70a985cplars } 102865695bbc89088b9526ea9045410e5afb70a985cplars 103e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis if (TEST_RETURN != TC[i].policy) 104e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis tst_resm(TFAIL, 105e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis "policy value returned is not " 106e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis "correct"); 107e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis else 108e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis tst_resm(TPASS, 109e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis "policy value returned is correct"); 110865695bbc89088b9526ea9045410e5afb70a985cplars } 111865695bbc89088b9526ea9045410e5afb70a985cplars } 112865695bbc89088b9526ea9045410e5afb70a985cplars 113e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis cleanup(); 114bad5f23976ad6e901f0993c97fde22998d0f21b4Garrett Cooper tst_exit(); 115f9e342dc738dc41f4ac77b46edacc5755a3e728dGarrett Cooper} 116865695bbc89088b9526ea9045410e5afb70a985cplars 117c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingervoid setup(void) 118865695bbc89088b9526ea9045410e5afb70a985cplars{ 119f9e342dc738dc41f4ac77b46edacc5755a3e728dGarrett Cooper 120d1e794d62b1bf619df8390535e4c2a58899b1145Cyril Hrubis tst_require_root(); 121865695bbc89088b9526ea9045410e5afb70a985cplars 122865695bbc89088b9526ea9045410e5afb70a985cplars tst_sig(NOFORK, DEF_HANDLER, cleanup); 123865695bbc89088b9526ea9045410e5afb70a985cplars 124865695bbc89088b9526ea9045410e5afb70a985cplars TEST_PAUSE; 125865695bbc89088b9526ea9045410e5afb70a985cplars} 126865695bbc89088b9526ea9045410e5afb70a985cplars 127c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingervoid cleanup(void) 128865695bbc89088b9526ea9045410e5afb70a985cplars{ 129bad5f23976ad6e901f0993c97fde22998d0f21b4Garrett Cooper} 130