Module Name: src
Committed By: christos
Date: Thu Dec 21 03:31:43 UTC 2017
Modified Files:
src/tests/lib/libc/gen/posix_spawn: t_spawnattr.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c
diff -u src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.2 src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.3
--- src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.2 Mon Dec 18 08:18:23 2017
+++ src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c Wed Dec 20 22:31:43 2017
@@ -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);