Module Name:    src
Committed By:   ozaki-r
Date:           Thu Dec 28 07:09:31 UTC 2017

Modified Files:
        src/tests/rump/kernspace: workqueue.c

Log Message:
Functionalize some routines to add new tests easily (NFC)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/rump/kernspace/workqueue.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/kernspace/workqueue.c
diff -u src/tests/rump/kernspace/workqueue.c:1.3 src/tests/rump/kernspace/workqueue.c:1.4
--- src/tests/rump/kernspace/workqueue.c:1.3	Thu Dec 28 04:38:02 2017
+++ src/tests/rump/kernspace/workqueue.c	Thu Dec 28 07:09:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: workqueue.c,v 1.3 2017/12/28 04:38:02 ozaki-r Exp $	*/
+/*	$NetBSD: workqueue.c,v 1.4 2017/12/28 07:09:31 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: workqueue.c,v 1.3 2017/12/28 04:38:02 ozaki-r Exp $");
+__RCSID("$NetBSD: workqueue.c,v 1.4 2017/12/28 07:09:31 ozaki-r Exp $");
 #endif /* !lint */
 
 #include <sys/param.h>
@@ -61,19 +61,15 @@ rump_work1(struct work *wk, void *arg)
 	mutex_exit(&sc->mtx);
 }
 
-void
-rumptest_workqueue1()
+static struct test_softc *
+create_sc(void)
 {
-
 	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)
@@ -81,6 +77,25 @@ rumptest_workqueue1()
 
 	sc->counter = 0;
 
+	return sc;
+}
+
+static void
+destroy_sc(struct test_softc *sc)
+{
+
+	cv_destroy(&sc->cv);
+	mutex_destroy(&sc->mtx);
+	workqueue_destroy(sc->wq);
+}
+
+void
+rumptest_workqueue1()
+{
+	struct test_softc *sc;
+
+	sc = create_sc();
+
 #define ITERATIONS 12435
 	for (size_t i = 0; i < ITERATIONS; ++i) {
 		int e;
@@ -94,8 +109,6 @@ rumptest_workqueue1()
 
 	KASSERT(sc->counter == ITERATIONS);
 
-	cv_destroy(&sc->cv);
-	mutex_destroy(&sc->mtx);
-	workqueue_destroy(sc->wq);
+	destroy_sc(sc);
+#undef ITERATIONS
 }
-

Reply via email to