From nobody Mon Oct 27 18:31:41 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 1521733071467151.31935791105127; Thu, 22 Mar 2018 08:37:51 -0700 (PDT) Received: from localhost ([::1]:33217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ez2Hm-0006aJ-Kv for importer@patchew.org; Thu, 22 Mar 2018 11:37:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ez299-0000Ml-2P for qemu-devel@nongnu.org; Thu, 22 Mar 2018 11:28:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ez297-0008Cf-Vn for qemu-devel@nongnu.org; Thu, 22 Mar 2018 11:28:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49896 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 1ez293-00088P-7f; Thu, 22 Mar 2018 11:28:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCD298182D3A; Thu, 22 Mar 2018 15:28:48 +0000 (UTC) Received: from localhost (unknown [10.36.118.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 676C42023230; Thu, 22 Mar 2018 15:28:48 +0000 (UTC) From: Stefan Hajnoczi To: Date: Thu, 22 Mar 2018 15:28:34 +0000 Message-Id: <20180322152834.12656-4-stefanha@redhat.com> In-Reply-To: <20180322152834.12656-1-stefanha@redhat.com> References: <20180322152834.12656-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 22 Mar 2018 15:28:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 22 Mar 2018 15:28:48 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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] [PATCH 3/3] 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini 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 --- 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