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_setscheduler() sets errno == EINVAL when the
12 * sched_ss_low_priority member is not within the inclusive priority range for
13 * the sporadic server policy.
14 *
15 * @pt:SS
16 */
17
18#include <errno.h>
19#include <sched.h>
20#include <stdio.h>
21#include "posixtest.h"
22
23#if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1)
24
25int main(void)
26{
27	int invalid_priority, result;
28	struct sched_param param;
29
30	invalid_priority = sched_get_priority_max(SCHED_SPORADIC);
31	if (invalid_priority == -1) {
32		perror("An error occurs when calling sched_get_priority_max()");
33		return PTS_UNRESOLVED;
34	}
35
36	/* set an invalid priority */
37	invalid_priority++;
38	param.sched_ss_low_priority = invalid_priority;
39
40	result = sched_setscheduler(0, SCHED_SPORADIC, &param);
41
42	if (result == -1 && errno == EINVAL) {
43		printf("Test PASSED\n");
44		return PTS_PASS;
45	} else if (result != -1) {
46		printf("The returned code is not -1.\n");
47		return PTS_FAIL;
48	} else if (errno == EPERM) {
49		printf
50		    ("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n");
51		return PTS_UNRESOLVED;
52	} else {
53		perror("Unknow error");
54		return PTS_FAIL;
55	}
56}
57#else
58int main(void)
59{
60	printf("Does not support SS (SPORADIC SERVER)\n");
61	return PTS_UNSUPPORTED;
62}
63#endif
64