summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2015-09-08 07:15:10 +0000
committerkib <kib@FreeBSD.org>2015-09-08 07:15:10 +0000
commitd894e2ffed5ac27e43558b5eb24237ce0bb66985 (patch)
tree0883a334cf8197646b966ad53887dff1673f1c77
parent19493aa1674ce1e3de78262b5daa7e76ddbaf718 (diff)
downloadFreeBSD-src-d894e2ffed5ac27e43558b5eb24237ce0bb66985.zip
FreeBSD-src-d894e2ffed5ac27e43558b5eb24237ce0bb66985.tar.gz
MFC r287360:
Fix t_spawnattr test for attributes handling by posix_spawn(3). Connect it to the build.
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c59
-rw-r--r--lib/libc/tests/gen/posix_spawn/Makefile2
2 files changed, 33 insertions, 28 deletions
diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
index eb99c41..78313cd 100644
--- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
+++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
@@ -30,6 +30,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/param.h>
#include <atf-c.h>
#include <stdio.h>
#include <stdlib.h>
@@ -42,51 +43,56 @@
#include <unistd.h>
#include <sys/wait.h>
-#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_priority(int scheduler);
+
+static const int schedulers[] = {
+ SCHED_OTHER,
+ SCHED_FIFO,
+ SCHED_RR
+};
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);
+ u_int i;
+ int scheduler;
/* get current schedule policy */
scheduler = sched_getscheduler(0);
+ for (i = 0; i < nitems(schedulers); i++) {
+ if (schedulers[i] == scheduler)
+ break;
+ }
+ ATF_REQUIRE_MSG(i < nitems(schedulers),
+ "Unknown current scheduler %d", scheduler);
/* new scheduler */
- new = (scheduler + 1);
- if (new > max)
- new = min;
-
- return new;
+ i++;
+ if (i >= nitems(schedulers))
+ i = 0;
+ return schedulers[i];
}
static int
-get_different_priority()
+get_different_priority(int scheduler)
{
- int scheduler, max, min, new, priority;
+ int max, min, new, priority;
struct sched_param param;
- /* get current schedule policy */
- scheduler = sched_getscheduler(0);
-
max = sched_get_priority_max(scheduler);
min = sched_get_priority_min(scheduler);
sched_getparam(0, &param);
priority = param.sched_priority;
- /* new schedule policy */
- new = (priority + 1);
+ /*
+ * Change numerical value of the priority, to ensure that it
+ * was set for the spawned child.
+ */
+ new = priority + 1;
if (new > max)
new = min;
-
return new;
}
@@ -119,16 +125,15 @@ 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;
sigemptyset(&sig);
sigaddset(&sig, SIGUSR1);
- posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER |
- POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETPGROUP |
- POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF |
- POSIX_SPAWN_SETSIGDEF);
+ posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER |
+ POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETPGROUP |
+ POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF);
posix_spawnattr_setpgroup(&attr, 0);
posix_spawnattr_setschedparam(&attr, &sp);
posix_spawnattr_setschedpolicy(&attr, scheduler);
diff --git a/lib/libc/tests/gen/posix_spawn/Makefile b/lib/libc/tests/gen/posix_spawn/Makefile
index a1c9b9e..d2dfa54 100644
--- a/lib/libc/tests/gen/posix_spawn/Makefile
+++ b/lib/libc/tests/gen/posix_spawn/Makefile
@@ -10,9 +10,9 @@ TESTSDIR= ${TESTSBASE}/lib/libc/gen/posix_spawn
BINDIR= ${TESTSDIR}
-# TODO: t_spawnattr (fix from pho@ needs additional review)
NETBSD_ATF_TESTS_C= fileactions_test
NETBSD_ATF_TESTS_C+= spawn_test
+NETBSD_ATF_TESTS_C+= spawnattr_test
PROGS= h_fileactions
PROGS+= h_spawn
OpenPOWER on IntegriCloud