From aef814ffa9ed9b7280264cd46f87376120c0d3b7 Mon Sep 17 00:00:00 2001 From: maya Date: Fri, 29 Sep 2017 12:42:36 +0000 Subject: [PATCH] Add simple test for workqueue(9) --- 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(-) create mode 100644 tests/rump/kernspace/workqueue.c create mode 100644 tests/rump/rumpkern/t_workqueue.c diff --git a/distrib/sets/lists/debug/mi b/distrib/sets/lists/debug/mi index 1f7e81f49aef..bfb47056daaf 100644 --- a/distrib/sets/lists/debug/mi +++ b/distrib/sets/lists/debug/mi @@ -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 --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index 6f25f041ea64..c1831f635834 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -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 --git a/tests/rump/kernspace/Makefile b/tests/rump/kernspace/Makefile index 4f8f9d6de4aa..3d0d4ffc40d3 100644 --- a/tests/rump/kernspace/Makefile +++ b/tests/rump/kernspace/Makefile @@ -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 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 --git a/tests/rump/kernspace/workqueue.c b/tests/rump/kernspace/workqueue.c new file mode 100644 index 000000000000..43852cc82d3e --- /dev/null +++ b/tests/rump/kernspace/workqueue.c @@ -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 +#if !defined(lint) +__RCSID("$NetBSD: workqueue.c,v 1.1 2017/09/29 12:42:36 maya Exp $"); +#endif /* !lint */ + +#include +#include +#include +#include +#include +#include +#include + +#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 --git a/tests/rump/rumpkern/Makefile b/tests/rump/rumpkern/Makefile index 71000fb8062e..4ece42901658 100644 --- a/tests/rump/rumpkern/Makefile +++ b/tests/rump/rumpkern/Makefile @@ -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 @@ -12,6 +12,7 @@ TESTS_C+= t_modlinkset 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 --git a/tests/rump/rumpkern/t_workqueue.c b/tests/rump/rumpkern/t_workqueue.c new file mode 100644 index 000000000000..a32f6b12832a --- /dev/null +++ b/tests/rump/rumpkern/t_workqueue.c @@ -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 +#include +#include + +#include + +#include + +#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(); +}