Home | History | Annotate | Download | only in sched_getparam
      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_getparam() returns -1 on failure.
     12  *
     13  * The test create a child process which exit immediately and call
     14  * sched_getparam 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 
     24 int main(void)
     25 {
     26 
     27 	struct sched_param param;
     28 	int result = -1, child_pid;
     29 	int stat_loc;
     30 
     31 	/* Create a child process which exit immediately */
     32 	child_pid = fork();
     33 	if (child_pid == -1) {
     34 		perror("fork failed");
     35 		return PTS_UNRESOLVED;
     36 	} else if (child_pid == 0) {
     37 		exit(0);
     38 	}
     39 
     40 	/* Wait for the child process to exit */
     41 	if (wait(&stat_loc) == -1) {
     42 		perror("wait failed");
     43 		return PTS_UNRESOLVED;
     44 	}
     45 
     46 	/* Assume the pid is not yet reatributed to an other process */
     47 	result = sched_getparam(child_pid, &param);
     48 
     49 	if (result == -1 && errno == ESRCH) {
     50 		printf("Test PASSED\n");
     51 		return PTS_PASS;
     52 	}
     53 	if (result != -1) {
     54 		printf("returned code is not -1.\n");
     55 		return PTS_FAIL;
     56 	}
     57 	if (errno != ESRCH) {
     58 		perror("errno is not ESRCH");
     59 		return PTS_FAIL;
     60 	} else {
     61 		perror("Unresolved test error");
     62 		return PTS_UNRESOLVED;
     63 	}
     64 
     65 }
     66