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 sched_setparam() sets errno == EINVAL when the 120dc076565f772bb1953209fb69ea150b494aaa40robbiew * sched_ss_repl_period is not greater than or equal to the 130dc076565f772bb1953209fb69ea150b494aaa40robbiew * sched_ss_init_budget member. 140dc076565f772bb1953209fb69ea150b494aaa40robbiew * 150dc076565f772bb1953209fb69ea150b494aaa40robbiew * @pt:SS 160dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 1717dc34f217c5617baae6abc8d4cbef0ec9caadc2Garrett Cooper#include <errno.h> 180dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sched.h> 190dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h> 200dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <unistd.h> 210dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h" 220dc076565f772bb1953209fb69ea150b494aaa40robbiew 230dc076565f772bb1953209fb69ea150b494aaa40robbiew#if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) 240dc076565f772bb1953209fb69ea150b494aaa40robbiew 254ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void) 26354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao{ 270dc076565f772bb1953209fb69ea150b494aaa40robbiew int policy, result; 280dc076565f772bb1953209fb69ea150b494aaa40robbiew struct sched_param param; 290dc076565f772bb1953209fb69ea150b494aaa40robbiew 30df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (sched_getparam(0, ¶m) != 0) { 310dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("An error occurs when calling sched_getparam()"); 320dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 332c28215423293e443469a07ae7011135d058b671Garrett Cooper } 340dc076565f772bb1953209fb69ea150b494aaa40robbiew 350dc076565f772bb1953209fb69ea150b494aaa40robbiew /* set a sched_ss_repl_period lower than the sched_ss_init_budget */ 360dc076565f772bb1953209fb69ea150b494aaa40robbiew param.sched_ss_repl_period.tv_sec = 1; 370dc076565f772bb1953209fb69ea150b494aaa40robbiew param.sched_ss_repl_period.tv_nsec = 0; 380dc076565f772bb1953209fb69ea150b494aaa40robbiew 390dc076565f772bb1953209fb69ea150b494aaa40robbiew param.sched_ss_init_budget.tv_sec = 2; 400dc076565f772bb1953209fb69ea150b494aaa40robbiew param.sched_ss_init_budget.tv_nsec = 0; 412c28215423293e443469a07ae7011135d058b671Garrett Cooper 42354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao result = sched_setparam(0, ¶m); 432c28215423293e443469a07ae7011135d058b671Garrett Cooper 44df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (result == -1 && errno == EINVAL) { 450dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test PASSED\n"); 460dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_PASS; 47df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper } else if (result != -1) { 480dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("The returned code is not -1.\n"); 490dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 50df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper } else if (errno == EPERM) { 51354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao printf 52354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao ("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root\n"); 530dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 540dc076565f772bb1953209fb69ea150b494aaa40robbiew } else { 55354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao perror("Unknown error"); 56354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return PTS_FAIL; 570dc076565f772bb1953209fb69ea150b494aaa40robbiew } 580dc076565f772bb1953209fb69ea150b494aaa40robbiew} 590dc076565f772bb1953209fb69ea150b494aaa40robbiew 6017dc34f217c5617baae6abc8d4cbef0ec9caadc2Garrett Cooper#elif _POSIX_SPORADIC_SERVER == -1 61354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint main(void) 62393822aa72d8652550d8c88c17240ed19b86593cGarrett Cooper{ 6317dc34f217c5617baae6abc8d4cbef0ec9caadc2Garrett Cooper printf("_POSIX_SPORADIC_SERVER support not available\n"); 64393822aa72d8652550d8c88c17240ed19b86593cGarrett Cooper return PTS_UNSUPPORTED; 6517dc34f217c5617baae6abc8d4cbef0ec9caadc2Garrett Cooper} 6617dc34f217c5617baae6abc8d4cbef0ec9caadc2Garrett Cooper 6717dc34f217c5617baae6abc8d4cbef0ec9caadc2Garrett Cooper#else 6817dc34f217c5617baae6abc8d4cbef0ec9caadc2Garrett Cooper#error "_POSIX_SPORADIC_SERVER not defined correctly" 69ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman#endif 70