From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017626385749.7892161946381; Tue, 25 Jul 2017 14:20:26 -0700 (PDT) Received: from localhost ([::1]:34663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7Fe-0005KB-LT for importer@patchew.org; Tue, 25 Jul 2017 17:20:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7B8-00020t-AD for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7B6-00041q-J4 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56874) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7B6-00041M-2g for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2DB2C058ECF for ; Tue, 25 Jul 2017 21:15:38 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E6FC5C7C1; Tue, 25 Jul 2017 21:15:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D2DB2C058ECF Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:12 -0500 Message-Id: <20170725211523.3998-2-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 25 Jul 2017 21:15:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 01/12] qobject: Accept "%"PRId64 in qobject_from_jsonf() 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: armbru@redhat.com, stefanha@redhat.com 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" Commit 1792d7d0 was written because PRId64 expands to non-portable crap for some libc, and we had testsuite failures on Mac OS as a result. This in turn makes it difficult to rely on the obvious conversions of 64-bit values into JSON, requiring things such as casting int64_t to long long so we can use a reliable %lld and still keep -Wformat happy. So now it's time to fix that. We are already lexing %I64d (hello mingw); now expand the lexer to parse %qd (hello Mac OS). In the process, we can drop one state: IN_ESCAPE_I64 is redundant with IN_ESCAPE_LL, and reused again by %qd, so rename it to IN_ESCAPE_64. And fix a comment that mistakenly omitted %u as a supported escape. Next, tweak the parser to accept the exact spelling of PRId64 regardless of what it expands to (note that there are are now dead branches in the 'if' chain for some platforms, like glibc; but there are other platforms where all branches are necessary). We are at least safe in that we are parsing the correct size 32-bit or a 64-bit quantity on whatever branch we end up in. This also means that we no longer parse everything that the lexer will consume (no more %I64d on glibc), but that is intentional. And of course, update the testsuite for coverage of the feature. Finally, update configure to barf on any libc that uses yet another form of PRId64 that we have not yet coded for, so that we can once again update json-lexer.c to cater to those quirks (my guess? we might see %jd next) (on the bright side, json-parser.c should no longer need updates). Yes, the only way I could find to quickly learn what spelling is preferred when cross-compiling is to grep a compiled binary; C does not make it easy to turn a string constant into an integer constant, let alone make preprocessor decisions; and even parsing '$CC -E' output is fragile, since 64-bit glibc pre-processes as "l" "d" rather than "ld", and newer gcc splits macro expansions across multiple lines. I'm assuming that 'strings' is portable enough during configure; if that assumption fails in some constrained docker environment, an easy hack is to add this to configure: strings () { tr -d '\0' < "$1"; } Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster --- v3: incorporate review comments from Markus --- configure | 24 ++++++++++++++++++++++++ qobject/json-lexer.c | 21 +++++++++------------ qobject/json-parser.c | 10 ++++++---- tests/check-qjson.c | 7 +++++++ 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/configure b/configure index 987f59ba88..5b0eddec3c 100755 --- a/configure +++ b/configure @@ -3222,6 +3222,30 @@ for i in $glib_modules; do fi done +# Sanity check that we can parse PRId64 and friends in json-lexer.c +# (Sadly, the "easiest" way to do this is to grep the compiled binary, +# since we can't control whether the preprocessor would output "ld" vs. +# "l" "d", nor even portably ensure it fits output on the same line as +# a witness marker.) +cat > $TMPC < +int main(void) { + static const char findme[] =3D "\nUnLiKeLyToClAsH_" PRId64 "\n"; + return !findme[0]; +} +EOF +if ! compile_prog "$CFLAGS" "$LIBS" ; then + error_exit "can't determine value of PRId64" +fi +nl=3D' +' +case $(strings $TMPE | grep ^UnLiKeLyToClAsH) in + '' | *"$nl"* ) error_exit "can't determine value of PRId64" ;; + *_ld | *_lld | *_I64d | *_qd) ;; + *) error_exit "unexepected value of PRId64, please add %$(strings $TMP= E | + sed -n s/^UnLiKeLyToClAsH_//p) support to json-lexer.c" ;; +esac + # Sanity check that the current size_t matches the # size that glib thinks it should be. This catches # problems on multi-arch where people try to build diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index 980ba159d6..9a0fc58444 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -29,9 +29,11 @@ * * '([^\\']|\\[\"'\\/bfnrt]|\\u[0-9a-fA-F]{4})*' * - * Extension for vararg handling in JSON construction: + * Extension for vararg handling in JSON construction [this lexer + * actually accepts multiple forms of PRId64, but parse_escape() later + * filters to only parse the current platform's spelling]: * - * %((l|ll|I64)?d|[ipsf]) + * %(PRI[du]64|(l|ll)?[ud]|[ipsf]) * */ @@ -60,10 +62,9 @@ enum json_lexer_state { IN_KEYWORD, IN_ESCAPE, IN_ESCAPE_L, - IN_ESCAPE_LL, + IN_ESCAPE_64, IN_ESCAPE_I, IN_ESCAPE_I6, - IN_ESCAPE_I64, IN_WHITESPACE, IN_START, }; @@ -225,24 +226,19 @@ static const uint8_t json_lexer[][256] =3D { }, /* escape */ - [IN_ESCAPE_LL] =3D { + [IN_ESCAPE_64] =3D { ['d'] =3D JSON_ESCAPE, ['u'] =3D JSON_ESCAPE, }, [IN_ESCAPE_L] =3D { ['d'] =3D JSON_ESCAPE, - ['l'] =3D IN_ESCAPE_LL, - ['u'] =3D JSON_ESCAPE, - }, - - [IN_ESCAPE_I64] =3D { - ['d'] =3D JSON_ESCAPE, + ['l'] =3D IN_ESCAPE_64, ['u'] =3D JSON_ESCAPE, }, [IN_ESCAPE_I6] =3D { - ['4'] =3D IN_ESCAPE_I64, + ['4'] =3D IN_ESCAPE_64, }, [IN_ESCAPE_I] =3D { @@ -257,6 +253,7 @@ static const uint8_t json_lexer[][256] =3D { ['u'] =3D JSON_ESCAPE, ['f'] =3D JSON_ESCAPE, ['l'] =3D IN_ESCAPE_L, + ['q'] =3D IN_ESCAPE_64, ['I'] =3D IN_ESCAPE_I, }, diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 724ca240e4..388aa7a386 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -470,16 +470,18 @@ static QObject *parse_escape(JSONParserContext *ctxt,= va_list *ap) return QOBJECT(qnum_from_int(va_arg(*ap, int))); } else if (!strcmp(token->str, "%ld")) { return QOBJECT(qnum_from_int(va_arg(*ap, long))); - } else if (!strcmp(token->str, "%lld") || - !strcmp(token->str, "%I64d")) { + } else if (!strcmp(token->str, "%lld")) { return QOBJECT(qnum_from_int(va_arg(*ap, long long))); + } else if (!strcmp(token->str, "%" PRId64)) { + return QOBJECT(qnum_from_int(va_arg(*ap, int64_t))); } else if (!strcmp(token->str, "%u")) { return QOBJECT(qnum_from_uint(va_arg(*ap, unsigned int))); } else if (!strcmp(token->str, "%lu")) { return QOBJECT(qnum_from_uint(va_arg(*ap, unsigned long))); - } else if (!strcmp(token->str, "%llu") || - !strcmp(token->str, "%I64u")) { + } else if (!strcmp(token->str, "%llu")) { return QOBJECT(qnum_from_uint(va_arg(*ap, unsigned long long))); + } else if (!strcmp(token->str, "%" PRIu64)) { + return QOBJECT(qnum_from_uint(va_arg(*ap, uint64_t))); } else if (!strcmp(token->str, "%s")) { return QOBJECT(qstring_from_str(va_arg(*ap, const char *))); } else if (!strcmp(token->str, "%f")) { diff --git a/tests/check-qjson.c b/tests/check-qjson.c index a3a97b0d99..1ad1f41a52 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -990,8 +990,10 @@ static void vararg_number(void) QNum *qnum; int value =3D 0x2342; long long value_ll =3D 0x2342342343LL; + uint64_t value_u64 =3D 0x2342342343ULL; double valuef =3D 2.323423423; int64_t val; + uint64_t uval; qnum =3D qobject_to_qnum(qobject_from_jsonf("%d", value)); g_assert(qnum_get_try_int(qnum, &val)); @@ -1003,6 +1005,11 @@ static void vararg_number(void) g_assert_cmpint(val, =3D=3D, value_ll); QDECREF(qnum); + qnum =3D qobject_to_qnum(qobject_from_jsonf("%" PRIu64, value_u64)); + g_assert(qnum_get_try_uint(qnum, &uval)); + g_assert_cmpint(uval, =3D=3D, value_u64); + QDECREF(qnum); + qnum =3D qobject_to_qnum(qobject_from_jsonf("%f", valuef)); g_assert(qnum_get_double(qnum) =3D=3D valuef); QDECREF(qnum); --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017451496359.4554732106682; Tue, 25 Jul 2017 14:17:31 -0700 (PDT) Received: from localhost ([::1]:34654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7Cq-0002yj-Su for importer@patchew.org; Tue, 25 Jul 2017 17:17:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7B9-00020y-59 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7B7-00042s-UB for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7B7-00042C-N6 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABC45A102D for ; Tue, 25 Jul 2017 21:15:40 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 114EA5C470; Tue, 25 Jul 2017 21:15:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ABC45A102D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:13 -0500 Message-Id: <20170725211523.3998-3-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 25 Jul 2017 21:15:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 02/12] qtest: Avoid passing raw strings through hmp() 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: armbru@redhat.com, stefanha@redhat.com 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" The next patch will add __attribute__((__format__)) to hmp(), which in turn causes gcc to warn about non-literal format strings. Rather than risk an arbitrary string containing % being mis-handled, always pass variable strings along with a %s format. It also makes it easier to prove correctness locally, rather than auditing all the source strings. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170720214008.28494-4-eblake@redhat.com> Signed-off-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- tests/test-hmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-hmp.c b/tests/test-hmp.c index d77b3c8710..0af066487c 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -80,7 +80,7 @@ static void test_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", hmp_cmds[i]); } - response =3D hmp(hmp_cmds[i]); + response =3D hmp("%s", hmp_cmds[i]); g_free(response); } @@ -103,7 +103,7 @@ static void test_info_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", info); } - resp =3D hmp(info); + resp =3D hmp("%s", info); g_free(resp); /* And move forward to the next line */ info =3D strchr(endp + 1, '\n'); --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017848974855.8453028820468; Tue, 25 Jul 2017 14:24:08 -0700 (PDT) Received: from localhost ([::1]:34686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7JH-00006l-GU for importer@patchew.org; Tue, 25 Jul 2017 17:24:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BA-000217-Jw for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7B8-00043N-Ph for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7B8-00042m-FP for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94624C0BFD10 for ; Tue, 25 Jul 2017 21:15:41 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id E27855C7C1; Tue, 25 Jul 2017 21:15:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 94624C0BFD10 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:14 -0500 Message-Id: <20170725211523.3998-4-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 25 Jul 2017 21:15:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 03/12] qtest: Document calling conventions 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: armbru@redhat.com, stefanha@redhat.com 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" We have two flavors of vararg usage in qtest; make it clear that qmp() has different semantics than hmp(), and let the compiler enforce that hmp() is used correctly. However, qmp() (and friends) only accept a subset of printf flags look-alikes (namely, those that our JSON parser understands), and what is worse, qmp("true") (the JSON keyword 'true') is different from qmp("%s", "true") (the JSON string '"true"'), and we have some intermediate cleanup patches to do before we can mark those as printf-like. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- v3: restore lost attributes, add comments on va_list forms, tweak commit message to mention upcoming qmp cleanups v2: several comment tweaks, explain why qmp() can't be marked --- tests/libqtest.h | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 38bc1e9953..82e89b4d4f 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -50,7 +50,8 @@ void qtest_quit(QTestState *s); /** * qtest_qmp_discard_response: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * * Sends a QMP message to QEMU and consumes the response. */ @@ -59,7 +60,8 @@ void qtest_qmp_discard_response(QTestState *s, const char= *fmt, ...); /** * qtest_qmp: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * * Sends a QMP message to QEMU and returns the response. */ @@ -68,7 +70,8 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); /** * qtest_async_qmp: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * * Sends a QMP message to QEMU and leaves the response in the stream. */ @@ -77,7 +80,8 @@ void qtest_async_qmp(QTestState *s, const char *fmt, ...); /** * qtest_qmpv_discard_response: * @s: #QTestState instance to operate on. - * @fmt: QMP message to send to QEMU + * @fmt: QMP message to send to QEMU; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * @ap: QMP message arguments * * Sends a QMP message to QEMU and consumes the response. @@ -87,7 +91,8 @@ void qtest_qmpv_discard_response(QTestState *s, const cha= r *fmt, va_list ap); /** * qtest_qmpv: * @s: #QTestState instance to operate on. - * @fmt: QMP message to send to QEMU + * @fmt: QMP message to send to QEMU; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * @ap: QMP message arguments * * Sends a QMP message to QEMU and returns the response. @@ -97,7 +102,8 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_lis= t ap); /** * qtest_async_qmpv: * @s: #QTestState instance to operate on. - * @fmt: QMP message to send to QEMU + * @fmt: QMP message to send to QEMU; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * @ap: QMP message arguments * * Sends a QMP message to QEMU and leaves the response in the stream. @@ -134,19 +140,19 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const c= har *event); /** * qtest_hmp: * @s: #QTestState instance to operate on. - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, formats arguments like vsprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * QMP events are discarded. * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmp(QTestState *s, const char *fmt, ...); +char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); /** * qtest_hmpv: * @s: #QTestState instance to operate on. - * @fmt: HMP command to send to QEMU + * @fmt: HMP command to send to QEMU, formats arguments like vsprintf(). * @ap: HMP command arguments * * Send HMP command to QEMU via QMP's human-monitor-command. @@ -154,7 +160,8 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...); * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap); +char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); /** * qtest_get_irq: @@ -535,7 +542,8 @@ static inline void qtest_end(void) /** * qmp: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * * Sends a QMP message to QEMU and returns the response. */ @@ -543,7 +551,8 @@ QDict *qmp(const char *fmt, ...); /** * qmp_async: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * * Sends a QMP message to QEMU and leaves the response in the stream. */ @@ -551,7 +560,8 @@ void qmp_async(const char *fmt, ...); /** * qmp_discard_response: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). * * Sends a QMP message to QEMU and consumes the response. */ @@ -592,13 +602,13 @@ static inline QDict *qmp_eventwait_ref(const char *ev= ent) /** * hmp: - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, formats arguments like vsprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * * Returns: the command's output. The caller should g_free() it. */ -char *hmp(const char *fmt, ...); +char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); /** * get_irq: --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017624315199.05403591155368; Tue, 25 Jul 2017 14:20:24 -0700 (PDT) Received: from localhost ([::1]:34662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7Fe-0005K6-Nm for importer@patchew.org; Tue, 25 Jul 2017 17:20:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BM-0002AE-8f for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BL-0004MN-9k for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50678) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BF-0004Ap-RJ; Tue, 25 Jul 2017 17:15:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D009B7EA87; Tue, 25 Jul 2017 21:15:48 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2C2B5C7C1; Tue, 25 Jul 2017 21:15:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D009B7EA87 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:15 -0500 Message-Id: <20170725211523.3998-5-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 25 Jul 2017 21:15:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 04/12] tests: Pass literal format strings directly to qmp_FOO() 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: "open list:IDE" , John Snow , armbru@redhat.com, stefanha@redhat.com 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" From: Markus Armbruster The qmp_FOO() take a printf-like format string. In a few places, we assign a string literal to a variable and pass that instead of simply passing the literal. Clean that up. Bonus: gets rid of non-literal format strings. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Signed-off-by: Markus Armbruster Message-Id: <1500645206-13559-4-git-send-email-armbru@redhat.com> Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi Reviewed-by: John Snow --- tests/ahci-test.c | 4 +--- tests/ide-test.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 999121bb7c..97622e0044 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -1350,7 +1350,6 @@ static void test_flush_migrate(void) AHCIQState *src, *dst; AHCICommand *cmd; uint8_t px; - const char *s; char *uri =3D g_strdup_printf("unix:%s", mig_socket); prepare_blkdebug_script(debug_path, "flush_to_disk"); @@ -1386,8 +1385,7 @@ static void test_flush_migrate(void) ahci_migrate(src, dst, uri); /* Complete the command */ - s =3D "{'execute':'cont' }"; - qmp_async(s); + qmp_async("{'execute':'cont' }"); qmp_eventwait("RESUME"); ahci_command_wait(dst, cmd); ahci_command_verify(dst, cmd); diff --git a/tests/ide-test.c b/tests/ide-test.c index bfd79ddbdc..ea2657d3d1 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -624,7 +624,6 @@ static void test_retry_flush(const char *machine) QPCIDevice *dev; QPCIBar bmdma_bar, ide_bar; uint8_t data; - const char *s; prepare_blkdebug_script(debug_path, "flush_to_disk"); @@ -652,8 +651,7 @@ static void test_retry_flush(const char *machine) qmp_eventwait("STOP"); /* Complete the command */ - s =3D "{'execute':'cont' }"; - qmp_discard_response(s); + qmp_discard_response("{'execute':'cont' }"); /* Check registers */ data =3D qpci_io_readb(dev, ide_bar, reg_device); --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017488546319.63504924463757; Tue, 25 Jul 2017 14:18:08 -0700 (PDT) Received: from localhost ([::1]:34655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7DS-0003Nv-Kl for importer@patchew.org; Tue, 25 Jul 2017 17:18:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BL-00029N-6B for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BJ-0004Iy-0p for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55811) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BI-0004Ge-Mk for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B88BA7F6A5 for ; Tue, 25 Jul 2017 21:15:51 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1743E5C6C9; Tue, 25 Jul 2017 21:15:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B88BA7F6A5 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:16 -0500 Message-Id: <20170725211523.3998-6-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 25 Jul 2017 21:15:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 05/12] tests: Clean up string interpolation into QMP input (simple cases) 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: armbru@redhat.com, stefanha@redhat.com 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" From: Markus Armbruster When you build QMP input manually like this cmd =3D g_strdup_printf("{ 'execute': 'migrate'," "'arguments': { 'uri': '%s' } }", uri); rsp =3D qmp(cmd); g_free(cmd); you're responsible for escaping the interpolated values for JSON. Not done here, and therefore works only for sufficiently nice @uri. For instance, if @uri contained a single "'", qobject_from_jsonv() would fail, qmp_fd_sendv() would misinterpret the failure as empty input and do nothing, and the test would hang waiting for a response that never comes. Leaving interpolation into JSON to qmp() is more robust: rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", uri= ); It's also more concise. Clean up the simple cases where we interpolate exactly a JSON value. Bonus: gets rid of non-literal format strings. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Signed-off-by: Markus Armbruster Message-Id: <1500645206-13559-5-git-send-email-armbru@redhat.com> Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/libqos/libqos.c | 16 +---- tests/libqos/pci-pc.c | 9 +-- tests/postcopy-test.c | 8 +-- tests/test-qga.c | 160 +++++++++++++++++++++-----------------------= ---- tests/vhost-user-test.c | 6 +- 5 files changed, 77 insertions(+), 122 deletions(-) diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 6226546c28..42c5315423 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -86,20 +86,12 @@ void set_context(QOSState *s) static QDict *qmp_execute(const char *command) { - char *fmt; - QDict *rsp; - - fmt =3D g_strdup_printf("{ 'execute': '%s' }", command); - rsp =3D qmp(fmt); - g_free(fmt); - - return rsp; + return qmp("{ 'execute': %s }", command); } void migrate(QOSState *from, QOSState *to, const char *uri) { const char *st; - char *s; QDict *rsp, *sub; bool running; @@ -114,11 +106,7 @@ void migrate(QOSState *from, QOSState *to, const char = *uri) QDECREF(rsp); /* Issue the migrate command. */ - s =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D qmp(s); - g_free(s); + rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index ded1c54c06..d40aa9dffd 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -159,14 +159,9 @@ void qpci_free_pc(QPCIBus *bus) void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) { QDict *response; - char *cmd; - cmd =3D g_strdup_printf("{'execute': 'device_del'," - " 'arguments': {" - " 'id': '%s'" - "}}", id); - response =3D qmp(cmd); - g_free(cmd); + response =3D qmp("{'execute': 'device_del', 'arguments': {'id': %s}}", + id); g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index 8142f2ab90..e2ead875a8 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -358,7 +358,7 @@ static void test_migrate(void) char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *global =3D global_qtest, *from, *to; unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; - gchar *cmd, *cmd_src, *cmd_dst; + gchar *cmd_src, *cmd_dst; QDict *rsp; char *bootpath =3D g_strdup_printf("%s/bootsect", tmpfs); @@ -445,11 +445,7 @@ static void test_migrate(void) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D qmp(cmd); - g_free(cmd); + rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); diff --git a/tests/test-qga.c b/tests/test-qga.c index 06783e7585..91a7b6e16b 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -144,12 +144,11 @@ static void test_qga_sync_delimited(gconstpointer fix) guint32 v, r =3D g_random_int(); unsigned char c; QDict *ret; - gchar *cmd; - cmd =3D g_strdup_printf("\xff{'execute': 'guest-sync-delimited'," - " 'arguments': {'id': %u } }", r); - qmp_fd_send(fixture->fd, cmd); - g_free(cmd); + qmp_fd_send(fixture->fd, + "\xff{'execute': 'guest-sync-delimited'," + " 'arguments': {'id': %u } }", + r); /* * Read and ignore garbage until resynchronized. @@ -186,7 +185,6 @@ static void test_qga_sync(gconstpointer fix) const TestFixture *fixture =3D fix; guint32 v, r =3D g_random_int(); QDict *ret; - gchar *cmd; /* * TODO guest-sync is inherently limited: we cannot distinguish @@ -199,10 +197,9 @@ static void test_qga_sync(gconstpointer fix) * invalid JSON. Testing of '\xff' handling is done in * guest-sync-delimited instead. */ - cmd =3D g_strdup_printf("{'execute': 'guest-sync'," - " 'arguments': {'id': %u } }", r); - ret =3D qmp_fd(fixture->fd, cmd); - g_free(cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-sync', 'arguments': {'id': %u } }", + r); g_assert_nonnull(ret); qmp_assert_no_error(ret); @@ -393,7 +390,7 @@ static void test_qga_file_ops(gconstpointer fix) const TestFixture *fixture =3D fix; const unsigned char helloworld[] =3D "Hello World!\n"; const char *b64; - gchar *cmd, *path, *enc; + gchar *path, *enc; unsigned char *dec; QDict *ret, *val; int64_t id, eof; @@ -411,10 +408,10 @@ static void test_qga_file_ops(gconstpointer fix) enc =3D g_base64_encode(helloworld, sizeof(helloworld)); /* write */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-write'," - " 'arguments': { 'handle': %" PRId64 "," - " 'buf-b64': '%s' } }", id, enc); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-write'," + " 'arguments': { 'handle': %" PRId64 ", 'buf-b64': %s } }= ", + id, enc); g_assert_nonnull(ret); qmp_assert_no_error(ret); @@ -424,23 +421,20 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpint(count, =3D=3D, sizeof(helloworld)); g_assert_cmpint(eof, =3D=3D, 0); QDECREF(ret); - g_free(cmd); /* flush */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-flush'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-flush'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); /* close */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); /* check content */ path =3D g_build_filename(fixture->test_dir, "foo", NULL); @@ -462,10 +456,10 @@ static void test_qga_file_ops(gconstpointer fix) QDECREF(ret); /* read */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -475,14 +469,13 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpstr(b64, =3D=3D, enc); QDECREF(ret); - g_free(cmd); g_free(enc); /* read eof */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -491,14 +484,13 @@ static void test_qga_file_ops(gconstpointer fix) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, ""); QDECREF(ret); - g_free(cmd); /* seek */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-seek'," - " 'arguments': { 'handle': %" PRId64 ", " - " 'offset': %d, 'whence': '%s' } }", - id, 6, "set"); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-seek'," + " 'arguments': { 'handle': %" PRId64 ", " + " 'offset': %d, 'whence': %s } }", + id, 6, "set"); qmp_assert_no_error(ret); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "position"); @@ -506,13 +498,12 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpint(count, =3D=3D, 6); g_assert(!eof); QDECREF(ret); - g_free(cmd); /* partial read */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -525,15 +516,13 @@ static void test_qga_file_ops(gconstpointer fix) g_free(dec); QDECREF(ret); - g_free(cmd); /* close */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); } static void test_qga_file_write_read(gconstpointer fix) @@ -541,7 +530,7 @@ static void test_qga_file_write_read(gconstpointer fix) const TestFixture *fixture =3D fix; const unsigned char helloworld[] =3D "Hello World!\n"; const char *b64; - gchar *cmd, *enc; + gchar *enc; QDict *ret, *val; int64_t id, eof; gsize count; @@ -556,10 +545,10 @@ static void test_qga_file_write_read(gconstpointer fi= x) enc =3D g_base64_encode(helloworld, sizeof(helloworld)); /* write */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-write'," - " 'arguments': { 'handle': %" PRId64 "," - " 'buf-b64': '%s' } }", id, enc); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-write'," + " 'arguments': { 'handle': %" PRId64 "," + " 'buf-b64': %s } }", id, enc); g_assert_nonnull(ret); qmp_assert_no_error(ret); @@ -569,13 +558,12 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert_cmpint(count, =3D=3D, sizeof(helloworld)); g_assert_cmpint(eof, =3D=3D, 0); QDECREF(ret); - g_free(cmd); /* read (check implicit flush) */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -584,14 +572,13 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, ""); QDECREF(ret); - g_free(cmd); /* seek to 0 */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-seek'," - " 'arguments': { 'handle': %" PRId64 ", " - " 'offset': %d, 'whence': '%s' } }", - id, 0, "set"); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-seek'," + " 'arguments': { 'handle': %" PRId64 ", " + " 'offset': %d, 'whence': %s } }", + id, 0, "set"); qmp_assert_no_error(ret); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "position"); @@ -599,13 +586,12 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert_cmpint(count, =3D=3D, 0); g_assert(!eof); QDECREF(ret); - g_free(cmd); /* read */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -614,16 +600,14 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, enc); QDECREF(ret); - g_free(cmd); g_free(enc); /* close */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); } static void test_qga_get_time(gconstpointer fix) @@ -647,7 +631,6 @@ static void test_qga_set_time(gconstpointer fix) const TestFixture *fixture =3D fix; QDict *ret; int64_t current, time; - gchar *cmd; /* get current time */ ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); @@ -673,11 +656,10 @@ static void test_qga_set_time(gconstpointer fix) QDECREF(ret); /* set back current time */ - cmd =3D g_strdup_printf("{'execute': 'guest-set-time'," - " 'arguments': { 'time': %" PRId64 " } }", - current + time * 1000); - ret =3D qmp_fd(fixture->fd, cmd); - g_free(cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-set-time'," + " 'arguments': { 'time': %" PRId64 " } }", + current + time * 1000); g_assert_nonnull(ret); qmp_assert_no_error(ret); QDECREF(ret); @@ -864,7 +846,6 @@ static void test_qga_guest_exec(gconstpointer fix) int64_t pid, now, exitcode; gsize len; bool exited; - char *cmd; /* exec 'echo foo bar' */ ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" @@ -879,10 +860,10 @@ static void test_qga_guest_exec(gconstpointer fix) /* wait for completion */ now =3D g_get_monotonic_time(); - cmd =3D g_strdup_printf("{'execute': 'guest-exec-status'," - " 'arguments': { 'pid': %" PRId64 " } }", pid); do { - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-exec-status'," + " 'arguments': { 'pid': %" PRId64 " } }", pid); g_assert_nonnull(ret); val =3D qdict_get_qdict(ret, "return"); exited =3D qdict_get_bool(val, "exited"); @@ -892,7 +873,6 @@ static void test_qga_guest_exec(gconstpointer fix) } while (!exited && g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND); g_assert(exited); - g_free(cmd); /* check stdout */ exitcode =3D qdict_get_int(val, "exitcode"); diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index d4da09f147..f2a2b6cad9 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -662,11 +662,7 @@ static void test_migrate(void) g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D qmp(cmd); - g_free(cmd); + rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017658902465.98103628585045; Tue, 25 Jul 2017 14:20:58 -0700 (PDT) Received: from localhost ([::1]:34669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7GD-0005rJ-H9 for importer@patchew.org; Tue, 25 Jul 2017 17:20:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BN-0002Ba-PL for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BM-0004P0-QI for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33160) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BM-0004NI-Kq for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A47CF12BBC for ; Tue, 25 Jul 2017 21:15:55 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF2EC1898E; Tue, 25 Jul 2017 21:15:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A47CF12BBC Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:17 -0500 Message-Id: <20170725211523.3998-7-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 25 Jul 2017 21:15:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 06/12] tests/libqos/usb: Clean up string interpolation into QMP input 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: armbru@redhat.com, stefanha@redhat.com 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" From: Markus Armbruster Leaving interpolation into JSON to qmp() is more robust than building QMP input manually, as explained in the previous commit. The case in usb_test_hotplug() is slightly more complicated: it interpolates *into* JSON values. Clean it up by building the values separately, so we can again leave interpolation to qmp(). Signed-off-by: Markus Armbruster Message-Id: <1500645206-13559-6-git-send-email-armbru@redhat.com> [fix commit message typo] Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/libqos/usb.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c index 0cdfaecda7..f88d4a6a3a 100644 --- a/tests/libqos/usb.c +++ b/tests/libqos/usb.c @@ -40,18 +40,20 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t = expect) void usb_test_hotplug(const char *hcd_id, const int port, void (*port_check)(void)) { + char id[32]; + char *bus; QDict *response; - char *cmd; - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': 'usb-tablet'," - " 'port': '%d'," - " 'bus': '%s.0'," - " 'id': 'usbdev%d'" - "}}", port, hcd_id, port); - response =3D qmp(cmd); - g_free(cmd); + sprintf(id, "usbdev%d", port); + bus =3D g_strdup_printf("%s.0", hcd_id); + response =3D qmp("{'execute': 'device_add'," + " 'arguments': {" + " 'driver': 'usb-tablet'," + " 'port': %s," + " 'bus': %s," + " 'id': %s" + " }}", id + 6, bus, id); + g_free(bus); g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); @@ -60,12 +62,8 @@ void usb_test_hotplug(const char *hcd_id, const int port, port_check(); } - cmd =3D g_strdup_printf("{'execute': 'device_del'," - " 'arguments': {" - " 'id': 'usbdev%d'" - "}}", port); - response =3D qmp(cmd); - g_free(cmd); + response =3D qmp("{'execute': 'device_del', 'arguments': { 'id': %s }}= ", + id); g_assert(response); g_assert(qdict_haskey(response, "event")); g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017797648683.2437557011764; Tue, 25 Jul 2017 14:23:17 -0700 (PDT) Received: from localhost ([::1]:34683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7IS-0007ou-1n for importer@patchew.org; Tue, 25 Jul 2017 17:23:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BP-0002DV-PQ for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BO-0004S8-Nk for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42246) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BO-0004Q9-FY for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:15:58 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A36FA9659 for ; Tue, 25 Jul 2017 21:15:57 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2C15189D3; Tue, 25 Jul 2017 21:15:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8A36FA9659 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:18 -0500 Message-Id: <20170725211523.3998-8-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 25 Jul 2017 21:15:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 07/12] qtest: Add a new helper qmp_cmd() and friends 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: armbru@redhat.com, stefanha@redhat.com 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" When interpolating a QMP command from the testsuite, we have a very common pattern that the command to be executed is a string constant, while the arguments may need to be crafted from qobject_from_jsonf() or even by hand. Make it easier to craft the arguments without having to save all the interpolation to the final qmp() call, by adding new helper functions; the function takes QObject instead of QDict in order to reduce the number of conversions between the two. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/libqtest.h | 31 +++++++++++++++++++++++++++++++ tests/libqtest.c | 25 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/tests/libqtest.h b/tests/libqtest.h index 82e89b4d4f..26930fed4d 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -68,6 +68,17 @@ void qtest_qmp_discard_response(QTestState *s, const cha= r *fmt, ...); QDict *qtest_qmp(QTestState *s, const char *fmt, ...); /** + * qtest_qmp_cmd: + * @s: #QTestState instance to operate on. + * @cmd: Command name to send + * @args: Arguments to transfer to the command, or NULL. + * + * Sends a QMP message to QEMU and returns the response. Calling this will + * reduce the reference count of @args. + */ +QDict *qtest_qmp_cmd(QTestState *s, const char *cmd, QObject *args); + +/** * qtest_async_qmp: * @s: #QTestState instance to operate on. * @fmt...: QMP message to send to qemu; formats arguments through @@ -550,6 +561,16 @@ static inline void qtest_end(void) QDict *qmp(const char *fmt, ...); /** + * qmp_cmd: + * @cmd: Command name to send + * @args: Arguments to transfer to the command, or NULL. + * + * Sends a QMP message to QEMU and returns the response. Calling this will + * reduce the reference count of @args. + */ +QDict *qmp_cmd(const char *cmd, QObject *args); + +/** * qmp_async: * @fmt...: QMP message to send to qemu; formats arguments through * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf])'). @@ -568,6 +589,16 @@ void qmp_async(const char *fmt, ...); void qmp_discard_response(const char *fmt, ...); /** + * qmp_cmd_discard_response: + * @cmd: Command name to send + * @args: Arguments to transfer to the command, or NULL. + * + * Sends a QMP message to QEMU and consumes the response. Calling this will + * reduce the reference count of @args. + */ +void qmp_cmd_discard_response(const char *cmd, QObject *args); + +/** * qmp_receive: * * Reads a QMP message from QEMU and returns the response. diff --git a/tests/libqtest.c b/tests/libqtest.c index 4a5492a603..1b57cedca1 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -540,6 +540,17 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...) return response; } +QDict *qtest_qmp_cmd(QTestState *s, const char *cmd, QObject *args) +{ + QDict *dict =3D qdict_new(); + + qdict_put_str(dict, "execute", cmd); + if (args) { + qdict_put_obj(dict, "arguments", args); + } + return qtest_qmp(s, "%p", QOBJECT(dict)); +} + void qtest_async_qmp(QTestState *s, const char *fmt, ...) { va_list ap; @@ -925,6 +936,11 @@ QDict *qmp(const char *fmt, ...) return response; } +QDict *qmp_cmd(const char *cmd, QObject *args) +{ + return qtest_qmp_cmd(global_qtest, cmd, args); +} + void qmp_async(const char *fmt, ...) { va_list ap; @@ -942,6 +958,15 @@ void qmp_discard_response(const char *fmt, ...) qtest_qmpv_discard_response(global_qtest, fmt, ap); va_end(ap); } + +void qmp_cmd_discard_response(const char *cmd, QObject *args) +{ + QDict *response; + + response =3D qmp_cmd(cmd, args); + QDECREF(response); +} + char *hmp(const char *fmt, ...) { va_list ap; --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017497374598.2578833998562; Tue, 25 Jul 2017 14:18:17 -0700 (PDT) Received: from localhost ([::1]:34656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7Db-0003Wv-TR for importer@patchew.org; Tue, 25 Jul 2017 17:18:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BY-0002If-4o for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BW-0004aT-2q for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59696) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BP-0004Sp-Tz; Tue, 25 Jul 2017 17:16:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3DD9C0587E8; Tue, 25 Jul 2017 21:15:58 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAB455B809; Tue, 25 Jul 2017 21:15:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F3DD9C0587E8 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:19 -0500 Message-Id: <20170725211523.3998-9-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 25 Jul 2017 21:15:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 08/12] qtests: convert tests to use qmp_cmd 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: "open list:IDE" , John Snow , armbru@redhat.com, stefanha@redhat.com 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" Now that we have the qmp_cmd() helper, we can further simplify some of the tests by using it. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/device-introspect-test.c | 3 +-- tests/ide-test.c | 2 +- tests/libqos/libqos.c | 5 +++-- tests/libqos/pci-pc.c | 4 ++-- tests/libqos/usb.c | 18 +++++++++--------- tests/pc-cpu-test.c | 10 +++++----- tests/postcopy-test.c | 9 +++++---- tests/vhost-user-test.c | 12 ++++++------ 8 files changed, 32 insertions(+), 31 deletions(-) diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c index f7162c023f..fc6d559e14 100644 --- a/tests/device-introspect-test.c +++ b/tests/device-introspect-test.c @@ -36,8 +36,7 @@ static QList *qom_list_types(const char *implements, bool= abstract) if (implements) { qdict_put_str(args, "implements", implements); } - resp =3D qmp("{'execute': 'qom-list-types'," - " 'arguments': %p }", args); + resp =3D qmp_cmd("qom-list-types", QOBJECT(args)); g_assert(qdict_haskey(resp, "return")); ret =3D qdict_get_qlist(resp, "return"); QINCREF(ret); diff --git a/tests/ide-test.c b/tests/ide-test.c index ea2657d3d1..75dc472e6a 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -651,7 +651,7 @@ static void test_retry_flush(const char *machine) qmp_eventwait("STOP"); /* Complete the command */ - qmp_discard_response("{'execute':'cont' }"); + qmp_cmd_discard_response("cont", NULL); /* Check registers */ data =3D qpci_io_readb(dev, ide_bar, reg_device); diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 42c5315423..18844617ae 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -4,6 +4,7 @@ #include "libqtest.h" #include "libqos/libqos.h" #include "libqos/pci.h" +#include "qapi/qmp/qjson.h" /*** Test Setup & Teardown ***/ @@ -86,7 +87,7 @@ void set_context(QOSState *s) static QDict *qmp_execute(const char *command) { - return qmp("{ 'execute': %s }", command); + return qmp_cmd(command, NULL); } void migrate(QOSState *from, QOSState *to, const char *uri) @@ -106,7 +107,7 @@ void migrate(QOSState *from, QOSState *to, const char *= uri) QDECREF(rsp); /* Issue the migrate command. */ - rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); + rsp =3D qmp_cmd("migrate", qobject_from_jsonf("{ 'uri': %s }", uri)); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index d40aa9dffd..8494671290 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -17,6 +17,7 @@ #include "hw/pci/pci_regs.h" #include "qemu-common.h" +#include "qapi/qmp/qjson.h" #define ACPI_PCIHP_ADDR 0xae00 @@ -160,8 +161,7 @@ void qpci_unplug_acpi_device_test(const char *id, uint8= _t slot) { QDict *response; - response =3D qmp("{'execute': 'device_del', 'arguments': {'id': %s}}", - id); + response =3D qmp_cmd("device_del", qobject_from_jsonf("{'id': %s}", id= )); g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c index f88d4a6a3a..a96f5ebd6a 100644 --- a/tests/libqos/usb.c +++ b/tests/libqos/usb.c @@ -15,6 +15,7 @@ #include "libqtest.h" #include "hw/usb/uhci-regs.h" #include "libqos/usb.h" +#include "qapi/qmp/qjson.h" void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, uint32_t devfn, in= t bar) { @@ -46,13 +47,13 @@ void usb_test_hotplug(const char *hcd_id, const int por= t, sprintf(id, "usbdev%d", port); bus =3D g_strdup_printf("%s.0", hcd_id); - response =3D qmp("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': 'usb-tablet'," - " 'port': %s," - " 'bus': %s," - " 'id': %s" - " }}", id + 6, bus, id); + response =3D qmp_cmd("device_add", + qobject_from_jsonf("{" + " 'driver': 'usb-tablet'," + " 'port': %s," + " 'bus': %s," + " 'id': %s" + "}", id + 6, bus, id)); g_free(bus); g_assert(response); g_assert(!qdict_haskey(response, "error")); @@ -62,8 +63,7 @@ void usb_test_hotplug(const char *hcd_id, const int port, port_check(); } - response =3D qmp("{'execute': 'device_del', 'arguments': { 'id': %s }}= ", - id); + response =3D qmp_cmd("device_del", qobject_from_jsonf("{ 'id': %s }", = id)); g_assert(response); g_assert(qdict_haskey(response, "event")); g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); diff --git a/tests/pc-cpu-test.c b/tests/pc-cpu-test.c index c4211a4e85..9eb4c16965 100644 --- a/tests/pc-cpu-test.c +++ b/tests/pc-cpu-test.c @@ -12,6 +12,7 @@ #include "qemu-common.h" #include "libqtest.h" #include "qapi/qmp/types.h" +#include "qapi/qmp/qjson.h" struct PCTestData { char *machine; @@ -37,8 +38,7 @@ static void test_pc_with_cpu_add(gconstpointer data) qtest_start(args); for (i =3D s->sockets * s->cores * s->threads; i < s->maxcpus; i++) { - response =3D qmp("{ 'execute': 'cpu-add'," - " 'arguments': { 'id': %d } }", i); + response =3D qmp_cmd("cpu-add", qobject_from_jsonf("{'id':%u}", i)= ); g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); @@ -60,9 +60,9 @@ static void test_pc_without_cpu_add(gconstpointer data) s->sockets, s->cores, s->threads, s->maxcpus); qtest_start(args); - response =3D qmp("{ 'execute': 'cpu-add'," - " 'arguments': { 'id': %d } }", - s->sockets * s->cores * s->threads); + response =3D qmp_cmd("cpu-add", + qobject_from_jsonf("{'id':%u}", + s->sockets * s->cores * s->threa= ds)); g_assert(response); g_assert(qdict_haskey(response, "error")); QDECREF(response); diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index e2ead875a8..f6e7340a6a 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -19,6 +19,7 @@ #include "chardev/char.h" #include "sysemu/sysemu.h" #include "hw/nvram/chrp_nvram.h" +#include "qapi/qmp/qjson.h" #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */ @@ -252,7 +253,7 @@ static uint64_t get_migration_pass(void) QDict *rsp, *rsp_return, *rsp_ram; uint64_t result; - rsp =3D return_or_event(qmp("{ 'execute': 'query-migrate' }")); + rsp =3D return_or_event(qmp_cmd("query-migrate", NULL)); rsp_return =3D qdict_get_qdict(rsp, "return"); if (!qdict_haskey(rsp_return, "ram")) { /* Still in setup */ @@ -273,7 +274,7 @@ static void wait_for_migration_complete(void) do { const char *status; - rsp =3D return_or_event(qmp("{ 'execute': 'query-migrate' }")); + rsp =3D return_or_event(qmp_cmd("query-migrate", NULL)); rsp_return =3D qdict_get_qdict(rsp, "return"); status =3D qdict_get_str(rsp_return, "status"); completed =3D strcmp(status, "completed") =3D=3D 0; @@ -445,13 +446,13 @@ static void test_migrate(void) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); - rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); + rsp =3D qmp_cmd("migrate", qobject_from_jsonf("{ 'uri': %s }", uri)); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); wait_for_migration_pass(); - rsp =3D return_or_event(qmp("{ 'execute': 'migrate-start-postcopy' }")= ); + rsp =3D return_or_event(qmp_cmd("migrate-start-postcopy", NULL)); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index f2a2b6cad9..88e1e20f99 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -9,6 +9,10 @@ */ #include "qemu/osdep.h" +#include +#include +#include +#include #include "libqtest.h" #include "qapi/error.h" @@ -22,15 +26,11 @@ #include "libqos/pci-pc.h" #include "libqos/virtio-pci.h" #include "qapi/error.h" +#include "qapi/qmp/qjson.h" #include "libqos/malloc-pc.h" #include "hw/virtio/virtio-net.h" -#include -#include -#include -#include - /* GLIB version compatibility flags */ #if !GLIB_CHECK_VERSION(2, 26, 0) #define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000)) @@ -662,7 +662,7 @@ static void test_migrate(void) g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); - rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); + rsp =3D qmp_cmd("migrate", qobject_from_jsonf("{ 'uri': %s }", uri)); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017775991426.794506125565; Tue, 25 Jul 2017 14:22:55 -0700 (PDT) Received: from localhost ([::1]:34681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7I6-0007Wn-Hd for importer@patchew.org; Tue, 25 Jul 2017 17:22:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BX-0002Hp-3w for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BV-0004aL-UY for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BR-0004TT-AF; Tue, 25 Jul 2017 17:16:01 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F2A3E185E; Tue, 25 Jul 2017 21:16:00 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BCCC5C7A7; Tue, 25 Jul 2017 21:15:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5F2A3E185E Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:20 -0500 Message-Id: <20170725211523.3998-10-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 25 Jul 2017 21:16:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 09/12] tests/libqos/pci: Clean up string interpolation into QMP input 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: "open list:virtio-blk" , armbru@redhat.com, stefanha@redhat.com 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" From: Markus Armbruster Leaving interpolation into JSON to qmp() is more robust than building QMP input manually, as explained in the commit before previous. The case in qpci_plug_device_test() is a bit complicated: it interpolates several JSON object members, not just a value. Clean it up by passing them in as QDict rather than string, so we can leave interpolation to qmp() here and to qobject_from_jsonf() in callers. Signed-off-by: Markus Armbruster Message-Id: <1500645206-13559-7-git-send-email-armbru@redhat.com> [use qmp_cmd for a slightly smaller diff] Signed-off-by: Eric Blake --- tests/libqos/pci.h | 2 +- tests/ivshmem-test.c | 10 +++++----- tests/libqos/pci.c | 32 +++++++++++++++++--------------- tests/virtio-blk-test.c | 5 ++++- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index ed480614ff..c981061703 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -109,6 +109,6 @@ void qpci_iounmap(QPCIDevice *dev, QPCIBar addr); QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr); void qpci_plug_device_test(const char *driver, const char *id, - uint8_t slot, const char *opts); + uint8_t slot, QDict *extra_args); void qpci_unplug_acpi_device_test(const char *id, uint8_t slot); #endif diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c index 37763425ee..38044bb01c 100644 --- a/tests/ivshmem-test.c +++ b/tests/ivshmem-test.c @@ -14,6 +14,7 @@ #include "libqos/libqos-pc.h" #include "libqos/libqos-spapr.h" #include "libqtest.h" +#include "qapi/qmp/qjson.h" #include "qemu-common.h" #define TMPSHMSIZE (1 << 20) @@ -419,19 +420,18 @@ static void test_ivshmem_server_irq(void) static void test_ivshmem_hotplug(void) { const char *arch =3D qtest_get_arch(); - gchar *opts; + QObject *extra_args =3D qobject_from_jsonf("{ 'shm': '%s', 'size': '1M= ' }", + tmpshm); qtest_start(""); - opts =3D g_strdup_printf("'shm': '%s', 'size': '1M'", tmpshm); - - qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, opts); + qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, + qobject_to_qdict(extra_args)); if (strcmp(arch, "ppc64") !=3D 0) { qpci_unplug_acpi_device_test("iv1", PCI_SLOT_HP); } qtest_end(); - g_free(opts); } static void test_ivshmem_memdev(void) diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 2dcdeade2a..2754412340 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -14,6 +14,7 @@ #include "libqos/pci.h" #include "hw/pci/pci_regs.h" +#include "qapi/qmp/qjson.h" #include "qemu/host-utils.h" void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, @@ -392,22 +393,23 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t a= ddr) } void qpci_plug_device_test(const char *driver, const char *id, - uint8_t slot, const char *opts) + uint8_t slot, QDict *extra_args) { - QDict *response; - char *cmd; - - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': '%s'," - " 'addr': '%d'," - " %s%s" - " 'id': '%s'" - "}}", driver, slot, - opts ? opts : "", opts ? "," : "", - id); - response =3D qmp(cmd); - g_free(cmd); + char addr[8]; + QDict *args, *response; + + sprintf(addr, "%d", slot); + args =3D qobject_to_qdict( + qobject_from_jsonf("{ 'driver': %s, 'addr': %s, 'id': %s}", + driver, addr, id)); + + if (extra_args) { + qdict_join(args, extra_args, true); + QDECREF(extra_args); + } + + response =3D qmp_cmd("device_add", QOBJECT(args)); + g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 0576cb16ba..64a48f40b2 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -16,6 +16,7 @@ #include "libqos/virtio-pci.h" #include "libqos/virtio-mmio.h" #include "libqos/malloc-generic.h" +#include "qapi/qmp/qjson.h" #include "qemu/bswap.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_config.h" @@ -658,12 +659,13 @@ static void pci_hotplug(void) QVirtioPCIDevice *dev; QOSState *qs; const char *arch =3D qtest_get_arch(); + QObject *extra_args =3D qobject_from_jsonf("{ 'drive': 'drive1' }"); qs =3D pci_test_start(); /* plug secondary disk */ qpci_plug_device_test("virtio-blk-pci", "drv1", PCI_SLOT_HP, - "'drive': 'drive1'"); + qobject_to_qdict(extra_args)); dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP); g_assert(dev); @@ -674,6 +676,7 @@ static void pci_hotplug(void) if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP); } + qtest_shutdown(qs); } --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501017959221284.47174385561493; Tue, 25 Jul 2017 14:25:59 -0700 (PDT) Received: from localhost ([::1]:34711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7L2-0001eY-JS for importer@patchew.org; Tue, 25 Jul 2017 17:25:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BY-0002Ih-5L for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BW-0004al-NF for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42952) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BW-0004aE-DI for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:06 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C43F63E2C for ; Tue, 25 Jul 2017 21:16:05 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FBE61898E; Tue, 25 Jul 2017 21:16:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C43F63E2C Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:21 -0500 Message-Id: <20170725211523.3998-11-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 25 Jul 2017 21:16:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 10/12] tests: Clean up wait for event 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: armbru@redhat.com, stefanha@redhat.com, Gerd Hoffmann 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" From: Markus Armbruster We still use hacks like qmp("") to wait for an event, even though we have qmp_eventwait() since commit 8fe941f, and qmp_eventwait_ref() since commit 7ffe312. Both commits neglected to convert all the existing hacks. Make up what they missed. Bonus: gets rid of empty format strings. A step towards compile-time format string checking without triggering -Wformat-zero-length. Signed-off-by: Markus Armbruster Message-Id: <1500645206-13559-8-git-send-email-armbru@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- tests/boot-order-test.c | 2 +- tests/libqos/pci-pc.c | 6 +----- tests/tco-test.c | 3 +-- tests/usb-hcd-uhci-test.c | 6 +----- tests/usb-hcd-xhci-test.c | 12 ++---------- tests/wdt_ib700-test.c | 35 ++++++++++------------------------- 6 files changed, 16 insertions(+), 48 deletions(-) diff --git a/tests/boot-order-test.c b/tests/boot-order-test.c index fc1e7941f7..9d516830dd 100644 --- a/tests/boot-order-test.c +++ b/tests/boot-order-test.c @@ -43,7 +43,7 @@ static void test_a_boot_order(const char *machine, * system_reset only requests reset. We get a RESET event after * the actual reset completes. Need to wait for that. */ - qmp_discard_response(""); /* HACK: wait for event */ + qmp_eventwait("RESET"); actual =3D read_boot_order(); g_assert_cmphex(actual, =3D=3D, expected_reboot); qtest_quit(global_qtest); diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index 8494671290..99ce39cff1 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -168,9 +168,5 @@ void qpci_unplug_acpi_device_test(const char *id, uint8= _t slot) outb(ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot); - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qmp_eventwait("DEVICE_DELETED"); } diff --git a/tests/tco-test.c b/tests/tco-test.c index c4c264eb3d..f2ed6ed91c 100644 --- a/tests/tco-test.c +++ b/tests/tco-test.c @@ -237,9 +237,8 @@ static void test_tco_max_timeout(void) static QDict *get_watchdog_action(void) { - QDict *ev =3D qmp(""); + QDict *ev =3D qmp_eventwait_ref("WATCHDOG"); QDict *data; - g_assert(!strcmp(qdict_get_str(ev, "event"), "WATCHDOG")); data =3D qdict_get_qdict(ev, "data"); QINCREF(data); diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c index 5b500fedb0..0fb7f8d223 100644 --- a/tests/usb-hcd-uhci-test.c +++ b/tests/usb-hcd-uhci-test.c @@ -68,11 +68,7 @@ static void test_usb_storage_hotplug(void) g_assert(!qdict_haskey(response, "error")); QDECREF(response); - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qmp_eventwait("DEVICE_DELETED"); } int main(int argc, char **argv) diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c index 031764da6d..c05a339894 100644 --- a/tests/usb-hcd-xhci-test.c +++ b/tests/usb-hcd-xhci-test.c @@ -57,11 +57,7 @@ static void test_usb_uas_hotplug(void) g_assert(!qdict_haskey(response, "error")); QDECREF(response); - response =3D qmp(""); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); - + qmp_eventwait("DEVICE_DELETED"); response =3D qmp("{'execute': 'device_del'," " 'arguments': {" @@ -71,11 +67,7 @@ static void test_usb_uas_hotplug(void) g_assert(!qdict_haskey(response, "error")); QDECREF(response); - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qmp_eventwait("DEVICE_DELETED"); } int main(int argc, char **argv) diff --git a/tests/wdt_ib700-test.c b/tests/wdt_ib700-test.c index 49f4f0c221..4fc8eeae86 100644 --- a/tests/wdt_ib700-test.c +++ b/tests/wdt_ib700-test.c @@ -18,26 +18,10 @@ static void qmp_check_no_event(void) QDECREF(resp); } -static QDict *qmp_get_event(const char *name) -{ - QDict *event =3D qmp(""); - QDict *data; - g_assert(qdict_haskey(event, "event")); - g_assert(!strcmp(qdict_get_str(event, "event"), name)); - - if (qdict_haskey(event, "data")) { - data =3D qdict_get_qdict(event, "data"); - QINCREF(data); - } else { - data =3D NULL; - } - - QDECREF(event); - return data; -} - static QDict *ib700_program_and_wait(QTestState *s) { + QDict *event, *data; + clock_step(NANOSECONDS_PER_SECOND * 40); qmp_check_no_event(); @@ -61,7 +45,11 @@ static QDict *ib700_program_and_wait(QTestState *s) clock_step(3 * NANOSECONDS_PER_SECOND); qmp_check_no_event(); clock_step(2 * NANOSECONDS_PER_SECOND); - return qmp_get_event("WATCHDOG"); + event =3D qmp_eventwait_ref("WATCHDOG"); + data =3D qdict_get_qdict(event, "data"); + QINCREF(data); + QDECREF(event); + return data; } @@ -73,8 +61,7 @@ static void ib700_pause(void) d =3D ib700_program_and_wait(s); g_assert(!strcmp(qdict_get_str(d, "action"), "pause")); QDECREF(d); - d =3D qmp_get_event("STOP"); - QDECREF(d); + qmp_eventwait("STOP"); qtest_end(); } @@ -86,8 +73,7 @@ static void ib700_reset(void) d =3D ib700_program_and_wait(s); g_assert(!strcmp(qdict_get_str(d, "action"), "reset")); QDECREF(d); - d =3D qmp_get_event("RESET"); - QDECREF(d); + qmp_eventwait("RESET"); qtest_end(); } @@ -99,8 +85,7 @@ static void ib700_shutdown(void) d =3D ib700_program_and_wait(s); g_assert(!strcmp(qdict_get_str(d, "action"), "reset")); QDECREF(d); - d =3D qmp_get_event("SHUTDOWN"); - QDECREF(d); + qmp_eventwait("SHUTDOWN"); qtest_end(); } --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501018065432781.2602006183049; Tue, 25 Jul 2017 14:27:45 -0700 (PDT) Received: from localhost ([::1]:34716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7Mk-0002n1-4c for importer@patchew.org; Tue, 25 Jul 2017 17:27:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7BZ-0002Jc-0r for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7BY-0004bP-63 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52664) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7BX-0004ax-PW for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6ACEA23D7 for ; Tue, 25 Jul 2017 21:16:06 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3EB4189BF; Tue, 25 Jul 2017 21:16:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D6ACEA23D7 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:22 -0500 Message-Id: <20170725211523.3998-12-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 25 Jul 2017 21:16:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 11/12] tests/libqtest: Clean up how we read the QMP greeting 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: armbru@redhat.com, stefanha@redhat.com 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" From: Markus Armbruster qtest_init() still uses the qtest_qmp_discard_response(s, "") hack to receive the greeting, even though we have qtest_qmp_receive() since commit 66e0c7b. Put it to use. Bonus: gets rid of an empty format string. A step towards compile-time format string checking without triggering -Wformat-zero-length. Signed-off-by: Markus Armbruster Message-Id: <1500645206-13559-9-git-send-email-armbru@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- tests/libqtest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 1b57cedca1..b0fcbf2872 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -230,9 +230,11 @@ QTestState *qtest_init_without_qmp_handshake(const cha= r *extra_args) QTestState *qtest_init(const char *extra_args) { QTestState *s =3D qtest_init_without_qmp_handshake(extra_args); + QDict *greeting; /* Read the QMP greeting and then do the handshake */ - qtest_qmp_discard_response(s, ""); + greeting =3D qtest_qmp_receive(s); + QDECREF(greeting); qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); return s; --=20 2.13.3 From nobody Sat May 4 02:40:26 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15010179290641014.2690851311612; Tue, 25 Jul 2017 14:25:29 -0700 (PDT) Received: from localhost ([::1]:34710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7KY-0001JX-9Z for importer@patchew.org; Tue, 25 Jul 2017 17:25:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da7Bg-0002QC-6v for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da7Bc-0004dA-0Y for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da7Bb-0004cm-Nq for qemu-devel@nongnu.org; Tue, 25 Jul 2017 17:16:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7FBFC0587E5 for ; Tue, 25 Jul 2017 21:16:10 +0000 (UTC) Received: from red.redhat.com (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18F905C7C1; Tue, 25 Jul 2017 21:16:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C7FBFC0587E5 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 16:15:23 -0500 Message-Id: <20170725211523.3998-13-eblake@redhat.com> In-Reply-To: <20170725211523.3998-1-eblake@redhat.com> References: <20170725211523.3998-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 25 Jul 2017 21:16:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 12/12] tests/libqtest: Enable compile-time format string checking 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: armbru@redhat.com, stefanha@redhat.com 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" From: Markus Armbruster qtest_qmp() & friends pass their format string and variable arguments to qobject_from_jsonv(). Unlike qobject_from_jsonv(), they aren't decorated with GCC_FMT_ATTR(). Fix that to get compile-time format string checking. Signed-off-by: Markus Armbruster Message-Id: <1500645206-13559-10-git-send-email-armbru@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- tests/libqtest.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 26930fed4d..7e1bd474aa 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -55,7 +55,8 @@ void qtest_quit(QTestState *s); * * Sends a QMP message to QEMU and consumes the response. */ -void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...); +void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); /** * qtest_qmp: @@ -65,7 +66,8 @@ void qtest_qmp_discard_response(QTestState *s, const char= *fmt, ...); * * Sends a QMP message to QEMU and returns the response. */ -QDict *qtest_qmp(QTestState *s, const char *fmt, ...); +QDict *qtest_qmp(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); /** * qtest_qmp_cmd: @@ -86,7 +88,8 @@ QDict *qtest_qmp_cmd(QTestState *s, const char *cmd, QObj= ect *args); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qtest_async_qmp(QTestState *s, const char *fmt, ...); +void qtest_async_qmp(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); /** * qtest_qmpv_discard_response: @@ -97,7 +100,8 @@ void qtest_async_qmp(QTestState *s, const char *fmt, ...= ); * * Sends a QMP message to QEMU and consumes the response. */ -void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p); +void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p) + GCC_FMT_ATTR(2, 0); /** * qtest_qmpv: @@ -108,7 +112,8 @@ void qtest_qmpv_discard_response(QTestState *s, const c= har *fmt, va_list ap); * * Sends a QMP message to QEMU and returns the response. */ -QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap); +QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); /** * qtest_async_qmpv: @@ -119,7 +124,8 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_li= st ap); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap); +void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); /** * qtest_receive: @@ -558,7 +564,7 @@ static inline void qtest_end(void) * * Sends a QMP message to QEMU and returns the response. */ -QDict *qmp(const char *fmt, ...); +QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); /** * qmp_cmd: @@ -577,7 +583,7 @@ QDict *qmp_cmd(const char *cmd, QObject *args); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qmp_async(const char *fmt, ...); +void qmp_async(const char *fmt, ...) GCC_FMT_ATTR(1, 2); /** * qmp_discard_response: @@ -586,7 +592,7 @@ void qmp_async(const char *fmt, ...); * * Sends a QMP message to QEMU and consumes the response. */ -void qmp_discard_response(const char *fmt, ...); +void qmp_discard_response(const char *fmt, ...) GCC_FMT_ATTR(1, 2); /** * qmp_cmd_discard_response: @@ -955,10 +961,10 @@ static inline int64_t clock_set(int64_t val) } QDict *qmp_fd_receive(int fd); -void qmp_fd_sendv(int fd, const char *fmt, va_list ap); -void qmp_fd_send(int fd, const char *fmt, ...); -QDict *qmp_fdv(int fd, const char *fmt, va_list ap); -QDict *qmp_fd(int fd, const char *fmt, ...); +void qmp_fd_sendv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); +void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +QDict *qmp_fdv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); +QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); /** * qtest_cb_for_every_machine: --=20 2.13.3