Source-Changes-HG archive

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

[src/trunk]: src Add simple test for workqueue(9)



details:   https://anonhg.NetBSD.org/src/rev/7792ef62b182
branches:  trunk
changeset: 356484:7792ef62b182
user:      maya <maya%NetBSD.org@localhost>
date:      Fri Sep 29 12:42:36 2017 +0000

description:
Add simple test for workqueue(9)

diffstat:

 distrib/sets/lists/debug/mi       |   3 +-
 distrib/sets/lists/tests/mi       |   3 +-
 tests/rump/kernspace/Makefile     |   4 +-
 tests/rump/kernspace/workqueue.c  |  98 +++++++++++++++++++++++++++++++++++++++
 tests/rump/rumpkern/Makefile      |   3 +-
 tests/rump/rumpkern/t_workqueue.c |  63 +++++++++++++++++++++++++
 6 files changed, 169 insertions(+), 5 deletions(-)

diffs (236 lines):

diff -r 6097d501b971 -r 7792ef62b182 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Fri Sep 29 10:22:36 2017 +0000
+++ b/distrib/sets/lists/debug/mi       Fri Sep 29 12:42:36 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.224 2017/08/16 13:53:19 joerg Exp $
+# $NetBSD: mi,v 1.225 2017/09/29 12:42:36 maya Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -2306,6 +2306,7 @@
 ./usr/libdata/debug/usr/tests/rump/rumpkern/t_signals.debug            tests-syscall-debug     debug,atf,rump
 ./usr/libdata/debug/usr/tests/rump/rumpkern/t_threads.debug            tests-syscall-debug     debug,atf,rump
 ./usr/libdata/debug/usr/tests/rump/rumpkern/t_tsleep.debug             tests-syscall-debug     debug,atf,rump
+./usr/libdata/debug/usr/tests/rump/rumpkern/t_workqueue.debug          tests-syscall-debug     debug,atf,rump
 ./usr/libdata/debug/usr/tests/rump/rumpkern/t_vm.debug                 tests-syscall-debug     debug,atf,rump
 ./usr/libdata/debug/usr/tests/rump/rumpvfs/t_basic.debug               tests-syscall-debug     debug,atf,rump
 ./usr/libdata/debug/usr/tests/rump/rumpvfs/t_etfs.debug                tests-syscall-debug     debug,atf,rump
diff -r 6097d501b971 -r 7792ef62b182 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Sep 29 10:22:36 2017 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Sep 29 12:42:36 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.762 2017/09/20 09:36:20 ozaki-r Exp $
+# $NetBSD: mi,v 1.763 2017/09/29 12:42:36 maya Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3416,6 +3416,7 @@
 ./usr/tests/rump/rumpkern/t_sp                 tests-rump-tests        atf,rump
 ./usr/tests/rump/rumpkern/t_threads            tests-rump-tests        atf,rump
 ./usr/tests/rump/rumpkern/t_tsleep             tests-rump-tests        atf,rump
+./usr/tests/rump/rumpkern/t_workqueue          tests-rump-tests        atf,rump
 ./usr/tests/rump/rumpkern/t_vm                 tests-rump-tests        atf,rump
 ./usr/tests/rump/rumpnet                       tests-rump-tests        compattestfile,atf
 ./usr/tests/rump/rumpnet/Atffile               tests-rump-tests        atf,rump
diff -r 6097d501b971 -r 7792ef62b182 tests/rump/kernspace/Makefile
--- a/tests/rump/kernspace/Makefile     Fri Sep 29 10:22:36 2017 +0000
+++ b/tests/rump/kernspace/Makefile     Fri Sep 29 12:42:36 2017 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.5 2011/01/14 13:08:00 pooka Exp $
+#      $NetBSD: Makefile,v 1.6 2017/09/29 12:42:36 maya Exp $
 #
 
 .include <bsd.own.mk>
 
 LIB=   kernspace
-SRCS=  thread.c busypage.c tsleep.c alloc.c lockme.c sendsig.c
+SRCS=  thread.c busypage.c tsleep.c alloc.c lockme.c workqueue.c sendsig.c
 
 RUMPTOP=${NETBSDSRCDIR}/sys/rump
 
diff -r 6097d501b971 -r 7792ef62b182 tests/rump/kernspace/workqueue.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/kernspace/workqueue.c  Fri Sep 29 12:42:36 2017 +0000
@@ -0,0 +1,98 @@
+/*     $NetBSD: workqueue.c,v 1.1 2017/09/29 12:42:36 maya Exp $       */
+
+/*-
+ * Copyright (c) 2017 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: workqueue.c,v 1.1 2017/09/29 12:42:36 maya Exp $");
+#endif /* !lint */
+
+#include <sys/param.h>
+#include <sys/condvar.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/kthread.h>
+#include <sys/mutex.h>
+#include <sys/workqueue.h>
+
+#include "kernspace.h"
+
+struct test_softc {
+       kmutex_t mtx;
+       kcondvar_t cv;
+       struct workqueue *wq;
+       struct work wk;
+       int counter;
+};     
+       
+static void
+rump_work1(struct work *wk, void *arg)
+{
+       struct test_softc *sc = arg;
+
+       mutex_enter(&sc->mtx);
+       ++sc->counter;
+       cv_broadcast(&sc->cv);
+       mutex_exit(&sc->mtx);
+}
+
+void
+rumptest_workqueue1()
+{
+
+       int rv;
+
+       struct test_softc *sc;
+
+       sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
+
+       mutex_init(&sc->mtx, MUTEX_DEFAULT, IPL_NONE);
+       cv_init(&sc->cv, "rumpwqcv");
+
+       rv = workqueue_create(&sc->wq, "rumpwq",
+           rump_work1, sc, PRI_SOFTNET, IPL_SOFTNET, 0);
+       if (rv)
+               panic("workqueue creation failed: %d", rv);
+
+       sc->counter = 0;
+
+#define ITERATIONS 12435
+       for (size_t i = 0; i < ITERATIONS; ++i) {
+               workqueue_enqueue(sc->wq, &sc->wk, NULL);
+               mutex_enter(&sc->mtx);
+               cv_timedwait(&sc->cv, &sc->mtx, 2);
+               mutex_exit(&sc->mtx);
+       }
+
+       KASSERT(sc->counter == ITERATIONS);
+
+       cv_destroy(&sc->cv);
+       mutex_destroy(&sc->mtx);
+       workqueue_destroy(sc->wq);
+}
+
diff -r 6097d501b971 -r 7792ef62b182 tests/rump/rumpkern/Makefile
--- a/tests/rump/rumpkern/Makefile      Fri Sep 29 10:22:36 2017 +0000
+++ b/tests/rump/rumpkern/Makefile      Fri Sep 29 12:42:36 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.15 2014/06/10 04:28:40 he Exp $
+# $NetBSD: Makefile,v 1.16 2017/09/29 12:42:37 maya Exp $
 
 .include <bsd.own.mk>
 
@@ -12,6 +12,7 @@
 TESTS_C+=      t_signals
 TESTS_C+=      t_threads
 TESTS_C+=      t_tsleep
+TESTS_C+=      t_workqueue
 TESTS_C+=      t_vm
 
 TESTS_SH=      t_sp
diff -r 6097d501b971 -r 7792ef62b182 tests/rump/rumpkern/t_workqueue.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/t_workqueue.c Fri Sep 29 12:42:36 2017 +0000
@@ -0,0 +1,63 @@
+/*     $NetBSD: t_workqueue.c,v 1.1 2017/09/29 12:42:37 maya Exp $     */
+
+/*-
+ * Copyright (c) 2017 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/types.h>
+#include <sys/mount.h>
+#include <sys/sysctl.h>
+
+#include <rump/rump.h>
+
+#include <atf-c.h>
+
+#include "h_macros.h"
+#include "../kernspace/kernspace.h"
+
+ATF_TC(workqueue1);
+ATF_TC_HEAD(workqueue1, tc)
+{
+
+       atf_tc_set_md_var(tc, "descr", "Checks workqueue basics");
+}
+
+ATF_TC_BODY(workqueue1, tc)
+{
+
+       rump_init();
+
+       rump_schedule();
+       rumptest_workqueue1(); /* panics if fails */
+       rump_unschedule();
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+       ATF_TP_ADD_TC(tp, workqueue1);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index