Module Name:    src
Committed By:   thorpej
Date:           Fri Dec 28 19:54:36 UTC 2018

Modified Files:
        src/tests/rump/kernspace: kernspace.h threadpool.c
        src/tests/rump/rumpkern: t_threadpool.c

Log Message:
Add a test case that exercises repeated sceduling and cancelling of a job,
with periodic dropping of the interlock.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/rump/kernspace/kernspace.h
cvs rdiff -u -r1.3 -r1.4 src/tests/rump/kernspace/threadpool.c
cvs rdiff -u -r1.1 -r1.2 src/tests/rump/rumpkern/t_threadpool.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/kernspace.h
diff -u src/tests/rump/kernspace/kernspace.h:1.7 src/tests/rump/kernspace/kernspace.h:1.8
--- src/tests/rump/kernspace/kernspace.h:1.7	Mon Dec 24 21:42:05 2018
+++ src/tests/rump/kernspace/kernspace.h	Fri Dec 28 19:54:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kernspace.h,v 1.7 2018/12/24 21:42:05 thorpej Exp $	*/
+/*	$NetBSD: kernspace.h,v 1.8 2018/12/28 19:54:36 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2010, 2018 The NetBSD Foundation, Inc.
@@ -51,5 +51,6 @@ void rumptest_threadpool_percpu_lifecycl
 void rumptest_threadpool_unbound_schedule(void);
 void rumptest_threadpool_percpu_schedule(void);
 void rumptest_threadpool_job_cancel(void);
+void rumptest_threadpool_job_cancelthrash(void);
 
 #endif /* _TESTS_RUMP_KERNSPACE_KERNSPACE_H_ */

Index: src/tests/rump/kernspace/threadpool.c
diff -u src/tests/rump/kernspace/threadpool.c:1.3 src/tests/rump/kernspace/threadpool.c:1.4
--- src/tests/rump/kernspace/threadpool.c:1.3	Wed Dec 26 18:54:20 2018
+++ src/tests/rump/kernspace/threadpool.c	Fri Dec 28 19:54:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: threadpool.c,v 1.3 2018/12/26 18:54:20 thorpej Exp $	*/
+/*	$NetBSD: threadpool.c,v 1.4 2018/12/28 19:54:36 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: threadpool.c,v 1.3 2018/12/26 18:54:20 thorpej Exp $");
+__RCSID("$NetBSD: threadpool.c,v 1.4 2018/12/28 19:54:36 thorpej Exp $");
 #endif /* !lint */
 
 #include <sys/param.h>
@@ -237,3 +237,31 @@ rumptest_threadpool_job_cancel(void)
 
 	threadpool_put(pool, PRI_NONE);
 }
+
+void
+rumptest_threadpool_job_cancelthrash(void)
+{
+	struct test_job_data data;
+	struct threadpool *pool;
+	int i, error;
+
+	error = threadpool_get(&pool, PRI_NONE);
+	KASSERT(error == 0);
+
+	init_test_job_data(&data, test_job_func_cancel);
+
+	mutex_enter(&data.mutex);
+	for (i = 0; i < 10000; i++) {
+		threadpool_schedule_job(pool, &data.job);
+		if ((i % 3) == 0) {
+			mutex_exit(&data.mutex);
+			mutex_enter(&data.mutex);
+		}
+		threadpool_cancel_job(pool, &data.job);
+	}
+	mutex_exit(&data.mutex);
+
+	fini_test_job_data(&data);
+
+	threadpool_put(pool, PRI_NONE);
+}

Index: src/tests/rump/rumpkern/t_threadpool.c
diff -u src/tests/rump/rumpkern/t_threadpool.c:1.1 src/tests/rump/rumpkern/t_threadpool.c:1.2
--- src/tests/rump/rumpkern/t_threadpool.c:1.1	Mon Dec 24 21:42:05 2018
+++ src/tests/rump/rumpkern/t_threadpool.c	Fri Dec 28 19:54:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_threadpool.c,v 1.1 2018/12/24 21:42:05 thorpej Exp $	*/
+/*	$NetBSD: t_threadpool.c,v 1.2 2018/12/28 19:54:36 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -126,6 +126,24 @@ ATF_TC_BODY(threadpool_job_cancel, tc)
 	rump_unschedule();
 }
 
+ATF_TC(threadpool_job_cancelthrash);
+ATF_TC_HEAD(threadpool_job_cancelthrash, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	    "Tests thrashing job scheduling / cancellation");
+}
+
+ATF_TC_BODY(threadpool_job_cancelthrash, tc)
+{
+
+	rump_init();
+
+	rump_schedule();
+	rumptest_threadpool_job_cancelthrash(); /* panics if fails */
+	rump_unschedule();
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, threadpool_unbound_lifecycle);
@@ -133,6 +151,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, threadpool_unbound_schedule);
 	ATF_TP_ADD_TC(tp, threadpool_percpu_schedule);
 	ATF_TP_ADD_TC(tp, threadpool_job_cancel);
+	ATF_TP_ADD_TC(tp, threadpool_job_cancelthrash);
 
 	return atf_no_error();
 }

Reply via email to