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 sched_setscheduler() sets errno == EINVAL when 12 * the sched_ss_max_repl is not within the inclusive range [1,SS_REPL_MAX] 13 * 14 * Test the values 0 and SS_REPL_MAX+1. 15 * 16 * @pt:SS 17 */ 18 19 #include <errno.h> 20 #include <sched.h> 21 #include <stdio.h> 22 #include <unistd.h> 23 #include "posixtest.h" 24 25 #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) 26 27 int main(void) 28 { 29 int policy, result; 30 int result_code = PTS_PASS; 31 struct sched_param param; 32 33 if (sched_getparam(0, ¶m) == -1) { 34 perror("An error occurs when calling sched_getparam()"); 35 return PTS_UNRESOLVED; 36 } 37 38 param.sched_priority = sched_get_priority_max(SCHED_SPORADIC); 39 40 /* test when sched_ss_max_repl < 1 */ 41 param.sched_ss_max_repl = 0; 42 result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); 43 44 if (result != -1) { 45 printf 46 ("The returned code is not -1 when sched_ss_max_repl < 1.\n"); 47 result_code = PTS_FAIL; 48 } else if (errno == EPERM) { 49 printf 50 ("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); 51 result_code = PTS_UNRESOLVED; 52 } else if (errno != EINVAL) { 53 perror("Unknow error when testing sched_ss_max_repl < 1"); 54 result_code = PTS_FAIL; 55 } 56 57 /* test when sched_ss_max_repl > SS_REPL_MAX */ 58 param.sched_ss_max_repl = SS_REPL_MAX + 1; 59 result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); 60 61 if (result == -1 && errno == EINVAL) { 62 if (result_code == PTS_PASS) { 63 printf("Test PASSED\n"); 64 } 65 return result_code; 66 } else if (result != -1) { 67 printf 68 ("The returned code is not -1 when sched_ss_max_repl > SS_REPL_MAX.\n"); 69 return PTS_FAIL; 70 } else if (errno == EPERM) { 71 if (result_code == PTS_FAIL) { 72 printf 73 ("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root.\n"); 74 return PTS_FAIL; 75 } 76 return PTS_UNRESOLVED; 77 } else { 78 perror 79 ("Unknow error when testing sched_ss_max_repl > SS_REPL_MAX"); 80 return PTS_FAIL; 81 } 82 83 } 84 #else 85 int main(void) 86 { 87 printf("Does not support SS (SPORADIC SERVER)\n"); 88 return PTS_UNSUPPORTED; 89 } 90 91 #endif 92