Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src/tests/lib/libc/gen/posix_spawn Additionally pull up follo...



details:   https://anonhg.NetBSD.org/src/rev/213ae584c0dd
branches:  netbsd-8
changeset: 851832:213ae584c0dd
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Jun 25 12:55:01 2018 +0000

description:
Additionally pull up following revision(s) (requested by maya in ticket #892):

        tests/lib/libc/gen/posix_spawn/t_spawnattr.c: revision 1.2,1.3

Don't use SCHED_OTHER.

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.

diffstat:

 tests/lib/libc/gen/posix_spawn/t_spawnattr.c |  52 ++++++++++++++--------------
 1 files changed, 26 insertions(+), 26 deletions(-)

diffs (92 lines):

diff -r 5d76439aada3 -r 213ae584c0dd tests/lib/libc/gen/posix_spawn/t_spawnattr.c
--- a/tests/lib/libc/gen/posix_spawn/t_spawnattr.c      Sun Jun 24 09:51:46 2018 +0000
+++ b/tests/lib/libc/gen/posix_spawn/t_spawnattr.c      Mon Jun 25 12:55:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_spawnattr.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+/* $NetBSD: t_spawnattr.c,v 1.1.34.1 2018/06/25 12:55:01 martin Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -45,37 +45,33 @@
 #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)
 {
-       int scheduler, max, min, new;
-
-       max = MAX(MAX(SCHED_FIFO, SCHED_OTHER), SCHED_RR);
-       min = MIN(MIN(SCHED_FIFO, SCHED_OTHER), SCHED_RR);
+       /*
+        * We don't want to use SCHED_OTHER because it does not have
+        * different priorities.
+        */
 
        /* get current schedule policy */
-       scheduler = sched_getscheduler(0);
-                                       
-       /* new scheduler */
-       new = (scheduler + 1);
-       if (new > max)
-               new = min;
-                                                               
-       return new;
+       switch (sched_getscheduler(0)) {
+       case SCHED_RR:
+               return SCHED_FIFO;
+       case SCHED_FIFO:
+       case SCHED_OTHER:
+               return SCHED_RR;
+       default:
+               abort();
+       }
 }
 
 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);
 
@@ -83,10 +79,13 @@
        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;
 }
 
@@ -119,8 +118,9 @@
        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);



Home | Main Index | Thread Index | Old Index