Fix broken test: we can't assume that the current schedule priority range

will overlap with the requested scheduler range, so get the new scheduler
range, and then try to find a different priority. If that fails (to find
a different scheduling range), give up here.
This commit is contained in:
christos 2017-12-21 03:31:43 +00:00
parent 305714948e
commit 1abf1d7802

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_spawnattr.c,v 1.2 2017/12/18 13:18:23 christos Exp $ */
/* $NetBSD: t_spawnattr.c,v 1.3 2017/12/21 03:31:43 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -45,11 +45,8 @@
#define MAX(a, b) (a) > (b) ? (a) : (b)
#define MIN(a, b) (a) > (b) ? (b) : (a)
static int get_different_scheduler(void);
static int get_different_priority(void);
static int
get_different_scheduler()
get_different_scheduler(void)
{
/*
* We don't want to use SCHED_OTHER because it does not have
@ -69,14 +66,12 @@ get_different_scheduler()
}
static int
get_different_priority()
get_different_priority(int scheduler)
{
int scheduler, max, min, new, priority;
int min, max, new, priority;
struct sched_param param;
/* get current schedule policy */
scheduler = sched_getscheduler(0);
/* Get the priority range for the new scheduler */
max = sched_get_priority_max(scheduler);
min = sched_get_priority_min(scheduler);
@ -84,10 +79,13 @@ get_different_priority()
priority = param.sched_priority;
/* new schedule policy */
new = (priority + 1);
if (new > max)
new = min;
for (new = min; new <= max; new++)
if (priority != new)
break;
ATF_REQUIRE_MSG(priority != new, "could not find different priority");
printf("min %d max %d for scheduler %d, returning %d\n",
min, max, scheduler, new);
return new;
}
@ -120,8 +118,9 @@ ATF_TC_BODY(t_spawnattr, tc)
posix_spawnattr_init(&attr);
scheduler = get_different_scheduler();
priority = get_different_priority();
priority = get_different_priority(scheduler);
sp.sched_priority = priority;
printf("using scheduler %d, priority %d\n", scheduler, priority);
sigemptyset(&sig);
sigaddset(&sig, SIGUSR1);