Module Name:    src
Committed By:   martin
Date:           Mon Feb 13 21:03:08 UTC 2012

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/etc/mtree: NetBSD.dist.tests
        src/tests/kernel: Makefile
        src/tests/lib/libc/gen: Makefile
Added Files:
        src/tests/lib/libc/gen/posix_spawn: Makefile Makefile.inc
            h_fileactions.c h_nonexec.sh h_spawn.c h_spawnattr.c
            t_fileactions.c t_spawn.c t_spawnattr.c
Removed Files:
        src/tests/kernel/posix_spawn: Makefile Makefile.inc h_fileactions.c
            h_nonexec.sh h_spawn.c h_spawnattr.c t_fileactions.c t_spawn.c
            t_spawnattr.c

Log Message:
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng


To generate a diff of this commit:
cvs rdiff -u -r1.435 -r1.436 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.59 -r1.60 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r1.23 -r1.24 src/tests/kernel/Makefile
cvs rdiff -u -r1.1 -r0 src/tests/kernel/posix_spawn/Makefile \
    src/tests/kernel/posix_spawn/Makefile.inc \
    src/tests/kernel/posix_spawn/h_fileactions.c \
    src/tests/kernel/posix_spawn/h_nonexec.sh \
    src/tests/kernel/posix_spawn/h_spawn.c \
    src/tests/kernel/posix_spawn/h_spawnattr.c \
    src/tests/kernel/posix_spawn/t_fileactions.c \
    src/tests/kernel/posix_spawn/t_spawn.c \
    src/tests/kernel/posix_spawn/t_spawnattr.c
cvs rdiff -u -r1.33 -r1.34 src/tests/lib/libc/gen/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/gen/posix_spawn/Makefile \
    src/tests/lib/libc/gen/posix_spawn/Makefile.inc \
    src/tests/lib/libc/gen/posix_spawn/h_fileactions.c \
    src/tests/lib/libc/gen/posix_spawn/h_nonexec.sh \
    src/tests/lib/libc/gen/posix_spawn/h_spawn.c \
    src/tests/lib/libc/gen/posix_spawn/h_spawnattr.c \
    src/tests/lib/libc/gen/posix_spawn/t_fileactions.c \
    src/tests/lib/libc/gen/posix_spawn/t_spawn.c \
    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/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.435 src/distrib/sets/lists/tests/mi:1.436
--- src/distrib/sets/lists/tests/mi:1.435	Sat Feb 11 23:31:23 2012
+++ src/distrib/sets/lists/tests/mi	Mon Feb 13 21:03:06 2012
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.435 2012/02/11 23:31:23 martin Exp $
+# $NetBSD: mi,v 1.436 2012/02/13 21:03:06 martin Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -322,13 +322,13 @@
 ./usr/libdata/debug/usr/tests/kernel/kqueue/write/t_fifo.debug		tests-kernel-tests	debug,atf
 ./usr/libdata/debug/usr/tests/kernel/kqueue/write/t_pipe.debug		tests-kernel-tests	debug,atf
 ./usr/libdata/debug/usr/tests/kernel/kqueue/write/t_ttypty.debug	tests-kernel-tests	debug,atf
-./usr/libdata/debug/usr/tests/kernel/posix_spawn			tests-kernel-tests
-./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_spawn.debug		tests-kernel-tests	debug,atf
-./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_spawnattr.debug	tests-kernel-tests	debug,atf
-./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_fileactions.debug	tests-kernel-tests	debug,atf
-./usr/libdata/debug/usr/tests/kernel/posix_spawn/h_spawn.debug		tests-kernel-tests	debug,atf
-./usr/libdata/debug/usr/tests/kernel/posix_spawn/h_fileactions.debug	tests-kernel-tests	debug,atf
-./usr/libdata/debug/usr/tests/kernel/posix_spawn/h_spawnattr.debug	tests-kernel-tests	debug,atf
+./usr/libdata/debug/usr/tests/kernel/posix_spawn			tests-kernel-tests	obsolete
+./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_spawn.debug		tests-kernel-tests	obsolete
+./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_spawnattr.debug	tests-kernel-tests	obsolete
+./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_fileactions.debug	tests-kernel-tests	obsolete
+./usr/libdata/debug/usr/tests/kernel/posix_spawn/h_spawn.debug		tests-kernel-tests	obsolete
+./usr/libdata/debug/usr/tests/kernel/posix_spawn/h_fileactions.debug	tests-kernel-tests	obsolete
+./usr/libdata/debug/usr/tests/kernel/posix_spawn/h_spawnattr.debug	tests-kernel-tests	obsolete
 ./usr/libdata/debug/usr/tests/kernel/t_extattrctl.debug			tests-kernel-tests	debug,atf
 ./usr/libdata/debug/usr/tests/kernel/t_extent.debug			tests-kernel-tests	debug,atf
 ./usr/libdata/debug/usr/tests/kernel/t_filedesc.debug			tests-kernel-tests	debug,atf
@@ -365,6 +365,13 @@
 ./usr/libdata/debug/usr/tests/lib/libc/db				tests-lib-debug
 ./usr/libdata/debug/usr/tests/lib/libc/db/h_db.debug			tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen				tests-lib-debug
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn			tests-kernel-tests
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn/t_spawn.debug		tests-kernel-tests	debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn/t_spawnattr.debug	tests-kernel-tests	debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn/t_fileactions.debug	tests-kernel-tests	debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn/h_spawn.debug		tests-kernel-tests	debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn/h_fileactions.debug	tests-kernel-tests	debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn/h_spawnattr.debug	tests-kernel-tests	debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_alarm.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_assert.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_basedirname.debug		tests-lib-debug		debug,atf
@@ -1897,16 +1904,16 @@
 ./usr/tests/kernel/kqueue/write/t_fifo		tests-kernel-tests		atf
 ./usr/tests/kernel/kqueue/write/t_pipe		tests-kernel-tests		atf
 ./usr/tests/kernel/kqueue/write/t_ttypty	tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn			tests-kernel-tests
-./usr/tests/kernel/posix_spawn/Atffile		tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/t_spawn		tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/t_spawnattr	tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/t_fileactions	tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/h_spawn		tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/h_spawnattr	tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/h_fileactions	tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/h_nonexec	tests-kernel-tests		atf
-./usr/tests/kernel/posix_spawn/h_zero		tests-kernel-tests		atf
+./usr/tests/kernel/posix_spawn			tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/Atffile		tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/t_spawn		tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/t_spawnattr	tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/t_fileactions	tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/h_spawn		tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/h_spawnattr	tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/h_fileactions	tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/h_nonexec	tests-kernel-tests		obsolete
+./usr/tests/kernel/posix_spawn/h_zero		tests-kernel-tests		obsolete
 ./usr/tests/kernel/t_extattrctl			tests-kernel-tests		atf
 ./usr/tests/kernel/t_extent			tests-kernel-tests		atf
 ./usr/tests/kernel/t_filedesc			tests-kernel-tests		atf
@@ -1955,6 +1962,16 @@
 ./usr/tests/lib/libc/db/t_db			tests-lib-tests		atf
 ./usr/tests/lib/libc/gen			tests-lib-tests
 ./usr/tests/lib/libc/gen/Atffile		tests-lib-tests		atf
+./usr/tests/lib/libc/gen/posix_spawn			tests-kernel-tests
+./usr/tests/lib/libc/gen/posix_spawn/Atffile		tests-kernel-tests	atf
+./usr/tests/lib/libc/gen/posix_spawn/t_spawn		tests-kernel-tests	atf
+./usr/tests/lib/libc/gen/posix_spawn/t_spawnattr	tests-kernel-tests	atf
+./usr/tests/lib/libc/gen/posix_spawn/t_fileactions	tests-kernel-tests	atf
+./usr/tests/lib/libc/gen/posix_spawn/h_spawn		tests-kernel-tests	atf
+./usr/tests/lib/libc/gen/posix_spawn/h_spawnattr	tests-kernel-tests	atf
+./usr/tests/lib/libc/gen/posix_spawn/h_fileactions	tests-kernel-tests	atf
+./usr/tests/lib/libc/gen/posix_spawn/h_nonexec	tests-kernel-tests		atf
+./usr/tests/lib/libc/gen/posix_spawn/h_zero	tests-kernel-tests		atf
 ./usr/tests/lib/libc/gen/t_alarm		tests-lib-tests		atf
 ./usr/tests/lib/libc/gen/t_assert		tests-lib-tests		atf
 ./usr/tests/lib/libc/gen/t_basedirname		tests-lib-tests		atf

Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.59 src/etc/mtree/NetBSD.dist.tests:1.60
--- src/etc/mtree/NetBSD.dist.tests:1.59	Sat Feb 11 23:31:23 2012
+++ src/etc/mtree/NetBSD.dist.tests	Mon Feb 13 21:03:06 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.59 2012/02/11 23:31:23 martin Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.60 2012/02/13 21:03:06 martin Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -44,7 +44,6 @@
 ./usr/libdata/debug/usr/tests/kernel/kqueue
 ./usr/libdata/debug/usr/tests/kernel/kqueue/read
 ./usr/libdata/debug/usr/tests/kernel/kqueue/write
-./usr/libdata/debug/usr/tests/kernel/posix_spawn
 ./usr/libdata/debug/usr/tests/kernel/tty
 ./usr/libdata/debug/usr/tests/lib
 ./usr/libdata/debug/usr/tests/lib/csu
@@ -52,6 +51,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc
 ./usr/libdata/debug/usr/tests/lib/libc/db
 ./usr/libdata/debug/usr/tests/lib/libc/gen
+./usr/libdata/debug/usr/tests/lib/libc/gen/posix_spawn
 ./usr/libdata/debug/usr/tests/lib/libc/hash
 ./usr/libdata/debug/usr/tests/lib/libc/locale
 ./usr/libdata/debug/usr/tests/lib/libc/inet
@@ -169,7 +169,6 @@
 ./usr/tests/kernel/kqueue
 ./usr/tests/kernel/kqueue/read
 ./usr/tests/kernel/kqueue/write
-./usr/tests/kernel/posix_spawn
 ./usr/tests/kernel/tty
 ./usr/tests/lib
 ./usr/tests/lib/csu
@@ -177,6 +176,7 @@
 ./usr/tests/lib/libc
 ./usr/tests/lib/libc/db
 ./usr/tests/lib/libc/gen
+./usr/tests/lib/libc/gen/posix_spawn
 ./usr/tests/lib/libc/hash
 ./usr/tests/lib/libc/hash/data
 ./usr/tests/lib/libc/locale

Index: src/tests/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.23 src/tests/kernel/Makefile:1.24
--- src/tests/kernel/Makefile:1.23	Sat Feb 11 23:31:24 2012
+++ src/tests/kernel/Makefile	Mon Feb 13 21:03:06 2012
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.23 2012/02/11 23:31:24 martin Exp $
+# $NetBSD: Makefile,v 1.24 2012/02/13 21:03:06 martin Exp $
 
 NOMAN=		# defined
 
@@ -6,7 +6,7 @@ NOMAN=		# defined
 
 TESTSDIR=	${TESTSBASE}/kernel
 
-TESTS_SUBDIRS=	posix_spawn kqueue tty
+TESTS_SUBDIRS=	kqueue tty
 
 TESTS_C=	t_lock
 TESTS_C+=	t_lwpctl

Index: src/tests/lib/libc/gen/Makefile
diff -u src/tests/lib/libc/gen/Makefile:1.33 src/tests/lib/libc/gen/Makefile:1.34
--- src/tests/lib/libc/gen/Makefile:1.33	Tue Nov  8 05:47:00 2011
+++ src/tests/lib/libc/gen/Makefile	Mon Feb 13 21:03:08 2012
@@ -1,9 +1,11 @@
-# $NetBSD: Makefile,v 1.33 2011/11/08 05:47:00 jruoho Exp $
+# $NetBSD: Makefile,v 1.34 2012/02/13 21:03:08 martin Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=	${TESTSBASE}/lib/libc/gen
 
+TESTS_SUBDIRS=	posix_spawn
+
 TESTS_C+=	t_alarm
 TESTS_C+=	t_assert
 TESTS_C+=	t_basedirname

Added files:

Index: src/tests/lib/libc/gen/posix_spawn/Makefile
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/Makefile:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/Makefile	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,27 @@
+# $NetBSD: Makefile,v 1.1 2012/02/13 21:03:08 martin Exp $
+
+NOMAN=		# defined
+
+.include <bsd.own.mk>
+
+TESTSDIR=	${TESTSBASE}/lib/libc/gen/posix_spawn
+
+TESTS_C=	t_spawn
+TESTS_C+=	t_fileactions
+TESTS_C+=	t_spawnattr
+
+BINDIR=		${TESTSDIR}
+SCRIPTSDIR=	${TESTSDIR}
+
+PROGS=		h_fileactions
+PROGS+=		h_spawn
+PROGS+=		h_spawnattr
+SCRIPTS=	h_nonexec h_zero
+
+h_zero:
+	dd if=/dev/zero of=h_zero bs=1k count=2
+	chmod a+x h_zero
+
+CLEANFILES+=	h_nonexec h_zero
+
+.include <bsd.test.mk>
Index: src/tests/lib/libc/gen/posix_spawn/Makefile.inc
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/Makefile.inc:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/Makefile.inc	Mon Feb 13 21:03:08 2012
@@ -0,0 +1 @@
+.include "../Makefile.inc"
Index: src/tests/lib/libc/gen/posix_spawn/h_fileactions.c
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/h_fileactions.c:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/h_fileactions.c	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,104 @@
+/* $NetBSD: h_fileactions.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles Zhang <[email protected]> and
+ * Martin Husemann <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#define BUFSIZE	16
+
+/*
+ * This checks (hardcoded) the assumptions that are setup from the
+ * main test program via posix spawn file actions.
+ * Program exits with EXIT_SUCCESS or EXIT_FAILURE accordingly
+ * (and does some stderr diagnostics in case of errors).
+ */
+int
+main(int argc, char **argv)
+{
+	int res = EXIT_SUCCESS;
+	char buf[BUFSIZE];
+	struct stat sb0, sb1;
+
+	strcpy(buf, "test...");
+	/* file desc 3 should be closed via addclose */
+	if (read(3, buf, BUFSIZE) != -1 || errno != EBADF) {
+		fprintf(stderr, "%s: filedesc 3 is not closed\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+	/* file desc 4 should be closed via closeonexec */
+	if (read(4, buf, BUFSIZE) != -1 || errno != EBADF) {
+		fprintf(stderr, "%s: filedesc 4 is not closed\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+	/* file desc 5 remains open */
+	if (write(5, buf, BUFSIZE) <= 0) {
+		fprintf(stderr, "%s: could not write to filedesc 5\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+	/* file desc 6 should be open (via addopen) */
+	if (write(6, buf, BUFSIZE) <= 0) {
+		fprintf(stderr, "%s: could not write to filedesc 6\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+	/* file desc 7 should refer to stdout */
+	fflush(stdout);
+	if (fstat(fileno(stdout), &sb0) != 0) {
+		fprintf(stderr, "%s: could not fstat stdout\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+	if (fstat(7, &sb1) != 0) {
+		fprintf(stderr, "%s: could not fstat filedesc 7\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+	if (write(7, buf, strlen(buf)) <= 0) {
+		fprintf(stderr, "%s: could not write to filedesc 7\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+	if (memcmp(&sb0, &sb1, sizeof sb0) != 0) {
+		fprintf(stderr, "%s: stat results differ\n", getprogname());
+		res = EXIT_FAILURE;
+	}
+
+	return res;
+}
+
Index: src/tests/lib/libc/gen/posix_spawn/h_nonexec.sh
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/h_nonexec.sh:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/h_nonexec.sh	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,3 @@
+#! /nonexistent
+
+# this is just a dummy script, trying to be non-executable
Index: src/tests/lib/libc/gen/posix_spawn/h_spawn.c
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/h_spawn.c:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/h_spawn.c	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,50 @@
+/* $NetBSD: h_spawn.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles Zhang <[email protected]> and
+ * Martin Husemann <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, char **argv)
+{
+	unsigned long ret;
+	char *endp;
+
+	if (argc < 2) {
+		fprintf(stderr, "usage:\n\t%s (retcode)\n", getprogname());
+		exit(255);
+	}
+	ret = strtoul(argv[1], &endp, 10);
+
+	fprintf(stderr, "%s exiting with status %lu\n", getprogname(), ret);
+	return ret;
+}
Index: src/tests/lib/libc/gen/posix_spawn/h_spawnattr.c
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/h_spawnattr.c:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/h_spawnattr.c	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,90 @@
+/* $NetBSD: h_spawnattr.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles Zhang <[email protected]> and
+ * Martin Husemann <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+/*
+ * Helper to test the hardcoded assumptions from t_spawnattr.c
+ * Exit with apropriate exit status and print diagnostics to
+ * stderr explaining what is wrong.
+ */
+int
+main(int argc, char **argv)
+{
+	int parent_pipe, res = EXIT_SUCCESS;
+	sigset_t sig;
+	struct sigaction act;
+	ssize_t rd;
+	char tmp;
+
+	sigemptyset(&sig);
+	if (sigprocmask(0, NULL, &sig) < 0) {
+		fprintf(stderr, "%s: sigprocmask error\n", getprogname());
+		res = EXIT_FAILURE;
+	}
+	if (!sigismember(&sig, SIGUSR1)) {
+		fprintf(stderr, "%s: SIGUSR not in procmask\n", getprogname());
+		res = EXIT_FAILURE;
+	}
+	if (sigaction(SIGUSR1, NULL, &act) < 0) {
+		fprintf(stderr, "%s: sigaction error\n", getprogname());
+		res = EXIT_FAILURE;
+	}
+	if (act.sa_sigaction != (void *)SIG_DFL) {
+		fprintf(stderr, "%s: SIGUSR1 action != SIG_DFL\n",
+		    getprogname());
+		res = EXIT_FAILURE;
+	}
+
+	if (argc >= 2) {
+		parent_pipe = atoi(argv[1]);
+		if (parent_pipe > 2) {
+			printf("%s: waiting for command from parent on pipe "
+			    "%d\n", getprogname(), parent_pipe);
+			rd = read(parent_pipe, &tmp, 1);
+			if (rd == 1) {
+				printf("%s: got command %c from parent\n",
+				    getprogname(), tmp);
+			} else if (rd == -1) {
+				printf("%s: %d is no pipe, errno %d\n",
+				    getprogname(), parent_pipe, errno);
+				res = EXIT_FAILURE;
+			}
+		}
+	}
+
+	return res;
+}
Index: src/tests/lib/libc/gen/posix_spawn/t_fileactions.c
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/t_fileactions.c:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/t_fileactions.c	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,92 @@
+/* $NetBSD: t_fileactions.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles Zhang <[email protected]> and
+ * Martin Husemann <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <spawn.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+ATF_TC(t_spawn_fileactions);
+
+ATF_TC_HEAD(t_spawn_fileactions, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Tests posix_spawn with fileactions");
+}
+
+ATF_TC_BODY(t_spawn_fileactions, tc)
+{
+	int fd1, fd2, fd3, status, err;
+	pid_t pid;
+	char * const args[2] = { __UNCONST("h_fileactions"), NULL };
+	char helper[FILENAME_MAX];
+	posix_spawn_file_actions_t fa;
+
+	posix_spawn_file_actions_init(&fa);
+
+	closefrom(fileno(stderr)+1);
+
+	fd1 = open("/dev/null", O_RDONLY);
+	ATF_REQUIRE(fd1 == 3);
+
+	fd2 = open("/dev/null", O_WRONLY, O_CLOEXEC);
+	ATF_REQUIRE(fd2 == 4);
+
+	fd3 = open("/dev/null", O_WRONLY);
+	ATF_REQUIRE(fd3 == 5);
+
+	posix_spawn_file_actions_addclose(&fa, fd1);
+	posix_spawn_file_actions_addopen(&fa, 6, "/dev/null", O_RDWR, 0);
+	posix_spawn_file_actions_adddup2(&fa, 1, 7); 
+
+	snprintf(helper, sizeof helper, "%s/h_fileactions",
+	    atf_tc_get_config_var(tc, "srcdir"));
+	err = posix_spawn(&pid, helper, &fa, NULL, args, NULL);
+	ATF_REQUIRE(err == 0);
+
+	waitpid(pid, &status, 0);
+	ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
+
+	posix_spawn_file_actions_destroy(&fa);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, t_spawn_fileactions);
+
+	return atf_no_error();
+}
Index: src/tests/lib/libc/gen/posix_spawn/t_spawn.c
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/t_spawn.c:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/t_spawn.c	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,184 @@
+/* $NetBSD: t_spawn.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles Zhang <[email protected]> and
+ * Martin Husemann <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include <atf-c.h>
+#include <spawn.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/wait.h>
+
+ATF_TC(t_spawn_ls);
+
+ATF_TC_HEAD(t_spawn_ls, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Tests a simple posix_spawn executing /bin/ls");
+}
+
+ATF_TC_BODY(t_spawn_ls, tc)
+{
+	char * const args[] = { __UNCONST("ls"), __UNCONST("-la"), NULL };
+	int err;
+
+	err = posix_spawn(NULL, "/bin/ls", NULL, NULL, args, NULL);
+	ATF_REQUIRE(err == 0);
+}
+
+ATF_TC(t_spawnp_ls);
+
+ATF_TC_HEAD(t_spawnp_ls, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Tests a simple posix_spawnp executing ls via $PATH");
+}
+
+ATF_TC_BODY(t_spawnp_ls, tc)
+{
+	char * const args[] = { __UNCONST("ls"), __UNCONST("-la"), NULL };
+	int err;
+
+	err = posix_spawnp(NULL, "ls", NULL, NULL, args, NULL);
+	ATF_REQUIRE(err == 0);
+}
+
+ATF_TC(t_spawn_zero);
+
+ATF_TC_HEAD(t_spawn_zero, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "posix_spawn an invalid binary");
+}
+
+ATF_TC_BODY(t_spawn_zero, tc)
+{
+	char buf[FILENAME_MAX];
+	char * const args[] = { __UNCONST("h_zero"), NULL };
+	int err;
+
+	snprintf(buf, sizeof buf, "%s/h_zero", atf_tc_get_config_var(tc, "srcdir"));
+	err = posix_spawn(NULL, buf, NULL, NULL, args, NULL);
+	ATF_REQUIRE_MSG(err == ENOEXEC, "expected error %d, got %d when spawning %s", ENOEXEC, err, buf);
+}
+
+ATF_TC(t_spawn_missing);
+
+ATF_TC_HEAD(t_spawn_missing, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "posix_spawn a non existant binary");
+}
+
+ATF_TC_BODY(t_spawn_missing, tc)
+{
+	char buf[FILENAME_MAX];
+	char * const args[] = { __UNCONST("h_nonexist"), NULL };
+	int err;
+
+	snprintf(buf, sizeof buf, "%s/h_nonexist",
+	    atf_tc_get_config_var(tc, "srcdir"));
+	err = posix_spawn(NULL, buf, NULL, NULL, args, NULL);
+	ATF_REQUIRE_MSG(err == ENOENT, "expected error %d, got %d when spawning %s", ENOENT, err, buf);
+}
+
+ATF_TC(t_spawn_nonexec);
+
+ATF_TC_HEAD(t_spawn_nonexec, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "posix_spawn a script with non existing interpreter");
+}
+
+ATF_TC_BODY(t_spawn_nonexec, tc)
+{
+	char buf[FILENAME_MAX];
+	char * const args[] = { __UNCONST("h_nonexec"), NULL };
+	int err;
+
+	snprintf(buf, sizeof buf, "%s/h_nonexec",
+	    atf_tc_get_config_var(tc, "srcdir"));
+	err = posix_spawn(NULL, buf, NULL, NULL, args, NULL);
+	ATF_REQUIRE_MSG(err == ENOENT, "expected error %d, got %d when spawning %s", ENOENT, err, buf);
+}
+
+ATF_TC(t_spawn_child);
+
+ATF_TC_HEAD(t_spawn_child, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "posix_spawn a child and get it's return code");
+}
+
+ATF_TC_BODY(t_spawn_child, tc)
+{
+	char buf[FILENAME_MAX];
+	char * const args0[] = { __UNCONST("h_spawn"), __UNCONST("0"), NULL };
+	char * const args1[] = { __UNCONST("h_spawn"), __UNCONST("1"), NULL };
+	char * const args7[] = { __UNCONST("h_spawn"), __UNCONST("7"), NULL };
+	int err, status;
+	pid_t pid;
+
+	snprintf(buf, sizeof buf, "%s/h_spawn",
+	    atf_tc_get_config_var(tc, "srcdir"));
+
+	err = posix_spawn(&pid, buf, NULL, NULL, args0, NULL);
+	ATF_REQUIRE(err == 0);
+	ATF_REQUIRE(pid > 0);
+	waitpid(pid, &status, 0);
+	ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+
+	err = posix_spawn(&pid, buf, NULL, NULL, args1, NULL);
+	ATF_REQUIRE(err == 0);
+	ATF_REQUIRE(pid > 0);
+	waitpid(pid, &status, 0);
+	ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 1);
+
+	err = posix_spawn(&pid, buf, NULL, NULL, args7, NULL);
+	ATF_REQUIRE(err == 0);
+	ATF_REQUIRE(pid > 0);
+	waitpid(pid, &status, 0);
+	ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 7);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, t_spawn_ls);
+	ATF_TP_ADD_TC(tp, t_spawnp_ls);
+	ATF_TP_ADD_TC(tp, t_spawn_zero);
+	ATF_TP_ADD_TC(tp, t_spawn_missing);
+	ATF_TP_ADD_TC(tp, t_spawn_nonexec);
+	ATF_TP_ADD_TC(tp, t_spawn_child);
+
+	return atf_no_error();
+}
Index: src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c
diff -u /dev/null src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.1
--- /dev/null	Mon Feb 13 21:03:09 2012
+++ src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c	Mon Feb 13 21:03:08 2012
@@ -0,0 +1,173 @@
+/* $NetBSD: t_spawnattr.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles Zhang <[email protected]> and
+ * Martin Husemann <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <signal.h>
+#include <spawn.h>
+#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_scheduler()
+{
+	int scheduler, max, min, new;
+
+	max = MAX(MAX(SCHED_FIFO, SCHED_OTHER), SCHED_RR);
+	min = MIN(MIN(SCHED_FIFO, SCHED_OTHER), SCHED_RR);
+
+	/* get current schedule policy */
+	scheduler = sched_getscheduler(0);
+					
+	/* new scheduler */
+	new = (scheduler + 1);
+	if (new > max)
+		new = min;
+								
+	return new;
+}
+
+static int
+get_different_priority()
+{
+	int scheduler, 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);
+	if (new > max)
+		new = min;
+	
+	return new;
+}
+
+ATF_TC(t_spawnattr);
+
+ATF_TC_HEAD(t_spawnattr, tc)
+{
+	atf_tc_set_md_var(tc, "require.user", "root");
+	atf_tc_set_md_var(tc, "descr",
+	    "Tests posix_spawn with scheduler attributes");
+}
+
+ATF_TC_BODY(t_spawnattr, tc)
+{
+	int pid, scheduler, child_scheduler, priority, status, err, pfd[2];
+	char helper_arg[128];
+	char * const args[] = { __UNCONST("h_spawnattr"), helper_arg, NULL };
+	struct sched_param sp, child_sp;
+	sigset_t sig;
+	posix_spawnattr_t attr;
+	char helper[FILENAME_MAX];
+
+	/*
+	 * create a pipe to controll the child
+	 */
+	err = pipe(pfd);
+	ATF_REQUIRE_MSG(err == 0, "could not create pipe, errno %d", errno);
+	sprintf(helper_arg, "%d", pfd[0]);
+
+	posix_spawnattr_init(&attr);
+
+	scheduler = get_different_scheduler();
+	priority = get_different_priority();
+	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_setpgroup(&attr, 0);
+	posix_spawnattr_setschedparam(&attr, &sp);
+	posix_spawnattr_setschedpolicy(&attr, scheduler);
+	posix_spawnattr_setsigmask(&attr, &sig);
+	posix_spawnattr_setsigdefault(&attr, &sig);
+
+	sprintf(helper, "%s/h_spawnattr",
+	    atf_tc_get_config_var(tc, "srcdir"));
+	err = posix_spawn(&pid, helper, NULL, &attr, args, NULL);
+	ATF_REQUIRE_MSG(err == 0, "error %d", err);
+
+	child_scheduler = sched_getscheduler(pid);
+	ATF_REQUIRE_MSG(scheduler == child_scheduler,
+	    "scheduler = %d, child_scheduler = %d, pid %d, errno %d",
+	    scheduler, child_scheduler, pid, errno);
+
+	sched_getparam(pid, &child_sp);
+	ATF_REQUIRE_MSG(child_sp.sched_priority == sp.sched_priority,
+	    "priority is: %d, but we requested: %d",
+	    child_sp.sched_priority, sp.sched_priority);
+
+	ATF_REQUIRE_MSG(pid == getpgid(pid), "child pid: %d, child pgid: %d",
+	    pid, getpgid(pid));
+
+	/* ready, let child go */
+	write(pfd[1], "q", 1);
+	close(pfd[0]);
+	close(pfd[1]);
+
+	/* wait and check result from child */
+	waitpid(pid, &status, 0);
+	ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
+
+	posix_spawnattr_destroy(&attr);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, t_spawnattr);
+
+	return atf_no_error();
+}

Reply via email to