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