Source-Changes-HG archive

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

[src/trunk]: src/tests/rump Add some kernel namespace (i.e. _KERNEL) helpers ...



details:   https://anonhg.NetBSD.org/src/rev/ccd47e006764
branches:  trunk
changeset: 755304:ccd47e006764
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon May 31 23:32:50 2010 +0000

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

diffstat:

 tests/rump/Atffile               |    4 +-
 tests/rump/Makefile              |    4 +-
 tests/rump/kernspace/Makefile    |   13 +++
 tests/rump/kernspace/busypage.c  |   92 +++++++++++++++++++++++++
 tests/rump/kernspace/kernspace.h |   38 ++++++++++
 tests/rump/kernspace/thread.c    |  108 +++++++++++++++++++++++++++++
 tests/rump/kernspace/tsleep.c    |  142 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 397 insertions(+), 4 deletions(-)

diffs (truncated from 442 to 300 lines):

diff -r f46aaf724dc1 -r ccd47e006764 tests/rump/Atffile
--- a/tests/rump/Atffile        Mon May 31 23:18:33 2010 +0000
+++ b/tests/rump/Atffile        Mon May 31 23:32:50 2010 +0000
@@ -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
diff -r f46aaf724dc1 -r ccd47e006764 tests/rump/Makefile
--- a/tests/rump/Makefile       Mon May 31 23:18:33 2010 +0000
+++ b/tests/rump/Makefile       Mon May 31 23:32:50 2010 +0000
@@ -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>
diff -r f46aaf724dc1 -r ccd47e006764 tests/rump/kernspace/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/kernspace/Makefile     Mon May 31 23:32:50 2010 +0000
@@ -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>
diff -r f46aaf724dc1 -r ccd47e006764 tests/rump/kernspace/busypage.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/kernspace/busypage.c   Mon May 31 23:32:50 2010 +0000
@@ -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);
+
+}
diff -r f46aaf724dc1 -r ccd47e006764 tests/rump/kernspace/kernspace.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/kernspace/kernspace.h  Mon May 31 23:32:50 2010 +0000
@@ -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_ */
diff -r f46aaf724dc1 -r ccd47e006764 tests/rump/kernspace/thread.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/kernspace/thread.c     Mon May 31 23:32:50 2010 +0000
@@ -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);
+}
diff -r f46aaf724dc1 -r ccd47e006764 tests/rump/kernspace/tsleep.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/kernspace/tsleep.c     Mon May 31 23:32:50 2010 +0000
@@ -0,0 +1,142 @@



Home | Main Index | Thread Index | Old Index