[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/34] tests: cover aio_co_enter from a worker thread without BQL
From: |
Eric Blake |
Subject: |
[PULL 02/34] tests: cover aio_co_enter from a worker thread without BQL taken |
Date: |
Tue, 15 Jun 2021 15:47:24 -0500 |
From: Paolo Bonzini <pbonzini@redhat.com>
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>
Message-Id: <20210614110214.726722-1-pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@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 8a4607846340..6feeb9a4a9fd 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
- [PULL 00/34] NBD patches for 2021-06-15, Eric Blake, 2021/06/15
- [PULL 03/34] co-queue: drop extra coroutine_fn marks, Eric Blake, 2021/06/15
- [PULL 02/34] tests: cover aio_co_enter from a worker thread without BQL taken,
Eric Blake <=
- [PULL 04/34] block/nbd: fix channel object leak, Eric Blake, 2021/06/15
- [PULL 01/34] async: the main AioContext is only "current" if under the BQL, Eric Blake, 2021/06/15
- [PULL 05/34] block/nbd: fix how state is cleared on nbd_open() failure paths, Eric Blake, 2021/06/15
- [PULL 07/34] qemu-sockets: introduce socket_address_parse_named_fd(), Eric Blake, 2021/06/15
- [PULL 06/34] block/nbd: connect_thread_func(): do qio_channel_set_delay(false), Eric Blake, 2021/06/15
- [PULL 10/34] block/nbd: nbd_client_handshake(): fix leak of s->ioc, Eric Blake, 2021/06/15
- [PULL 09/34] block/nbd: ensure ->connection_thread is always valid, Eric Blake, 2021/06/15
- [PULL 08/34] block/nbd: call socket_address_parse_named_fd() in advance, Eric Blake, 2021/06/15
- [PULL 11/34] block/nbd: BDRVNBDState: drop unused connect_err and connect_status, Eric Blake, 2021/06/15
- [PULL 12/34] block/nbd: simplify waking of nbd_co_establish_connection(), Eric Blake, 2021/06/15