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 policy value is
12 * not defined in the sched.h header.
13 *
14 * Assume that the header does not defined a scheduling policy with a value
15 * of -1. (It is more coherent with the specificationS of sched_getscheduler
16 * and sched_setscheduler for which the result code -1 indicate an error.)
17 * If no error occurs whith -1, the test will run sched_setscheduler with the
18 * very improbable policy value INVALID_POLICY.
19 */
20 #include <sched.h>
21 #include <stdio.h>
22 #include <errno.h>
23 #include <unistd.h>
24 #include "posixtest.h"
25
26 /* There is no chance that a scheduling policy has such a value */
27 #define INVALID_POLICY -27367
28
main(void)29 int main(void)
30 {
31 int result;
32 struct sched_param param;
33
34 param.sched_priority = 0;
35
36 result = sched_setscheduler(0, -1, ¶m);
37
38 if (result == -1 && errno == EINVAL) {
39 printf("Test PASSED\n");
40 return PTS_PASS;
41 } else if (errno == EPERM) {
42 printf
43 ("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n");
44 return PTS_UNRESOLVED;
45 } else if (errno == 0) {
46 printf
47 ("No error occurs, check if -1 a valid value for the scheduling policy.\n");
48 } else {
49 perror("Unknow error");
50 return PTS_FAIL;
51 }
52
53 printf("Testing with very improbable policy value %i:\n",
54 INVALID_POLICY);
55
56 result = sched_setscheduler(0, INVALID_POLICY, ¶m);
57
58 if (result == -1 && errno == EINVAL) {
59 printf("Test PASSED with policy value %i\n", INVALID_POLICY);
60 return PTS_PASS;
61 } else if (errno == 0) {
62 printf
63 ("No error occurs, could %i be a valid value for the scheduling policy ???\n",
64 INVALID_POLICY);
65 return PTS_UNRESOLVED;
66 } else {
67 perror("Unknow error");
68 return PTS_FAIL;
69 }
70
71 }
72