From nobody Wed Dec 17 05:43:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522162273330373.2368765769188; Tue, 27 Mar 2018 07:51:13 -0700 (PDT) Received: from localhost ([::1]:34729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0pwO-0006oX-IU for importer@patchew.org; Tue, 27 Mar 2018 10:51:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0pn7-0007uf-Tt for qemu-devel@nongnu.org; Tue, 27 Mar 2018 10:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0pn6-0000ys-Ln for qemu-devel@nongnu.org; Tue, 27 Mar 2018 10:41:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33524 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f0pn6-0000yk-Gz for qemu-devel@nongnu.org; Tue, 27 Mar 2018 10:41:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C9BB4068024; Tue, 27 Mar 2018 14:41:36 +0000 (UTC) Received: from localhost (ovpn-116-115.ams2.redhat.com [10.36.116.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5382B6F9E6; Tue, 27 Mar 2018 14:41:33 +0000 (UTC) From: Stefan Hajnoczi To: Date: Tue, 27 Mar 2018 15:41:23 +0100 Message-Id: <20180327144124.32533-4-stefanha@redhat.com> In-Reply-To: <20180327144124.32533-1-stefanha@redhat.com> References: <20180327144124.32533-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 27 Mar 2018 14:41:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 27 Mar 2018 14:41:36 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 3/4] coroutine: add test-aio coroutine queue chaining test case X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Check that two coroutines can queue each other repeatedly without hitting stack exhaustion. Switch to qemu_init_main_loop() in main() because coroutines use qemu_get_aio_context() - they don't know about test-aio's ctx variable. Signed-off-by: Stefan Hajnoczi Reviewed-by: Paolo Bonzini Message-id: 20180322152834.12656-4-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- tests/test-aio.c | 65 ++++++++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/tests/test-aio.c b/tests/test-aio.c index 54e20d6ab1..86fb73b3d5 100644 --- a/tests/test-aio.c +++ b/tests/test-aio.c @@ -16,6 +16,8 @@ #include "qemu/timer.h" #include "qemu/sockets.h" #include "qemu/error-report.h" +#include "qemu/coroutine.h" +#include "qemu/main-loop.h" =20 static AioContext *ctx; =20 @@ -827,24 +829,59 @@ static void test_source_timer_schedule(void) timer_del(&data.timer); } =20 +/* + * Check that aio_co_enter() can chain many times + * + * Two coroutines should be able to invoke each other via aio_co_enter() m= any + * times without hitting a limit like stack exhaustion. In other words, t= he + * calls should be chained instead of nested. + */ + +typedef struct { + Coroutine *other; + unsigned i; + unsigned max; +} ChainData; + +static void coroutine_fn chain(void *opaque) +{ + ChainData *data =3D opaque; + + for (data->i =3D 0; data->i < data->max; data->i++) { + /* Queue up the other coroutine... */ + aio_co_enter(ctx, data->other); + + /* ...and give control to it */ + qemu_coroutine_yield(); + } +} + +static void test_queue_chaining(void) +{ + /* This number of iterations hit stack exhaustion in the past: */ + ChainData data_a =3D { .max =3D 25000 }; + ChainData data_b =3D { .max =3D 25000 }; + + data_b.other =3D qemu_coroutine_create(chain, &data_a); + data_a.other =3D qemu_coroutine_create(chain, &data_b); + + qemu_coroutine_enter(data_b.other); + + g_assert_cmpint(data_a.i, =3D=3D, data_a.max); + g_assert_cmpint(data_b.i, =3D=3D, data_b.max - 1); + + /* Allow the second coroutine to terminate */ + qemu_coroutine_enter(data_a.other); + + g_assert_cmpint(data_b.i, =3D=3D, data_b.max); +} =20 /* End of tests. */ =20 int main(int argc, char **argv) { - Error *local_error =3D NULL; - GSource *src; - - init_clocks(NULL); - - ctx =3D aio_context_new(&local_error); - if (!ctx) { - error_reportf_err(local_error, "Failed to create AIO Context: "); - exit(1); - } - src =3D aio_get_g_source(ctx); - g_source_attach(src, NULL); - g_source_unref(src); + qemu_init_main_loop(&error_fatal); + ctx =3D qemu_get_aio_context(); =20 while (g_main_context_iteration(NULL, false)); =20 @@ -864,6 +901,8 @@ int main(int argc, char **argv) g_test_add_func("/aio/external-client", test_aio_external_clie= nt); g_test_add_func("/aio/timer/schedule", test_timer_schedule); =20 + g_test_add_func("/aio/coroutine/queue-chaining", test_queue_chaining); + g_test_add_func("/aio-gsource/flush", test_source_fl= ush); g_test_add_func("/aio-gsource/bh/schedule", test_source_bh= _schedule); g_test_add_func("/aio-gsource/bh/schedule10", test_source_bh= _schedule10); --=20 2.14.3