Received: from eggs.gnu.org ([2001:4830:134:3::10]:56612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWob-0002iO-TG for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btWoa-0003cl-6r for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37236) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWoZ-0003cZ-TG for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:08 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CDB84E4D7 for ; Mon, 10 Oct 2016 09:24:07 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 10 Oct 2016 13:22:54 +0400 Message-Id: <20161010092301.14974-18-marcandre.lureau@redhat.com> In-Reply-To: <20161010092301.14974-1-marcandre.lureau@redhat.com> References: <20161010092301.14974-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 17/24] qtest: add qtest-timeout List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: eblake@redhat.com, berrange@redhat.com, armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= This command allows to test async behavior. It is only registered when qtest is enabled. See the schema documentation for more details. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qtest.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 22 ++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/qtest.c b/qtest.c index 22482cc..eda171d 100644 --- a/qtest.c +++ b/qtest.c @@ -31,6 +31,8 @@ #ifdef TARGET_PPC64 #include "hw/ppc/spapr_rtas.h" #endif +#include "qapi/qmp/dispatch.h" +#include "qapi/qmp-input-visitor.h" =20 #define MAX_IRQ 256 =20 @@ -649,6 +651,49 @@ static void qtest_event(void *opaque, int event) } } =20 +static gboolean qtest_timeout_cb(void *data) +{ + QmpReturn *qret =3D data; + + qmp_return(qret, NULL); + + return FALSE; +} + +static void qmp_qtest_timeout(QDict *args, QmpReturn *qret) +{ + Error *err =3D NULL; + Visitor *v; + int64_t duration =3D 0; + + v =3D qmp_input_visitor_new(QOBJECT(args), true); + visit_start_struct(v, NULL, NULL, 0, &err); + if (err) { + goto out; + } + + visit_type_int(v, "duration", &duration, &err); + if (!err) { + visit_check_struct(v, &err); + } + visit_end_struct(v, NULL); + if (err) { + goto out; + } + + if (duration <=3D 0) { + qmp_return(qret, NULL); + } else { + g_timeout_add_seconds(duration, qtest_timeout_cb, qret); + } + +out: + if (err) { + qmp_return_error(qret, err); + } + visit_free(v); +} + static int qtest_init_accel(MachineState *ms) { QemuOpts *opts =3D qemu_opts_create(qemu_find_opts("icount"), NULL, = 0, @@ -656,6 +701,9 @@ static int qtest_init_accel(MachineState *ms) qemu_opt_set(opts, "shift", "0", &error_abort); configure_icount(opts, &error_abort); qemu_opts_del(opts); + + qmp_register_async_command("qtest-timeout", qmp_qtest_timeout, + QCO_NO_OPTIONS); return 0; } =20 diff --git a/qapi-schema.json b/qapi-schema.json index 95d3c72..e9618f6 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4658,3 +4658,25 @@ # Since: 2.7 ## { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] } + +## +# @qtest-timeout: +# +# @duration: the time before timeout expires (in seconds) +# +# Test command that replies after @duration seconds. +# +# Example: +# +# -> { "execute": "qtest-timeout", +# "arguments": { "duration": 5 } } +# ... after 5s +# <- { "return": {} } +# +# Note: this command is only available with a qtest machine +# +# Since: 2.8 +## +{ 'command': 'qtest-timeout', + 'data': {'duration': 'int'}, + 'gen': false } # so we can can register it manually when qtest is enab= led --=20 2.10.0