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