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 priority remain unchanged when the sched_ss_low_priority 12 * member is not within the inclusive priority range for the sporadic server 13 * policy. 14 * 15 * @pt:SS 16 */ 17 18#include <sched.h> 19#include <stdio.h> 20#include <unistd.h> 21#include "posixtest.h" 22 23#if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) 24 25int main(){ 26 int policy, invalid_priority, old_priority; 27 struct sched_param param; 28 29 if(sched_getparam(0, ¶m) != 0){ 30 perror("An error occurs when calling sched_getparam()"); 31 return PTS_UNRESOLVED; 32 } 33 old_priority = param.sched_priority; 34 35 policy = sched_getscheduler(0); 36 if(policy == -1){ 37 perror("An error occurs when calling sched_getscheduler()"); 38 return PTS_UNRESOLVED; 39 } else if(policy != SCHED_SPORADIC){ 40 if(sched_setscheduler(0, SCHED_SPORADIC, ¶m) != 0){ 41 perror("An error occurs when calling sched_getparam()"); 42 return PTS_UNRESOLVED; 43 } 44 } 45 46 47 invalid_priority = sched_get_priority_max(SCHED_SPORADIC); 48 if(invalid_priority == -1){ 49 perror("An error occurs when calling sched_get_priority_max()"); 50 return PTS_UNRESOLVED; 51 } 52 53 /* set an invalid priority */ 54 invalid_priority++; 55 param.sched_ss_low_priority = invalid_priority; 56 param.sched_priority++; 57 sched_setparam(0,¶m); 58 59 if(sched_getparam(0, ¶m) != 0){ 60 perror("An error occurs when calling sched_getparam()"); 61 return PTS_UNRESOLVED; 62 } 63 64 if(param.sched_priority == old_priority){ 65 printf("Test PASSED\n"); 66 return PTS_PASS; 67 } else { 68 printf("The priority have changed.\n"); 69 return PTS_FAIL; 70 } 71} 72 73#else 74int main() 75{ 76 printf("Does not support SS (SPORADIC SERVER)\n"); 77 return PTS_UNSUPPORTED; 78} 79 80#endif 81