1 #include "tests.h"
2 #include <asm/unistd.h>
3 
4 #if defined __NR_sched_getscheduler && defined __NR_sched_setscheduler
5 
6 # include <sched.h>
7 # include <stdio.h>
8 # include <unistd.h>
9 
10 int
11 main(void)
12 {
13 	TAIL_ALLOC_OBJECT_CONST_PTR(struct sched_param, param);
14 	long rc = syscall(__NR_sched_getscheduler, 0);
15 	const char *scheduler;
16 	switch (rc) {
17 		case SCHED_FIFO:
18 			scheduler = "SCHED_FIFO";
19 			break;
20 		case SCHED_RR:
21 			scheduler = "SCHED_RR";
22 			break;
23 # ifdef SCHED_BATCH
24 		case SCHED_BATCH:
25 			scheduler = "SCHED_BATCH";
26 			break;
27 # endif
28 # ifdef SCHED_IDLE
29 		case SCHED_IDLE:
30 			scheduler = "SCHED_IDLE";
31 			break;
32 # endif
33 # ifdef SCHED_ISO
34 		case SCHED_ISO:
35 			scheduler = "SCHED_ISO";
36 			break;
37 # endif
38 # ifdef SCHED_DEADLINE
39 		case SCHED_DEADLINE:
40 			scheduler = "SCHED_DEADLINE";
41 			break;
42 # endif
43 		default:
44 			scheduler = "SCHED_OTHER";
45 	}
46 	printf("sched_getscheduler(0) = %ld (%s)\n",
47 	       rc, scheduler);
48 
49 	rc = syscall(__NR_sched_getscheduler, -1);
50 	printf("sched_getscheduler(-1) = %s\n", sprintrc(rc));
51 
52 	param->sched_priority = -1;
53 
54 	rc = syscall(__NR_sched_setscheduler, 0, SCHED_FIFO, NULL);
55 	printf("sched_setscheduler(0, SCHED_FIFO, NULL) = %s\n", sprintrc(rc));
56 
57 	rc = syscall(__NR_sched_setscheduler, 0, SCHED_FIFO, param + 1);
58 	printf("sched_setscheduler(0, SCHED_FIFO, %p) = %s\n", param + 1,
59 	       sprintrc(rc));
60 
61 	rc = syscall(__NR_sched_setscheduler, 0, 0xfaceda7a, param);
62 	printf("sched_setscheduler(0, %#x /* SCHED_??? */, [%d]) = %s\n",
63 	       0xfaceda7a, param->sched_priority, sprintrc(rc));
64 
65 	rc = syscall(__NR_sched_setscheduler, -1, SCHED_FIFO, param);
66 	printf("sched_setscheduler(-1, SCHED_FIFO, [%d]) = %s\n",
67 	       param->sched_priority, sprintrc(rc));
68 
69 	rc = syscall(__NR_sched_setscheduler, 0, SCHED_FIFO, param);
70 	printf("sched_setscheduler(0, SCHED_FIFO, [%d]) = %s\n",
71 	       param->sched_priority, sprintrc(rc));
72 
73 	puts("+++ exited with 0 +++");
74 	return 0;
75 }
76 
77 #else
78 
79 SKIP_MAIN_UNDEFINED("__NR_sched_getscheduler && __NR_sched_setscheduler")
80 
81 #endif
82