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 * policy value is not defined in the sched.h header. 13 * 14 * The test attempt to set the policy to a very improbable value. 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#include <sched.h> 21#include <stdio.h> 22#include <errno.h> 23#include <unistd.h> 24#include "posixtest.h" 25 26int main(){ 27 int old_priority, old_policy, new_policy; 28 struct sched_param param; 29 int invalid_policy; 30 31 invalid_policy = 0; 32 /* Linux does not treat minus value as invalid for policy */ 33 while(invalid_policy == SCHED_OTHER || 34 invalid_policy == SCHED_FIFO || 35 invalid_policy == SCHED_RR) 36 invalid_policy++; 37 38 if(sched_getparam(getpid(), ¶m) == -1) { 39 perror("An error occurs when calling sched_getparam()"); 40 return PTS_UNRESOLVED; 41 } 42 old_priority = param.sched_priority; 43 44 old_policy = sched_getscheduler(getpid()); 45 if(old_policy == -1) { 46 perror("An error occurs when calling sched_getscheduler()"); 47 return PTS_UNRESOLVED; 48 } 49 50 sched_setscheduler(0, invalid_policy, ¶m); 51 52 if(errno == 0) { 53 printf("No error occurs, could %i be a valid value for the scheduling policy ???\n", invalid_policy); 54 return PTS_UNRESOLVED; 55 } 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 69 if(old_policy == new_policy && 70 old_priority == param.sched_priority) { 71 printf("Test PASSED\n"); 72 return PTS_PASS; 73 } 74 75 if(param.sched_priority != old_priority) { 76 printf("The param has changed\n"); 77 } 78 if(new_policy != old_policy) { 79 printf("The policy has changed\n"); 80 } 81 return PTS_FAIL; 82} 83