Source-Changes-HG archive

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

[src/trunk]: src/tests/rump/kernspace Fix a silly bug the "cancel thrash" tes...



details:   https://anonhg.NetBSD.org/src/rev/26d583eefc56
branches:  trunk
changeset: 447207:26d583eefc56
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jan 04 05:35:24 2019 +0000

description:
Fix a silly bug the "cancel thrash" test: the exit condition for the
job was never set, and so if the job actually got started before the
cancellation request came in, it would never finish and the cancellation
request would just hang forever.

Should address a spurious automated test failure reported by kre@.

diffstat:

 tests/rump/kernspace/threadpool.c |  31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diffs (61 lines):

diff -r 1b23b00184a8 -r 26d583eefc56 tests/rump/kernspace/threadpool.c
--- a/tests/rump/kernspace/threadpool.c Fri Jan 04 03:03:44 2019 +0000
+++ b/tests/rump/kernspace/threadpool.c Fri Jan 04 05:35:24 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: threadpool.c,v 1.4 2018/12/28 19:54:36 thorpej Exp $   */
+/*     $NetBSD: threadpool.c,v 1.5 2019/01/04 05:35:24 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.4 2018/12/28 19:54:36 thorpej Exp $");
+__RCSID("$NetBSD: threadpool.c,v 1.5 2019/01/04 05:35:24 thorpej Exp $");
 #endif /* !lint */
 
 #include <sys/param.h>
@@ -120,10 +120,12 @@
 {
        struct test_job_data *data =
            container_of(job, struct test_job_data, job);
-       
+
        mutex_enter(&data->mutex);
-       data->count = 1;
-       cv_broadcast(&data->cond);
+       if (data->count == 0) {
+               data->count = 1;
+               cv_broadcast(&data->cond);
+       }
        while (data->count != FINAL_COUNT - 1)
                cv_wait(&data->cond, &data->mutex);
        data->count = FINAL_COUNT;
@@ -257,7 +259,26 @@
                        mutex_exit(&data.mutex);
                        mutex_enter(&data.mutex);
                }
+               /*
+                * If the job managed to start, ensure that its exit
+                * condition is met so that we don't wait forever
+                * for the job to finish.
+                */
+               data.count = FINAL_COUNT - 1;
+               cv_broadcast(&data.cond);
+
                threadpool_cancel_job(pool, &data.job);
+
+               /*
+                * After cancellation, either the job didn't start
+                * (data.count == FINAL_COUNT - 1, per above) or
+                * it finished (data.count == FINAL_COUNT).
+                */
+               KASSERT(data.count == (FINAL_COUNT - 1) ||
+                   data.count == FINAL_COUNT);
+
+               /* Reset for the loop. */
+               data.count = 0;
        }
        mutex_exit(&data.mutex);
 



Home | Main Index | Thread Index | Old Index