1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License version 2. 4 * 5 * This program is distributed in the hope that it will be useful, 6 * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 8 * GNU General Public License for more details. 9 * 10 * 11 * Test that sched_setscheduler() sets errno == EINVAL when the 12 * sched_ss_repl_period is not greater than or equal to the 13 * sched_ss_init_budget member. 14 * 15 * @pt:SS 16 */ 17 18 #include <errno.h> 19 #include <sched.h> 20 #include <stdio.h> 21 #include <unistd.h> 22 #include "posixtest.h" 23 24 #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) 25 26 int main(void) 27 { 28 int policy, result; 29 struct sched_param param; 30 31 if (sched_getparam(0, ¶m) != 0) { 32 perror("An error occurs when calling sched_getparam()"); 33 return PTS_UNRESOLVED; 34 } 35 36 /* set a sched_ss_repl_period lower than the sched_ss_init_budget */ 37 param.sched_ss_repl_period.tv_sec = 1; 38 param.sched_ss_repl_period.tv_nsec = 0; 39 40 param.sched_ss_init_budget.tv_sec = 2; 41 param.sched_ss_init_budget.tv_nsec = 0; 42 43 param.sched_priority = sched_get_priority_max(SCHED_SPORADIC); 44 45 result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); 46 47 if (result == -1 && errno == EINVAL) { 48 printf("Test PASSED\n"); 49 return PTS_PASS; 50 } else if (result != -1) { 51 printf("The returned code is not -1.\n"); 52 return PTS_FAIL; 53 } else if (errno == EPERM) { 54 printf 55 ("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); 56 return PTS_UNRESOLVED; 57 } 58 perror("Unknow error"); 59 return PTS_FAIL; 60 } 61 #else 62 int main(void) 63 { 64 printf("Does not support SS (SPORADIC SERVER)\n"); 65 return PTS_UNSUPPORTED; 66 } 67 68 #endif 69