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 the policy and scheduling parameters remain unchanged when 12 * the sched_ss_max_repl is not within the inclusive range [1,SS_REPL_MAX] 13 * 14 * Test with a sched_ss_max_repl value of 0. 15 * Steps: 16 * 1. Get the old policy and priority. 17 * 2. Call sched_setscheduler with invalid args. 18 * 3. Check that the policy and priority have not changed. 19 * 20 * @pt:SS 21 */ 22#include <sched.h> 23#include <stdio.h> 24#include <errno.h> 25#include <unistd.h> 26#include "posixtest.h" 27 28 29#if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) 30 31int main(){ 32 int max_priority, old_priority, old_policy, new_policy; 33 struct sched_param param; 34 35 if(sched_getparam(getpid(), ¶m) == -1) { 36 perror("An error occurs when calling sched_getparam()"); 37 return PTS_UNRESOLVED; 38 } 39 old_priority = param.sched_priority; 40 41 old_policy = sched_getscheduler(getpid()); 42 if(old_policy == -1) { 43 perror("An error occurs when calling sched_getscheduler()"); 44 return PTS_UNRESOLVED; 45 } 46 47 /* Make sure that param.sched_priority != old_priority */ 48 max_priority = sched_get_priority_max(SCHED_SPORADIC); 49 param.sched_priority = (old_priority == max_priority) ? 50 sched_get_priority_min(SCHED_SPORADIC) : 51 max_priority; 52 53 param.sched_ss_max_repl = 0; 54 55 sched_setscheduler(0, SCHED_SPORADIC, ¶m); 56 57 if(sched_getparam(getpid(), ¶m) != 0) { 58 perror("An error occurs when calling sched_getparam()"); 59 return PTS_UNRESOLVED; 60 } 61 62 new_policy = sched_getscheduler(getpid()); 63 if(new_policy == -1) { 64 perror("An error occurs when calling sched_getscheduler()"); 65 return PTS_UNRESOLVED; 66 } 67 68 if(old_policy == new_policy && 69 old_priority == param.sched_priority) { 70 printf("Test PASSED\n"); 71 return PTS_PASS; 72 } 73 74 if(param.sched_priority != old_priority) { 75 printf("The param has changed\n"); 76 return PTS_FAIL; 77 } 78 if(new_policy != old_policy) { 79 printf("The policy has changed\n"); 80 return PTS_FAIL; 81 } 82 83} 84#else 85int main() 86{ 87 printf("Does not support SS (SPORADIC SERVER)\n"); 88 return PTS_UNSUPPORTED; 89} 90#endif 91