Home | History | Annotate | Download | only in sched_setparam
      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_setparam() sets errno == ESRCH when no process can be found
     12  * corresponding to that specified by pid.
     13  */
     14 #include <sched.h>
     15 #include <stdio.h>
     16 #include <errno.h>
     17 #include <unistd.h>
     18 #include <stdlib.h>
     19 #include <sys/wait.h>
     20 #include "posixtest.h"
     21 
     22 int main(void)
     23 {
     24 	struct sched_param param;
     25 	int child_pid, stat_loc, old_priority;
     26 
     27 	if (sched_getparam(0, &param) == -1) {
     28 		perror("An error occurs when calling sched_getparam()");
     29 		return PTS_UNRESOLVED;
     30 	}
     31 	old_priority = param.sched_priority;
     32 
     33 	/* Create a child process which exit immediately */
     34 	child_pid = fork();
     35 	if (child_pid == -1) {
     36 		perror("An error occurs when calling fork()");
     37 		return PTS_UNRESOLVED;
     38 	} else if (child_pid == 0) {
     39 		exit(0);
     40 	}
     41 
     42 	/* Wait for the child process to exit */
     43 	if (wait(&stat_loc) == -1) {
     44 		perror("An error occurs when calling wait()");
     45 		return PTS_UNRESOLVED;
     46 	}
     47 
     48 	/* Assume the pid is not yet reatributed to an other process */
     49 	param.sched_priority++;
     50 	sched_setparam(child_pid, &param);
     51 
     52 	if (sched_getparam(0, &param) != 0) {
     53 		perror("An error occurs when calling sched_getparam()");
     54 		return PTS_UNRESOLVED;
     55 	}
     56 
     57 	if (param.sched_priority == old_priority) {
     58 		printf("Test PASSED\n");
     59 		return PTS_PASS;
     60 	} else {
     61 		printf("The priority have changed.\n");
     62 		return PTS_FAIL;
     63 	}
     64 }
     65