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_getscheduler() returns -1 on failure. 12 * 13 * The test create a child process which exit immediately and call 14 * sched_getscheduler with the pid of defunct child. 15 */ 16 #include <stdio.h> 17 #include <sched.h> 18 #include <errno.h> 19 #include <unistd.h> 20 #include <stdlib.h> 21 #include <sys/wait.h> 22 #include "posixtest.h" 23 main(int argc,char ** argv)24int main(int argc, char **argv) 25 { 26 27 int result = -1, child_pid; 28 int stat_loc; 29 30 /* Create a child process which exit immediately */ 31 child_pid = fork(); 32 if(child_pid == -1){ 33 perror("An error occurs when calling fork()"); 34 return PTS_UNRESOLVED; 35 } else if (child_pid == 0){ 36 exit(0); 37 } 38 39 /* Wait for the child process to exit */ 40 if(wait(&stat_loc) == -1){ 41 perror("An error occurs when calling wait()"); 42 return PTS_UNRESOLVED; 43 } 44 45 /* Assume the pid is not yet reatributed to an other process */ 46 result = sched_getscheduler(child_pid); 47 48 if(result == -1) { 49 printf("Test PASSED\n"); 50 return PTS_PASS; 51 } 52 53 if(errno != ESRCH ) { 54 perror("ESRCH is not returned"); 55 return PTS_FAIL; 56 } 57 58 if(result != -1) { 59 printf("Returned code is not -1.\n"); 60 return PTS_FAIL; 61 } else { 62 perror("Unresolved test error"); 63 return PTS_UNRESOLVED; 64 } 65 66 } 67 68 69