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 the priority remain unchanged when the sched_priority
12 * member is not within the inclusive priority range for the current
13 * scheduling policy.
14 */
15#include <sched.h>
16#include <stdio.h>
17#include "posixtest.h"
18
19
20int main(){
21	int policy, invalid_priority, old_priority;
22	struct sched_param param;
23
24	if(sched_getparam(0, &param) != 0){
25		perror("An error occurs when calling sched_getparam()");
26		return PTS_UNRESOLVED;
27	}
28	old_priority = param.sched_priority;
29
30	policy = sched_getscheduler(0);
31	if(policy == -1){
32		perror("An error occurs when calling sched_getscheduler()");
33		return PTS_UNRESOLVED;
34	}
35
36	invalid_priority = sched_get_priority_max(policy);
37	if(invalid_priority == -1){
38		perror("An error occurs when calling sched_get_priority_max()");
39		return PTS_UNRESOLVED;
40	}
41
42	/* set an invalid priority */
43	invalid_priority++;
44	param.sched_priority = invalid_priority;
45	sched_setparam(0,&param);
46
47	if(sched_getparam(0, &param) != 0){
48		perror("An error occurs when calling sched_getparam()");
49		return PTS_UNRESOLVED;
50	}
51
52	if(param.sched_priority == old_priority){
53		printf("Test PASSED\n");
54		return PTS_PASS;
55	} else {
56		printf("The priority have changed.\n");
57		return PTS_FAIL;
58	}
59
60}
61