aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test-aio.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/test-aio.c')
-rw-r--r--tests/unit/test-aio.c100
1 files changed, 5 insertions, 95 deletions
diff --git a/tests/unit/test-aio.c b/tests/unit/test-aio.c
index 6feeb9a4a9..e77d86be87 100644
--- a/tests/unit/test-aio.c
+++ b/tests/unit/test-aio.c
@@ -16,7 +16,7 @@
#include "qemu/timer.h"
#include "qemu/sockets.h"
#include "qemu/error-report.h"
-#include "qemu/coroutine.h"
+#include "qemu/coroutine-core.h"
#include "qemu/main-loop.h"
static AioContext *ctx;
@@ -100,74 +100,10 @@ static void event_ready_cb(EventNotifier *e)
/* Tests using aio_*. */
-typedef struct {
- QemuMutex start_lock;
- EventNotifier notifier;
- bool thread_acquired;
-} AcquireTestData;
-
-static void *test_acquire_thread(void *opaque)
-{
- AcquireTestData *data = opaque;
-
- /* Wait for other thread to let us start */
- qemu_mutex_lock(&data->start_lock);
- qemu_mutex_unlock(&data->start_lock);
-
- /* event_notifier_set might be called either before or after
- * the main thread's call to poll(). The test case's outcome
- * should be the same in either case.
- */
- event_notifier_set(&data->notifier);
- aio_context_acquire(ctx);
- aio_context_release(ctx);
-
- data->thread_acquired = true; /* success, we got here */
-
- return NULL;
-}
-
-static void set_event_notifier(AioContext *ctx, EventNotifier *notifier,
+static void set_event_notifier(AioContext *nctx, EventNotifier *notifier,
EventNotifierHandler *handler)
{
- aio_set_event_notifier(ctx, notifier, false, handler, NULL);
-}
-
-static void dummy_notifier_read(EventNotifier *n)
-{
- event_notifier_test_and_clear(n);
-}
-
-static void test_acquire(void)
-{
- QemuThread thread;
- AcquireTestData data;
-
- /* Dummy event notifier ensures aio_poll() will block */
- event_notifier_init(&data.notifier, false);
- set_event_notifier(ctx, &data.notifier, dummy_notifier_read);
- g_assert(!aio_poll(ctx, false)); /* consume aio_notify() */
-
- qemu_mutex_init(&data.start_lock);
- qemu_mutex_lock(&data.start_lock);
- data.thread_acquired = false;
-
- qemu_thread_create(&thread, "test_acquire_thread",
- test_acquire_thread,
- &data, QEMU_THREAD_JOINABLE);
-
- /* Block in aio_poll(), let other thread kick us and acquire context */
- aio_context_acquire(ctx);
- qemu_mutex_unlock(&data.start_lock); /* let the thread run */
- g_assert(aio_poll(ctx, true));
- g_assert(!data.thread_acquired);
- aio_context_release(ctx);
-
- qemu_thread_join(&thread);
- set_event_notifier(ctx, &data.notifier, NULL);
- event_notifier_cleanup(&data.notifier);
-
- g_assert(data.thread_acquired);
+ aio_set_event_notifier(nctx, notifier, handler, NULL, NULL);
}
static void test_bh_schedule(void)
@@ -383,30 +319,6 @@ static void test_flush_event_notifier(void)
event_notifier_cleanup(&data.e);
}
-static void test_aio_external_client(void)
-{
- int i, j;
-
- for (i = 1; i < 3; i++) {
- EventNotifierTestData data = { .n = 0, .active = 10, .auto_set = true };
- event_notifier_init(&data.e, false);
- aio_set_event_notifier(ctx, &data.e, true, event_ready_cb, NULL);
- event_notifier_set(&data.e);
- for (j = 0; j < i; j++) {
- aio_disable_external(ctx);
- }
- for (j = 0; j < i; j++) {
- assert(!aio_poll(ctx, false));
- assert(event_notifier_test_and_clear(&data.e));
- event_notifier_set(&data.e);
- aio_enable_external(ctx);
- }
- assert(aio_poll(ctx, false));
- set_event_notifier(ctx, &data.e, NULL);
- event_notifier_cleanup(&data.e);
- }
-}
-
static void test_wait_event_notifier_noflush(void)
{
EventNotifierTestData data = { .n = 0 };
@@ -478,7 +390,7 @@ static void test_timer_schedule(void)
g_assert_cmpint(data.n, ==, 0);
- /* timer_mod may well cause an event notifer to have gone off,
+ /* timer_mod may well cause an event notifier to have gone off,
* so clear that
*/
do {} while (aio_poll(ctx, false));
@@ -903,7 +815,7 @@ static void test_worker_thread_co_enter(void)
qemu_thread_get_self(&this_thread);
co = qemu_coroutine_create(co_check_current_thread, &this_thread);
- qemu_thread_create(&worker_thread, "test_acquire_thread",
+ qemu_thread_create(&worker_thread, "test_aio_co_enter",
test_aio_co_enter,
co, QEMU_THREAD_JOINABLE);
@@ -923,7 +835,6 @@ int main(int argc, char **argv)
while (g_main_context_iteration(NULL, false));
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/aio/acquire", test_acquire);
g_test_add_func("/aio/bh/schedule", test_bh_schedule);
g_test_add_func("/aio/bh/schedule10", test_bh_schedule10);
g_test_add_func("/aio/bh/cancel", test_bh_cancel);
@@ -935,7 +846,6 @@ int main(int argc, char **argv)
g_test_add_func("/aio/event/wait", test_wait_event_notifier);
g_test_add_func("/aio/event/wait/no-flush-cb", test_wait_event_notifier_noflush);
g_test_add_func("/aio/event/flush", test_flush_event_notifier);
- g_test_add_func("/aio/external-client", test_aio_external_client);
g_test_add_func("/aio/timer/schedule", test_timer_schedule);
g_test_add_func("/aio/coroutine/queue-chaining", test_queue_chaining);