Module Name:    src
Committed By:   pooka
Date:           Mon May 31 23:32:51 UTC 2010

Modified Files:
        src/tests/rump: Atffile Makefile
Added Files:
        src/tests/rump/kernspace: Makefile busypage.c kernspace.h thread.c
            tsleep.c

Log Message:
Add some kernel namespace (i.e. _KERNEL) helpers for regression tests.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/rump/Atffile src/tests/rump/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/rump/kernspace/Makefile \
    src/tests/rump/kernspace/busypage.c src/tests/rump/kernspace/kernspace.h \
    src/tests/rump/kernspace/thread.c src/tests/rump/kernspace/tsleep.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/rump/Atffile
diff -u src/tests/rump/Atffile:1.1 src/tests/rump/Atffile:1.2
--- src/tests/rump/Atffile:1.1	Sat May  2 16:02:19 2009
+++ src/tests/rump/Atffile	Mon May 31 23:32:50 2010
@@ -1,6 +1,6 @@
 Content-Type: application/X-atf-atffile; version="1"
-X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2009/05/02 16:02:19 pooka Exp $"
+X-NetBSD-Id: "$NetBSD: Atffile,v 1.2 2010/05/31 23:32:50 pooka Exp $"
 
 prop: test-suite = "NetBSD"
 
-tp-glob: *
+tp-glob: rumpkern
Index: src/tests/rump/Makefile
diff -u src/tests/rump/Makefile:1.1 src/tests/rump/Makefile:1.2
--- src/tests/rump/Makefile:1.1	Sat May  2 16:02:19 2009
+++ src/tests/rump/Makefile	Mon May 31 23:32:50 2010
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile,v 1.1 2009/05/02 16:02:19 pooka Exp $
+#	$NetBSD: Makefile,v 1.2 2010/05/31 23:32:50 pooka Exp $
 #
 
 .include <bsd.own.mk>
 
 TESTSDIR=	${TESTSBASE}/rump
 
-SUBDIR=	rumpkern
+SUBDIR=	kernspace .WAIT rumpkern
 
 .include <bsd.test.mk>
 .include <bsd.subdir.mk>

Added files:

Index: src/tests/rump/kernspace/Makefile
diff -u /dev/null src/tests/rump/kernspace/Makefile:1.1
--- /dev/null	Mon May 31 23:32:51 2010
+++ src/tests/rump/kernspace/Makefile	Mon May 31 23:32:51 2010
@@ -0,0 +1,13 @@
+#	$NetBSD: Makefile,v 1.1 2010/05/31 23:32:51 pooka Exp $
+#
+
+LIB=	kernspace
+SRCS=	thread.c busypage.c tsleep.c
+
+RUMPTOP=${NETBSDSRCDIR}/sys/rump
+
+LIBISPRIVATE=
+
+.include "${RUMPTOP}/Makefile.rump"
+.include <bsd.lib.mk>
+.include <bsd.klinks.mk>
Index: src/tests/rump/kernspace/busypage.c
diff -u /dev/null src/tests/rump/kernspace/busypage.c:1.1
--- /dev/null	Mon May 31 23:32:51 2010
+++ src/tests/rump/kernspace/busypage.c	Mon May 31 23:32:51 2010
@@ -0,0 +1,92 @@
+/*	$NetBSD: busypage.c,v 1.1 2010/05/31 23:32:51 pooka 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 <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: busypage.c,v 1.1 2010/05/31 23:32:51 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/param.h>
+#include <sys/condvar.h>
+#include <sys/kthread.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+
+#include <uvm/uvm.h>
+
+#include "kernspace.h"
+
+static struct uvm_object *uobj;
+static struct vm_page *testpg;
+static kcondvar_t tcv;
+
+static bool threadrun = false;
+
+static void
+thread(void *arg)
+{
+
+	mutex_enter(&uobj->vmobjlock);
+	threadrun = true;
+	cv_signal(&tcv);
+	testpg->flags |= PG_WANTED;
+	UVM_UNLOCK_AND_WAIT(testpg, &uobj->vmobjlock, false, "tw", 0);
+	kthread_exit(0);
+}
+
+void
+rumptest_busypage()
+{
+	struct lwp *newl;
+	int rv;
+
+	cv_init(&tcv, "napina");
+
+	uobj = uao_create(1, 0);
+	testpg = uvm_pagealloc(uobj, 0, NULL, 0);
+	if (testpg == NULL)
+		panic("couldn't create vm page");
+
+	rv = kthread_create(PRI_NONE, KTHREAD_JOINABLE | KTHREAD_MPSAFE, NULL,
+	    thread, NULL, &newl, "jointest");
+	if (rv)
+		panic("thread creation failed: %d", rv);
+
+	mutex_enter(&uobj->vmobjlock);
+	while (!threadrun)
+		cv_wait(&tcv, &uobj->vmobjlock);
+	mutex_exit(&uobj->vmobjlock);
+
+	uvm_page_unbusy(&testpg, 1);
+
+	rv = kthread_join(newl);
+	if (rv)
+		panic("thread join failed: %d", rv);
+
+}
Index: src/tests/rump/kernspace/kernspace.h
diff -u /dev/null src/tests/rump/kernspace/kernspace.h:1.1
--- /dev/null	Mon May 31 23:32:51 2010
+++ src/tests/rump/kernspace/kernspace.h	Mon May 31 23:32:51 2010
@@ -0,0 +1,38 @@
+/*	$NetBSD: kernspace.h,v 1.1 2010/05/31 23:32:51 pooka 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.
+ */
+
+#ifndef _TESTS_RUMP_KERNSPACE_KERNSPACE_H_
+#define _TESTS_RUMP_KERNSPACE_KERNSPACE_H_
+
+void rumptest_busypage(void);
+void rumptest_threadjoin(void);
+void rumptest_thread(void);
+void rumptest_tsleep(void);
+
+#endif /* _TESTS_RUMP_KERNSPACE_KERNSPACE_H_ */
Index: src/tests/rump/kernspace/thread.c
diff -u /dev/null src/tests/rump/kernspace/thread.c:1.1
--- /dev/null	Mon May 31 23:32:51 2010
+++ src/tests/rump/kernspace/thread.c	Mon May 31 23:32:51 2010
@@ -0,0 +1,108 @@
+/*	$NetBSD: thread.c,v 1.1 2010/05/31 23:32:51 pooka 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 <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: thread.c,v 1.1 2010/05/31 23:32:51 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/kthread.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+
+#include "kernspace.h"
+
+static volatile int testit;
+
+static void
+jointhread(void *arg)
+{
+
+	kpause("take5", false, 1, NULL);
+	testit = 1;
+	kthread_exit(0);
+}
+
+void
+rumptest_threadjoin()
+{
+	struct lwp *newl;
+	int rv;
+
+	rv = kthread_create(PRI_NONE, KTHREAD_JOINABLE | KTHREAD_MPSAFE, NULL,
+	    jointhread, NULL, &newl, "jointest");
+	if (rv)
+		panic("thread creation failed: %d", rv);
+	rv = kthread_join(newl);
+	if (rv)
+		panic("thread join failed: %d", rv);
+
+	if (testit != 1)
+		panic("new thread did not run");
+}
+
+static kmutex_t mtx;
+static kcondvar_t cv;
+static int value;
+
+static void
+thethread(void *arg)
+{
+
+	mutex_enter(&mtx);
+	value = 1;
+	cv_signal(&cv);
+	mutex_exit(&mtx);
+
+	kthread_exit(0);
+}
+
+void
+rumptest_thread()
+{
+	struct lwp *newl;
+	int rv;
+
+	mutex_init(&mtx, MUTEX_DEFAULT, IPL_NONE);
+	cv_init(&cv, "jooei");
+	rv = kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
+	    thethread, NULL, &newl, "ktest");
+	if (rv)
+		panic("thread creation failed: %d", rv);
+
+	mutex_enter(&mtx);
+	while (value == 0)
+		cv_wait(&cv, &mtx);
+	mutex_exit(&mtx);
+
+	/* try to verify thread really exists and we don't crash */
+	kpause("take1", false, 1, NULL);
+}
Index: src/tests/rump/kernspace/tsleep.c
diff -u /dev/null src/tests/rump/kernspace/tsleep.c:1.1
--- /dev/null	Mon May 31 23:32:51 2010
+++ src/tests/rump/kernspace/tsleep.c	Mon May 31 23:32:51 2010
@@ -0,0 +1,142 @@
+/*	$NetBSD: tsleep.c,v 1.1 2010/05/31 23:32:51 pooka 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 <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: tsleep.c,v 1.1 2010/05/31 23:32:51 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/kthread.h>
+#include <sys/proc.h>
+#include <sys/simplelock.h>
+
+#include "kernspace.h"
+
+#define NTHREADS 10
+
+/*
+ * kernel lock is interlock
+ */
+static void
+bigthread(void *arg)
+{
+	static int wakeups;
+	struct simplelock slock;
+	int i;
+
+	simple_lock_init(&slock);
+	for (i = 0; i < 1000; i++) {
+		wakeup(bigthread);
+		if (wakeups >= NTHREADS-1)
+			break;
+		if (arg) {
+			simple_lock(&slock);
+			ltsleep(bigthread, PNORELOCK, "hii", 0, &slock);
+		} else {
+			tsleep(bigthread, 0, "hii", 0);
+		}
+	}
+
+	wakeup(bigthread);
+	wakeups++;
+
+	kthread_exit(0);
+}
+
+/*
+ * mpsafe thread.  need dedicated interlock
+ */
+static kmutex_t mymtx;
+
+static void
+tinythread(void *arg)
+{
+	static int wakeups;
+	int i, rv;
+	bool relock = ((uintptr_t)arg % 2) == 0;
+
+	for (i = 0; i < 1000; i++) {
+		mutex_enter(&mymtx);
+		wakeup(tinythread);
+		if (wakeups >= NTHREADS-1) {
+			mutex_exit(&mymtx);
+			break;
+		}
+		rv = mtsleep(tinythread, relock ? 0 : PNORELOCK,
+		    "haa", 0, &mymtx);
+		if (relock)
+			mutex_exit(&mymtx);
+		if (rv != 0)
+			panic("mtsleep failed");
+	}
+
+	mutex_enter(&mymtx);
+	wakeups++;
+	wakeup(tinythread);
+
+	rv = mtsleep(rumptest_tsleep, PNORELOCK, "kepuli", 1, &mymtx);
+	if (rv != EWOULDBLOCK)
+		panic("mtsleep unexpected return value %d", rv);
+
+	kthread_exit(0);
+}
+
+void
+rumptest_tsleep()
+{
+	struct lwp *bigl[NTHREADS];
+	struct lwp *notbigl[NTHREADS];
+	int rv, i;
+
+	for (i = 0; i < NTHREADS; i++) {
+		rv = kthread_create(PRI_NONE, KTHREAD_JOINABLE,
+		    NULL, bigthread, (void *)(uintptr_t)i, &bigl[i], "b");
+		if (rv)
+			panic("thread create failed: %d", rv);
+	}
+
+	mutex_init(&mymtx, MUTEX_DEFAULT, IPL_NONE);
+
+	for (i = 0; i < NTHREADS; i++) {
+		rv = kthread_create(PRI_NONE, KTHREAD_JOINABLE | KTHREAD_MPSAFE,
+		    NULL, tinythread, (void *)(uintptr_t)i, &notbigl[i], "nb");
+		if (rv)
+			panic("thread create failed: %d", rv);
+	}
+
+	for (i = 0; i < NTHREADS; i++) {
+		kthread_join(bigl[i]);
+	}
+
+	for (i = 0; i < NTHREADS; i++) {
+		kthread_join(notbigl[i]);
+	}
+}

Reply via email to