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
23
24int main(){
25	struct sched_param param;
26        int child_pid, stat_loc, old_priority;
27
28	if(sched_getparam(0, &param) == -1) {
29		perror("An error occurs when calling sched_getparam()");
30		return PTS_UNRESOLVED;
31	}
32	old_priority = param.sched_priority;
33
34        /* Create a child process which exit immediately */
35        child_pid = fork();
36        if(child_pid == -1){
37		perror("An error occurs when calling fork()");
38		return PTS_UNRESOLVED;
39        } else if (child_pid == 0){
40		exit(0);
41        }
42
43        /* Wait for the child process to exit */
44        if(wait(&stat_loc) == -1){
45		perror("An error occurs when calling wait()");
46		return PTS_UNRESOLVED;
47        }
48
49        /* Assume the pid is not yet reatributed to an other process */
50	param.sched_priority++;
51	sched_setparam(child_pid, &param);
52
53	if(sched_getparam(0, &param) != 0){
54		perror("An error occurs when calling sched_getparam()");
55		return PTS_UNRESOLVED;
56	}
57
58	if(param.sched_priority == old_priority){
59		printf("Test PASSED\n");
60		return PTS_PASS;
61	} else {
62		printf("The priority have changed.\n");
63		return PTS_FAIL;
64	}
65}
66