1 #include <errno.h>
2 #include <unistd.h>
3 #include <sys/sched.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #include <err.h>
8 #include <sysexits.h>
9 #include "prutil.h"
10
11 /*
12 * $FreeBSD: src/tools/regression/p1003_1b/prutil.c,v 1.1 2000/02/16 14:28:41 dufault Exp $
13 */
quit(const char * text)14 void quit(const char *text)
15 {
16 err(errno, text);
17 }
18
sched_text(int scheduler)19 char *sched_text(int scheduler)
20 {
21 switch(scheduler)
22 {
23 case SCHED_FIFO:
24 return "SCHED_FIFO";
25
26 case SCHED_RR:
27 return "SCHED_RR";
28
29 case SCHED_OTHER:
30 return "SCHED_OTHER";
31
32 default:
33 return "Illegal scheduler value";
34 }
35 }
36
sched_is(int line,struct sched_param * p,int shouldbe)37 int sched_is(int line, struct sched_param *p, int shouldbe)
38 {
39 int scheduler;
40 struct sched_param param;
41
42 /* What scheduler are we running now?
43 */
44 errno = 0;
45 scheduler = sched_getscheduler(0);
46 if (sched_getparam(0, ¶m))
47 quit("sched_getparam");
48
49 if (p)
50 *p = param;
51
52 if (shouldbe != -1 && scheduler != shouldbe)
53 {
54 fprintf(stderr,
55 "At line %d the scheduler should be %s yet it is %s.\n",
56 line, sched_text(shouldbe), sched_text(scheduler));
57
58 exit(-1);
59 }
60
61 return scheduler;
62 }
63