* [PATCH] tests: cover aio_co_enter from a worker thread without BQL taken
@ 2021-06-14 11:02 Paolo Bonzini
2021-06-14 14:52 ` Eric Blake
2021-06-15 9:00 ` Vladimir Sementsov-Ogievskiy
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-06-14 11:02 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, vsementsov
Add a testcase for the test fixed by commit 'async: the main AioContext
is only "current" if under the BQL.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
tests/unit/test-aio.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/tests/unit/test-aio.c b/tests/unit/test-aio.c
index 8a46078463..6feeb9a4a9 100644
--- a/tests/unit/test-aio.c
+++ b/tests/unit/test-aio.c
@@ -877,6 +877,42 @@ static void test_queue_chaining(void)
g_assert_cmpint(data_b.i, ==, data_b.max);
}
+static void co_check_current_thread(void *opaque)
+{
+ QemuThread *main_thread = opaque;
+ assert(qemu_thread_is_self(main_thread));
+}
+
+static void *test_aio_co_enter(void *co)
+{
+ /*
+ * qemu_get_current_aio_context() should not to be the main thread
+ * AioContext, because this is a worker thread that has not taken
+ * the BQL. So aio_co_enter will schedule the coroutine in the
+ * main thread AioContext.
+ */
+ aio_co_enter(qemu_get_aio_context(), co);
+ return NULL;
+}
+
+static void test_worker_thread_co_enter(void)
+{
+ QemuThread this_thread, worker_thread;
+ Coroutine *co;
+
+ qemu_thread_get_self(&this_thread);
+ co = qemu_coroutine_create(co_check_current_thread, &this_thread);
+
+ qemu_thread_create(&worker_thread, "test_acquire_thread",
+ test_aio_co_enter,
+ co, QEMU_THREAD_JOINABLE);
+
+ /* Test aio_co_enter from a worker thread. */
+ qemu_thread_join(&worker_thread);
+ g_assert(aio_poll(ctx, true));
+ g_assert(!aio_poll(ctx, false));
+}
+
/* End of tests. */
int main(int argc, char **argv)
@@ -903,6 +939,7 @@ int main(int argc, char **argv)
g_test_add_func("/aio/timer/schedule", test_timer_schedule);
g_test_add_func("/aio/coroutine/queue-chaining", test_queue_chaining);
+ g_test_add_func("/aio/coroutine/worker-thread-co-enter", test_worker_thread_co_enter);
g_test_add_func("/aio-gsource/flush", test_source_flush);
g_test_add_func("/aio-gsource/bh/schedule", test_source_bh_schedule);
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tests: cover aio_co_enter from a worker thread without BQL taken
2021-06-14 11:02 [PATCH] tests: cover aio_co_enter from a worker thread without BQL taken Paolo Bonzini
@ 2021-06-14 14:52 ` Eric Blake
2021-06-15 9:00 ` Vladimir Sementsov-Ogievskiy
1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2021-06-14 14:52 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kwolf, vsementsov, qemu-devel
On Mon, Jun 14, 2021 at 01:02:14PM +0200, Paolo Bonzini wrote:
> Add a testcase for the test fixed by commit 'async: the main AioContext
> is only "current" if under the BQL.
I can add the commit id to that commit when staging through my NBD
tree, if you'd like.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tests/unit/test-aio.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tests: cover aio_co_enter from a worker thread without BQL taken
2021-06-14 11:02 [PATCH] tests: cover aio_co_enter from a worker thread without BQL taken Paolo Bonzini
2021-06-14 14:52 ` Eric Blake
@ 2021-06-15 9:00 ` Vladimir Sementsov-Ogievskiy
1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2021-06-15 9:00 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: kwolf
14.06.2021 14:02, Paolo Bonzini wrote:
> Add a testcase for the test fixed by commit 'async: the main AioContext
> is only "current" if under the BQL.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-15 9:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14 11:02 [PATCH] tests: cover aio_co_enter from a worker thread without BQL taken Paolo Bonzini
2021-06-14 14:52 ` Eric Blake
2021-06-15 9:00 ` Vladimir Sementsov-Ogievskiy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.