Module Name:    src
Committed By:   pgoyette
Date:           Thu Jan 13 02:40:44 UTC 2011

Modified Files:
        src/tests/lib/libc: Makefile
        src/tests/lib/libc/gen: Makefile
        src/tests/lib/libc/sys: Makefile
Added Files:
        src/tests/lib/libc/gen: t_randomid.c
        src/tests/lib/libc/sys: t_cerror.c t_clone.c t_context.c
Removed Files:
        src/tests/lib/libc: t_cerror.c t_clone.c t_context.c t_randomid.c

Log Message:
Continuing the (re)organization of the lib/libc atf regression tests


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/tests/lib/libc/Makefile
cvs rdiff -u -r1.2 -r0 src/tests/lib/libc/t_cerror.c
cvs rdiff -u -r1.1 -r0 src/tests/lib/libc/t_clone.c \
    src/tests/lib/libc/t_context.c src/tests/lib/libc/t_randomid.c
cvs rdiff -u -r1.12 -r1.13 src/tests/lib/libc/gen/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/gen/t_randomid.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_cerror.c \
    src/tests/lib/libc/sys/t_clone.c src/tests/lib/libc/sys/t_context.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/Makefile
diff -u src/tests/lib/libc/Makefile:1.33 src/tests/lib/libc/Makefile:1.34
--- src/tests/lib/libc/Makefile:1.33	Thu Jan 13 01:56:44 2011
+++ src/tests/lib/libc/Makefile	Thu Jan 13 02:40:43 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.33 2011/01/13 01:56:44 pgoyette Exp $
+# $NetBSD: Makefile,v 1.34 2011/01/13 02:40:43 pgoyette Exp $
 
 .include <bsd.own.mk>
 .include <bsd.sys.mk>
@@ -12,14 +12,10 @@
 
 TESTSDIR=	${TESTSBASE}/lib/libc
 
-TESTS_C+=	t_cerror
-TESTS_C+=	t_clone
-TESTS_C+=	t_context
 TESTS_C+=	t_convfp
 TESTS_C+=	t_gdtoa
 TESTS_C+=	t_hsearch
 TESTS_C+=	t_inet
 TESTS_C+=	t_ptm
-TESTS_C+=	t_randomid
 
 .include <bsd.test.mk>

Index: src/tests/lib/libc/gen/Makefile
diff -u src/tests/lib/libc/gen/Makefile:1.12 src/tests/lib/libc/gen/Makefile:1.13
--- src/tests/lib/libc/gen/Makefile:1.12	Sun Jan  2 18:28:36 2011
+++ src/tests/lib/libc/gen/Makefile	Thu Jan 13 02:40:43 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.12 2011/01/02 18:28:36 pgoyette Exp $
+# $NetBSD: Makefile,v 1.13 2011/01/13 02:40:43 pgoyette Exp $
 
 .include <bsd.own.mk>
 
@@ -10,6 +10,7 @@
 TESTS_C+=	t_glob_star
 TESTS_C+=	t_humanize_number
 TESTS_C+=	t_ldexp
+TESTS_C+=	t_randomid
 TESTS_C+=	t_rbstress
 TESTS_C+=	t_siginfo
 TESTS_C+=	t_syslog_pthread

Index: src/tests/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.1 src/tests/lib/libc/sys/Makefile:1.2
--- src/tests/lib/libc/sys/Makefile:1.1	Mon Jan 10 04:57:56 2011
+++ src/tests/lib/libc/sys/Makefile	Thu Jan 13 02:40:44 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2011/01/10 04:57:56 christos Exp $
+# $NetBSD: Makefile,v 1.2 2011/01/13 02:40:44 pgoyette Exp $
 
 MKMAN=	no
 
@@ -6,6 +6,9 @@
 
 TESTSDIR=		${TESTSBASE}/lib/libc/sys
 
+TESTS_C+=		t_cerror
+TESTS_C+=		t_clone
+TESTS_C+=		t_context
 TESTS_C=		t_sigqueue
 
 .include <bsd.test.mk>

Added files:

Index: src/tests/lib/libc/gen/t_randomid.c
diff -u /dev/null src/tests/lib/libc/gen/t_randomid.c:1.1
--- /dev/null	Thu Jan 13 02:40:44 2011
+++ src/tests/lib/libc/gen/t_randomid.c	Thu Jan 13 02:40:43 2011
@@ -0,0 +1,93 @@
+/* $NetBSD: t_randomid.c,v 1.1 2011/01/13 02:40:43 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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 <sys/types.h>
+
+#include <assert.h>
+#include <inttypes.h>
+#include <randomid.h>
+#include <stdio.h>
+#include <string.h>
+
+#define	PERIOD		30000
+
+uint64_t last[65536];
+
+ATF_TC(randomid);
+
+ATF_TC_HEAD(randomid, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Check randomid(3)");
+}
+
+ATF_TC_BODY(randomid, tc)
+{
+	static randomid_t ctx = NULL;
+	uint64_t lowest, n, diff;
+	uint16_t id;
+
+	memset(last, 0, sizeof(last));
+	ctx = randomid_new(16, (long)3600);
+
+	lowest = UINT64_MAX;
+
+	for (n = 0; n < 1000000; n++) {
+		id = randomid(ctx);
+
+		if (last[id] > 0) {
+			diff = n - last[id];
+
+			if (diff <= lowest) {
+				if (lowest != UINT64_MAX)
+					printf("id %5d: last call at %9lld, "
+					    "current call %9lld (diff %5lld)"
+					    ", lowest %lld\n",
+					    id, last[id], n, diff, lowest);
+
+				ATF_REQUIRE_MSG(diff >= PERIOD,
+				    "diff (%"PRIu64") less than minimum "
+				    "period (%d)", diff, PERIOD);
+
+				lowest = diff;
+			}
+		}
+
+		last[id] = n;
+	}
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, randomid);
+
+	return atf_no_error();
+}

Index: src/tests/lib/libc/sys/t_cerror.c
diff -u /dev/null src/tests/lib/libc/sys/t_cerror.c:1.1
--- /dev/null	Thu Jan 13 02:40:44 2011
+++ src/tests/lib/libc/sys/t_cerror.c	Thu Jan 13 02:40:44 2011
@@ -0,0 +1,115 @@
+/* $NetBSD: t_cerror.c,v 1.1 2011/01/13 02:40:44 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * Copyright (c) 2003 Christopher G. Demetriou
+ * All rights reserved.
+ * 
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *          This product includes software developed for the
+ *          NetBSD Project.  See http://www.NetBSD.org/ for
+ *          information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ * 
+ * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_cerror.c,v 1.1 2011/01/13 02:40:44 pgoyette Exp $");
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+ATF_TC(cerror_32);
+ATF_TC_HEAD(cerror_32, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+		"Checks that libc's cerror (error handler) "
+		"correctly handles 32-bit error codes");
+}
+ATF_TC_BODY(cerror_32, tc)
+{
+	/* Make sure file desc 4 is closed. */
+	(void)close(4);
+
+	/* Check error and 32-bit return code.*/
+	errno = 0;
+	ATF_REQUIRE_EQ(close(4), -1);
+	ATF_REQUIRE_EQ(errno, EBADF);
+}
+
+ATF_TC(cerror_64);
+ATF_TC_HEAD(cerror_64, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+		"Checks that libc's cerror (error handler) "
+		"correctly handles 64-bit error codes");
+}
+ATF_TC_BODY(cerror_64, tc)
+{
+	/* Make sure file desc 4 is closed. */
+	(void)close(4);
+
+	/* Check error and 64-bit return code.*/
+	errno = 0;
+	ATF_REQUIRE_EQ(lseek(4, (off_t) 0, SEEK_SET), (off_t) -1);
+	ATF_REQUIRE_EQ(errno, EBADF);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, cerror_32);
+	ATF_TP_ADD_TC(tp, cerror_64);
+
+	return atf_no_error();
+}
Index: src/tests/lib/libc/sys/t_clone.c
diff -u /dev/null src/tests/lib/libc/sys/t_clone.c:1.1
--- /dev/null	Thu Jan 13 02:40:44 2011
+++ src/tests/lib/libc/sys/t_clone.c	Thu Jan 13 02:40:44 2011
@@ -0,0 +1,262 @@
+/* $NetBSD: t_clone.c,v 1.1 2011/01/13 02:40:44 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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 <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_clone.c,v 1.1 2011/01/13 02:40:44 pgoyette Exp $");
+
+#include <sys/mman.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <sched.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#define	STACKSIZE	(8 * 1024)
+#define	FROBVAL		41973
+#define	CHILDEXIT	0xa5
+
+/*
+ * return 1 if the stack grows down, 0 if it grows up.
+ */
+static int
+stackdir(void *p)
+{
+	int val;
+	void *q = &val;
+
+	return p < q ? 0 : 1;
+}
+
+static int
+dummy(void *arg)
+{
+
+	return 0;
+}
+
+ATF_TC(clone);
+
+ATF_TC_HEAD(clone, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Checks clone(2)");
+}
+
+static int
+clone_func(void *arg)
+{
+	long *frobp = arg, diff;
+
+	printf("child: stack ~= %p, frobme = %p\n", &frobp, frobp);
+	fflush(stdout);
+
+	if (frobp[0] != getppid())
+		return 1;
+
+	if (frobp[0] == getpid())
+		return 2;
+
+	diff = labs(frobp[1] - (long) &frobp);
+
+	if (diff > 1024)
+		return 3;
+
+	frobp[1] = FROBVAL;
+
+	return (CHILDEXIT);
+}
+
+ATF_TC_BODY(clone, tc)
+{
+	sigset_t mask;
+	void *allocstack, *stack;
+	pid_t pid;
+	volatile long frobme[2];
+	int stat;
+
+	allocstack = mmap(NULL, STACKSIZE, PROT_READ|PROT_WRITE|PROT_EXEC,
+	    MAP_PRIVATE|MAP_ANON, -1, (off_t) 0);
+
+	ATF_REQUIRE_ERRNO(errno, allocstack != MAP_FAILED);
+
+	stack = (caddr_t) allocstack + STACKSIZE * stackdir(&stat);
+
+	printf("parent: stack = %p, frobme = %p\n", stack, frobme);
+	fflush(stdout);
+
+	frobme[0] = (long)getpid();
+	frobme[1] = (long)stack;
+
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGUSR1);
+
+	ATF_REQUIRE_ERRNO(errno, sigprocmask(SIG_BLOCK, &mask, NULL) != -1);
+
+	switch (pid = __clone(clone_func, stack,
+	    CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGUSR1,
+	    __UNVOLATILE(frobme))) {
+	case 0:
+		atf_tc_fail("clone() returned 0");
+		/*NOTREACHED*/
+	case -1:
+		atf_tc_fail("clone() failed: %s", strerror(errno));
+		/*NOTREACHED*/
+	default:
+		while (waitpid(pid, &stat, __WCLONE) != pid)
+			continue;
+	}
+
+	ATF_REQUIRE_MSG(WIFEXITED(stat) != 0, "child didn't exit");
+
+	printf("parent: childexit = 0x%x, frobme = %ld\n",
+	    WEXITSTATUS(stat), frobme[1]);
+
+	switch (WEXITSTATUS(stat)) {
+	case CHILDEXIT:
+		ATF_REQUIRE_EQ(frobme[1], FROBVAL);
+		break;
+	case 1:
+		atf_tc_fail("child: argument does not contain parent's pid");
+		/*NOTREACHED*/
+	case 2:
+		atf_tc_fail("child: called in parent's pid");
+		/*NOTREACHED*/
+	case 3:
+		atf_tc_fail("child: called with bad stack");
+		/*NOTREACHED*/
+	default:
+		atf_tc_fail("child returned unknown code: %d",
+		    WEXITSTATUS(stat));
+		/*NOTREACHED*/
+	}
+
+	ATF_REQUIRE_ERRNO(errno, munmap(allocstack, STACKSIZE) != -1);
+}
+
+ATF_TC(null_stack);
+
+ATF_TC_HEAD(null_stack, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	    "Checks that clone(2) fails when stack pointer is NULL");
+}
+
+ATF_TC_BODY(null_stack, tc)
+{
+	int rv;
+
+	rv = __clone(dummy, NULL,
+	    CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD, NULL);
+
+	ATF_REQUIRE_EQ(rv, -1);
+	ATF_REQUIRE_EQ(errno, EINVAL);
+}
+
+ATF_TC(null_func);
+
+ATF_TC_HEAD(null_func, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	    "Checks that clone(2) fails when function pointer is NULL");
+}
+
+ATF_TC_BODY(null_func, tc)
+{
+	void *allocstack, *stack;
+	int rv, stat;
+
+	allocstack = mmap(NULL, STACKSIZE, PROT_READ|PROT_WRITE|PROT_EXEC,
+	    MAP_PRIVATE|MAP_ANON, -1, (off_t) 0);
+	ATF_REQUIRE_ERRNO(errno, allocstack != MAP_FAILED);
+	stack = (caddr_t) allocstack + STACKSIZE * stackdir(&stat);
+
+	errno = 0;
+	rv = __clone(0, stack,
+	    CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD, NULL);
+
+	ATF_REQUIRE_EQ(rv, -1);
+	ATF_REQUIRE_EQ(errno, EINVAL);
+
+	ATF_REQUIRE_ERRNO(errno, munmap(allocstack, STACKSIZE) != -1);
+}
+
+ATF_TC(out_of_proc);
+
+ATF_TC_HEAD(out_of_proc, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+		"Checks that clone(2) fails when running out of processes");
+	atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+
+ATF_TC_BODY(out_of_proc, tc)
+{
+	struct rlimit rl;
+	int rv;
+
+	ATF_REQUIRE_ERRNO(errno, getrlimit(RLIMIT_NPROC, &rl) != -1);
+
+	rl.rlim_cur = 0;
+	rl.rlim_max = 0;
+
+	ATF_REQUIRE_ERRNO(errno, setrlimit(RLIMIT_NPROC, &rl) != -1);
+
+	errno = 0;
+	rv = __clone(dummy, malloc(10240),
+	    CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD, (void *)&rl);
+
+	ATF_REQUIRE_EQ(rv, -1);
+	ATF_REQUIRE_EQ(errno, EAGAIN);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, clone);
+	ATF_TP_ADD_TC(tp, null_stack);
+	ATF_TP_ADD_TC(tp, null_func);
+	ATF_TP_ADD_TC(tp, out_of_proc);
+
+	return atf_no_error();
+}
Index: src/tests/lib/libc/sys/t_context.c
diff -u /dev/null src/tests/lib/libc/sys/t_context.c:1.1
--- /dev/null	Thu Jan 13 02:40:44 2011
+++ src/tests/lib/libc/sys/t_context.c	Thu Jan 13 02:40:44 2011
@@ -0,0 +1,102 @@
+/* $NetBSD: t_context.c,v 1.1 2011/01/13 02:40:44 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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 <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_context.c,v 1.1 2011/01/13 02:40:44 pgoyette Exp $");
+
+#include <ucontext.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include <atf-c.h>
+
+#define STACKSZ (10*1024)
+#define DEPTH 3
+
+static int calls;
+
+static void
+run(int n, ...)
+{
+	va_list va;
+	int i, ia;
+
+	ATF_REQUIRE_EQ(n, DEPTH - calls - 1);
+
+	va_start(va, n);
+	for (i = 0; i < 9; i++) {
+		ia = va_arg(va, int);
+		ATF_REQUIRE_EQ(i, ia);
+	}
+	va_end(va);
+
+	calls++;
+}
+
+ATF_TC(context);
+
+ATF_TC_HEAD(context, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	"Checks get/make/setcontext(), context linking via uc_link(), "
+	    "and argument passing to the new context");
+}
+
+ATF_TC_BODY(context, tc)
+{
+	ucontext_t uc[DEPTH];
+	ucontext_t save;
+	volatile int i = 0; /* avoid longjmp clobbering */
+
+	for (i = 0; i < DEPTH; ++i) {
+		ATF_REQUIRE_EQ(getcontext(&uc[i]), 0);
+
+		uc[i].uc_stack.ss_sp = malloc(STACKSZ);
+		uc[i].uc_stack.ss_size = STACKSZ;
+		uc[i].uc_link = (i > 0) ? &uc[i - 1] : &save;
+
+		makecontext(&uc[i], (void *)run, 10, i,
+			0, 1, 2, 3, 4, 5, 6, 7, 8);
+	}
+
+	ATF_REQUIRE_EQ(getcontext(&save), 0);
+
+	if (calls == 0)
+		ATF_REQUIRE_EQ(setcontext(&uc[DEPTH-1]), 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, context);
+
+	return atf_no_error();
+}

Reply via email to