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 * $FreeBSD: releng/10.3/tools/regression/p1003_1b/prutil.c 289954 2015-10-25 22:30:45Z ngie $
13 */
14void quit(const char *text)
15{
16	err(errno, "%s", text);
17}
18
19char *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
37int 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, &param))
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