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