12c28215423293e443469a07ae7011135d058b671Garrett Cooper/* 20dc076565f772bb1953209fb69ea150b494aaa40robbiew * This program is free software; you can redistribute it and/or modify 30dc076565f772bb1953209fb69ea150b494aaa40robbiew * it under the terms of the GNU General Public License version 2. 40dc076565f772bb1953209fb69ea150b494aaa40robbiew * 50dc076565f772bb1953209fb69ea150b494aaa40robbiew * This program is distributed in the hope that it will be useful, 60dc076565f772bb1953209fb69ea150b494aaa40robbiew * but WITHOUT ANY WARRANTY; without even the implied warranty of 70dc076565f772bb1953209fb69ea150b494aaa40robbiew * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 80dc076565f772bb1953209fb69ea150b494aaa40robbiew * GNU General Public License for more details. 90dc076565f772bb1953209fb69ea150b494aaa40robbiew * 100dc076565f772bb1953209fb69ea150b494aaa40robbiew * 110dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test that the priority remain unchanged when the sched_priority 120dc076565f772bb1953209fb69ea150b494aaa40robbiew * member is not within the inclusive priority range for the current 130dc076565f772bb1953209fb69ea150b494aaa40robbiew * scheduling policy. 140dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 150dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sched.h> 160dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h> 170dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h" 180dc076565f772bb1953209fb69ea150b494aaa40robbiew 194ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void) 20354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao{ 210dc076565f772bb1953209fb69ea150b494aaa40robbiew int policy, invalid_priority, old_priority; 220dc076565f772bb1953209fb69ea150b494aaa40robbiew struct sched_param param; 230dc076565f772bb1953209fb69ea150b494aaa40robbiew 24df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (sched_getparam(0, ¶m) != 0) { 250dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("An error occurs when calling sched_getparam()"); 260dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 270dc076565f772bb1953209fb69ea150b494aaa40robbiew } 280dc076565f772bb1953209fb69ea150b494aaa40robbiew old_priority = param.sched_priority; 290dc076565f772bb1953209fb69ea150b494aaa40robbiew 300dc076565f772bb1953209fb69ea150b494aaa40robbiew policy = sched_getscheduler(0); 31df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (policy == -1) { 320dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("An error occurs when calling sched_getscheduler()"); 330dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 340dc076565f772bb1953209fb69ea150b494aaa40robbiew } 350dc076565f772bb1953209fb69ea150b494aaa40robbiew 360dc076565f772bb1953209fb69ea150b494aaa40robbiew invalid_priority = sched_get_priority_max(policy); 37df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (invalid_priority == -1) { 380dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("An error occurs when calling sched_get_priority_max()"); 390dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 400dc076565f772bb1953209fb69ea150b494aaa40robbiew } 410dc076565f772bb1953209fb69ea150b494aaa40robbiew 420dc076565f772bb1953209fb69ea150b494aaa40robbiew /* set an invalid priority */ 430dc076565f772bb1953209fb69ea150b494aaa40robbiew invalid_priority++; 440dc076565f772bb1953209fb69ea150b494aaa40robbiew param.sched_priority = invalid_priority; 45354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao sched_setparam(0, ¶m); 460dc076565f772bb1953209fb69ea150b494aaa40robbiew 47df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (sched_getparam(0, ¶m) != 0) { 480dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("An error occurs when calling sched_getparam()"); 490dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 500dc076565f772bb1953209fb69ea150b494aaa40robbiew } 51705b501d0afe3f0d5908011d64cc10d436e2f10dGarrett Cooper 52df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (param.sched_priority == old_priority) { 530dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test PASSED\n"); 540dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_PASS; 550dc076565f772bb1953209fb69ea150b494aaa40robbiew } else { 560dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("The priority have changed.\n"); 570dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 580dc076565f772bb1953209fb69ea150b494aaa40robbiew } 592c28215423293e443469a07ae7011135d058b671Garrett Cooper 60ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 61