From nobody Wed May 1 23:12:28 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 1503091227343639.0027072590494; Fri, 18 Aug 2017 14:20:27 -0700 (PDT) Received: from localhost ([::1]:34110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diogr-0001mP-VD for importer@patchew.org; Fri, 18 Aug 2017 17:20:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocQ-0006ro-SK for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocO-0000ZR-8b for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51490) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocN-0000Yx-Pb for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:48 -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 0065EC047B82 for ; Fri, 18 Aug 2017 21:15:46 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F88260179; Fri, 18 Aug 2017 21:15:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0065EC047B82 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:30 -0500 Message-Id: <20170818211542.5380-2-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-1-eblake@redhat.com> MIME-Version: 1.0 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]); Fri, 18 Aug 2017 21:15:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v5 01/13] test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Back when the test was introduced, in commit 62c39b307, the test was set up to run qemu-ga directly on the host performing the test, and defaults to limiting itself to safe commands. At the time, it was envisioned that setting QGA_TEST_SIDE_EFFECTING in the environment could cover a few more commands, while noting the potential danger of those side effects running in the host. But this has NEVER been tested: if you enable the environment variable, the test WILL fail. One obvious reason: if you are not running as root, you'll probably get a permission failure when trying to freeze the file systems, or when changing system time. Less obvious: if you run the test as root (wow, you're brave), you could end up hanging if the test tries to log things to a temporarily frozen filesystem. But the cutest reason of all: if you get past the above hurdles, the test uses invalid JSON in test_qga_fstrim() (missing '' around the dictionary key 'minimum'), and will thus fail an assertion in qmp_fd(). Rather than leave this untested time-bomb in place, rip it out. Hopefully, as originally envisioned, we can find an opportunity to test an actual sandboxed guest where the guest-agent has full permissions and will not unduly affect the host running the test - if so, 'git revert' can be used if desired, for salvaging any useful parts of this attempt. Signed-off-by: Eric Blake Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/test-qga.c | 90 ----------------------------------------------------= ---- 1 file changed, 90 deletions(-) diff --git a/tests/test-qga.c b/tests/test-qga.c index 06783e7585..fd6bc7690f 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -642,65 +642,6 @@ static void test_qga_get_time(gconstpointer fix) QDECREF(ret); } -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'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - current =3D qdict_get_int(ret, "return"); - g_assert_cmpint(current, >, 0); - QDECREF(ret); - - /* set some old time */ - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-set-time'," - " 'arguments': { 'time': 1000 } }"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); - - /* check old time */ - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - time =3D qdict_get_int(ret, "return"); - g_assert_cmpint(time / 1000, <, G_USEC_PER_SEC * 10); - 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); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); -} - -static void test_qga_fstrim(gconstpointer fix) -{ - const TestFixture *fixture =3D fix; - QDict *ret; - QList *list; - const QListEntry *entry; - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fstrim'," - " arguments: { minimum: 4194304 } }"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - list =3D qdict_get_qlist(ret, "return"); - entry =3D qlist_first(list); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "paths")); - - QDECREF(ret); -} - static void test_qga_blacklist(gconstpointer data) { TestFixture fix; @@ -831,30 +772,6 @@ static void test_qga_fsfreeze_status(gconstpointer fix) QDECREF(ret); } -static void test_qga_fsfreeze_and_thaw(gconstpointer fix) -{ - const TestFixture *fixture =3D fix; - QDict *ret; - const gchar *status; - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-freeze'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - status =3D qdict_get_try_str(ret, "return"); - g_assert_cmpstr(status, =3D=3D, "frozen"); - QDECREF(ret); - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-thaw'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); -} - static void test_qga_guest_exec(gconstpointer fix) { const TestFixture *fixture =3D fix; @@ -1029,13 +946,6 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/guest-get-osinfo", &fix, test_qga_guest_get_osinfo); - if (g_getenv("QGA_TEST_SIDE_EFFECTING")) { - g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix, - test_qga_fsfreeze_and_thaw); - g_test_add_data_func("/qga/set-time", &fix, test_qga_set_time); - g_test_add_data_func("/qga/fstrim", &fix, test_qga_fstrim); - } - ret =3D g_test_run(); fixture_tear_down(&fix, NULL); --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091229914962.3332572360957; Fri, 18 Aug 2017 14:20:29 -0700 (PDT) Received: from localhost ([::1]:34111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diogt-0001ny-Dd for importer@patchew.org; Fri, 18 Aug 2017 17:20:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocQ-0006rl-Re for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocO-0000ZL-7B for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31779) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocN-0000Yy-Q1 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:48 -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 AE0548535D for ; Fri, 18 Aug 2017 21:15:46 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3846F60468; Fri, 18 Aug 2017 21:15:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AE0548535D 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:31 -0500 Message-Id: <20170818211542.5380-3-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 2017 21:15:46 +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 v5 02/13] qtest: Don't perform side effects inside assertion 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 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" Assertions should be separate from the side effects, since in theory, g_assert() can be disabled (in practice, we can't really ever do that). Signed-off-by: Eric Blake --- qtest.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/qtest.c b/qtest.c index 88a09e9afc..cbbfb71114 100644 --- a/qtest.c +++ b/qtest.c @@ -332,10 +332,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) strcmp(words[0], "outl") =3D=3D 0) { unsigned long addr; unsigned long value; + int ret; g_assert(words[1] && words[2]); - g_assert(qemu_strtoul(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtoul(words[2], NULL, 0, &value) =3D=3D 0); + ret =3D qemu_strtoul(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtoul(words[2], NULL, 0, &value); + g_assert(ret =3D=3D 0); g_assert(addr <=3D 0xffff); if (words[0][3] =3D=3D 'b') { @@ -352,9 +355,11 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) strcmp(words[0], "inl") =3D=3D 0) { unsigned long addr; uint32_t value =3D -1U; + int ret; g_assert(words[1]); - g_assert(qemu_strtoul(words[1], NULL, 0, &addr) =3D=3D 0); + ret =3D qemu_strtoul(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); g_assert(addr <=3D 0xffff); if (words[0][2] =3D=3D 'b') { @@ -372,10 +377,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) strcmp(words[0], "writeq") =3D=3D 0) { uint64_t addr; uint64_t value; + int ret; g_assert(words[1] && words[2]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &value) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &value); + g_assert(ret =3D=3D 0); if (words[0][5] =3D=3D 'b') { uint8_t data =3D value; @@ -401,9 +409,11 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) strcmp(words[0], "readq") =3D=3D 0) { uint64_t addr; uint64_t value =3D UINT64_C(-1); + int ret; g_assert(words[1]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); if (words[0][4] =3D=3D 'b') { uint8_t data; @@ -427,10 +437,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len, i; uint8_t *data; char *enc; + int ret; g_assert(words[1] && words[2]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); /* We'd send garbage to libqtest if len is 0 */ g_assert(len); @@ -451,10 +464,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len; uint8_t *data; gchar *b64_data; + int ret; g_assert(words[1] && words[2]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); data =3D g_malloc(len); cpu_physical_memory_read(addr, data, len); @@ -468,10 +484,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len, i; uint8_t *data; size_t data_len; + int ret; g_assert(words[1] && words[2] && words[3]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); data_len =3D strlen(words[3]); if (data_len < 3) { @@ -497,11 +516,15 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len; uint8_t *data; unsigned long pattern; + int ret; g_assert(words[1] && words[2] && words[3]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); - g_assert(qemu_strtoul(words[3], NULL, 0, &pattern) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtoul(words[3], NULL, 0, &pattern); + g_assert(ret =3D=3D 0); if (len) { data =3D g_malloc(len); @@ -517,10 +540,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint8_t *data; size_t data_len; gsize out_len; + int ret; g_assert(words[1] && words[2] && words[3]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); data_len =3D strlen(words[3]); if (data_len < 3) { @@ -551,11 +577,16 @@ static void qtest_process_command(CharBackend *chr, g= char **words) } else if (strcmp(words[0], "rtas") =3D=3D 0) { uint64_t res, args, ret; unsigned long nargs, nret; + int rc; - g_assert(qemu_strtoul(words[2], NULL, 0, &nargs) =3D=3D 0); - g_assert(qemu_strtou64(words[3], NULL, 0, &args) =3D=3D 0); - g_assert(qemu_strtoul(words[4], NULL, 0, &nret) =3D=3D 0); - g_assert(qemu_strtou64(words[5], NULL, 0, &ret) =3D=3D 0); + rc =3D qemu_strtoul(words[2], NULL, 0, &nargs); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtou64(words[3], NULL, 0, &args); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtoul(words[4], NULL, 0, &nret); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtou64(words[5], NULL, 0, &ret); + g_assert(rc =3D=3D 0); res =3D qtest_rtas_call(words[1], nargs, args, nret, ret); qtest_send_prefix(chr); @@ -565,7 +596,8 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) int64_t ns; if (words[1]) { - g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) =3D=3D 0); + int ret =3D qemu_strtoi64(words[1], NULL, 0, &ns); + g_assert(ret =3D=3D 0); } else { ns =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); } @@ -575,9 +607,11 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); } else if (qtest_enabled() && strcmp(words[0], "clock_set") =3D=3D 0) { int64_t ns; + int ret; g_assert(words[1]); - g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) =3D=3D 0); + ret =3D qemu_strtoi64(words[1], NULL, 0, &ns); + g_assert(ret =3D=3D 0); qtest_clock_warp(ns); qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091070440767.0084222509396; Fri, 18 Aug 2017 14:17:50 -0700 (PDT) Received: from localhost ([::1]:34036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioeK-0008Ak-I7 for importer@patchew.org; Fri, 18 Aug 2017 17:17:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocQ-0006rn-Ro for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocO-0000Zv-U2 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocO-0000ZC-Bg for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:48 -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 6C0C1A792 for ; Fri, 18 Aug 2017 21:15:47 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6C0960179; Fri, 18 Aug 2017 21:15:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6C0C1A792 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:32 -0500 Message-Id: <20170818211542.5380-4-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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.29]); Fri, 18 Aug 2017 21:15:47 +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 v5 03/13] libqtest: Remove dead qtest_instances variable 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 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" Prior to commit 063c23d9, we were tracking a list of parallel qtest objects, in order to safely clean up a SIGABRT handler only after the last connection quits. But when we switched to more of glib's infrastructure, the list became dead code that is never assigned to. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/libqtest.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index b9a1f180e1..3f956f09fc 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -42,7 +42,6 @@ struct QTestState }; static GHookList abrt_hooks; -static GList *qtest_instances; static struct sigaction sigact_old; #define g_assert_no_errno(ret) do { \ @@ -240,13 +239,10 @@ QTestState *qtest_init(const char *extra_args) void qtest_quit(QTestState *s) { - qtest_instances =3D g_list_remove(qtest_instances, s); g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s= )); /* Uninstall SIGABRT handler on last instance */ - if (!qtest_instances) { - cleanup_sigabrt_handler(); - } + cleanup_sigabrt_handler(); kill_qemu(s); close(s->fd); --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091070387177.14866416059715; Fri, 18 Aug 2017 14:17:50 -0700 (PDT) Received: from localhost ([::1]:34032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioeK-00089M-0Q for importer@patchew.org; Fri, 18 Aug 2017 17:17:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocQ-0006rm-Rl for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocP-0000bm-P2 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocP-0000Zn-FB for qemu-devel@nongnu.org; Fri, 18 Aug 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 8E9C23B98 for ; Fri, 18 Aug 2017 21:15:48 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id A335260179; Fri, 18 Aug 2017 21:15:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8E9C23B98 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:33 -0500 Message-Id: <20170818211542.5380-5-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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.29]); Fri, 18 Aug 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 v5 04/13] libqtest: Let socket_send() compute length 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 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" Rather than make multiple callers call strlen(), it's easier if socket_send() itself can compute a length via strlen() if none was provided (caller passes -1). Callers that can get at the length more efficiently are left that way. Signed-off-by: Eric Blake --- tests/libqtest.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 3f956f09fc..a6ce21d7f9 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -251,10 +251,13 @@ void qtest_quit(QTestState *s) g_free(s); } -static void socket_send(int fd, const char *buf, size_t size) +static void socket_send(int fd, const char *buf, ssize_t size) { size_t offset; + if (size < 0) { + size =3D strlen(buf); + } offset =3D 0; while (offset < size) { ssize_t len; @@ -274,9 +277,8 @@ static void socket_send(int fd, const char *buf, size_t= size) static void socket_sendf(int fd, const char *fmt, va_list ap) { gchar *str =3D g_strdup_vprintf(fmt, ap); - size_t size =3D strlen(str); - socket_send(fd, str, size); + socket_send(fd, str, -1); g_free(str); } @@ -858,7 +860,7 @@ void qtest_bufwrite(QTestState *s, uint64_t addr, const= void *data, size_t size) bdata =3D g_base64_encode(data, size); qtest_sendf(s, "b64write 0x%" PRIx64 " 0x%zx ", addr, size); - socket_send(s->fd, bdata, strlen(bdata)); + socket_send(s->fd, bdata, -1); socket_send(s->fd, "\n", 1); qtest_rsp(s, 0); g_free(bdata); --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091070440561.76284938057; Fri, 18 Aug 2017 14:17:50 -0700 (PDT) Received: from localhost ([::1]:34034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioeL-0008A9-51 for importer@patchew.org; Fri, 18 Aug 2017 17:17:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocR-0006s4-Bi for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocQ-0000cK-Hv for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocQ-0000bU-6r for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:50 -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 4AA194A6EB for ; Fri, 18 Aug 2017 21:15:49 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id C749460468; Fri, 18 Aug 2017 21:15:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4AA194A6EB 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:34 -0500 Message-Id: <20170818211542.5380-6-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 2017 21:15:49 +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 v5 05/13] libqtest: Use qemu_strtoul() 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 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" This will keep checkpatch happy when the next patch does code motion. Fix the include order to match HACKING when adding the needed header. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/libqtest.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index a6ce21d7f9..438a22678d 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -15,12 +15,13 @@ * */ #include "qemu/osdep.h" -#include "libqtest.h" #include #include #include +#include "libqtest.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-streamer.h" @@ -333,12 +334,14 @@ redo: g_string_free(line, TRUE); if (strcmp(words[0], "IRQ") =3D=3D 0) { - int irq; + long irq; + int ret; g_assert(words[1] !=3D NULL); g_assert(words[2] !=3D NULL); - irq =3D strtoul(words[2], NULL, 0); + ret =3D qemu_strtol(words[2], NULL, 0, &irq); + g_assert(!ret); g_assert_cmpint(irq, >=3D, 0); g_assert_cmpint(irq, <, MAX_IRQ); @@ -701,11 +704,13 @@ void qtest_outl(QTestState *s, uint16_t addr, uint32_= t value) static uint32_t qtest_in(QTestState *s, const char *cmd, uint16_t addr) { gchar **args; - uint32_t value; + int ret; + unsigned long value; qtest_sendf(s, "%s 0x%x\n", cmd, addr); args =3D qtest_rsp(s, 2); - value =3D strtoul(args[1], NULL, 0); + ret =3D qemu_strtoul(args[1], NULL, 0, &value); + g_assert(!ret && value <=3D UINT32_MAX); g_strfreev(args); return value; @@ -756,11 +761,13 @@ void qtest_writeq(QTestState *s, uint64_t addr, uint6= 4_t value) static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr) { gchar **args; + int ret; uint64_t value; qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr); args =3D qtest_rsp(s, 2); - value =3D strtoull(args[1], NULL, 0); + ret =3D qemu_strtou64(args[1], NULL, 0, &value); + g_assert(!ret); g_strfreev(args); return value; --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091536547952.793564906093; Fri, 18 Aug 2017 14:25:36 -0700 (PDT) Received: from localhost ([::1]:34410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diolr-0005qz-Ap for importer@patchew.org; Fri, 18 Aug 2017 17:25:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocS-0006sa-Rq for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocR-0000ed-CM for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocR-0000c9-3g for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:51 -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 3676A77355 for ; Fri, 18 Aug 2017 21:15:50 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 835BD60179; Fri, 18 Aug 2017 21:15:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3676A77355 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:35 -0500 Message-Id: <20170818211542.5380-7-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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.27]); Fri, 18 Aug 2017 21:15:50 +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 v5 06/13] libqtest: Topologically sort functions 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 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" Put static functions prior to public headers, in part so that improvements to qtest_start() can benefit from the static helpers without needing forward references. Code motion, with no semantic change. Signed-off-by: Eric Blake --- tests/libqtest.c | 263 +++++++++++++++++++++++++++------------------------= ---- 1 file changed, 131 insertions(+), 132 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 438a22678d..5d16351e24 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -49,7 +49,6 @@ static struct sigaction sigact_old; g_assert_cmpint(ret, !=3D, -1); \ } while (0) -static int qtest_query_target_endianness(QTestState *s); static int init_socket(const char *socket_path) { @@ -128,6 +127,137 @@ static void setup_sigabrt_handler(void) sigaction(SIGABRT, &sigact, &sigact_old); } +static void socket_send(int fd, const char *buf, ssize_t size) +{ + size_t offset; + + if (size < 0) { + size =3D strlen(buf); + } + offset =3D 0; + while (offset < size) { + ssize_t len; + + len =3D write(fd, buf + offset, size - offset); + if (len =3D=3D -1 && errno =3D=3D EINTR) { + continue; + } + + g_assert_no_errno(len); + g_assert_cmpint(len, >, 0); + + offset +=3D len; + } +} + +static void socket_sendf(int fd, const char *fmt, va_list ap) +{ + gchar *str =3D g_strdup_vprintf(fmt, ap); + + socket_send(fd, str, -1); + g_free(str); +} + +static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt,= ...) +{ + va_list ap; + + va_start(ap, fmt); + socket_sendf(s->fd, fmt, ap); + va_end(ap); +} + +static GString *qtest_recv_line(QTestState *s) +{ + GString *line; + size_t offset; + char *eol; + + while ((eol =3D strchr(s->rx->str, '\n')) =3D=3D NULL) { + ssize_t len; + char buffer[1024]; + + len =3D read(s->fd, buffer, sizeof(buffer)); + if (len =3D=3D -1 && errno =3D=3D EINTR) { + continue; + } + + if (len =3D=3D -1 || len =3D=3D 0) { + fprintf(stderr, "Broken pipe\n"); + exit(1); + } + + g_string_append_len(s->rx, buffer, len); + } + + offset =3D eol - s->rx->str; + line =3D g_string_new_len(s->rx->str, offset); + g_string_erase(s->rx, 0, offset + 1); + + return line; +} + +static gchar **qtest_rsp(QTestState *s, int expected_args) +{ + GString *line; + gchar **words; + int i; + +redo: + line =3D qtest_recv_line(s); + words =3D g_strsplit(line->str, " ", 0); + g_string_free(line, TRUE); + + if (strcmp(words[0], "IRQ") =3D=3D 0) { + long irq; + int ret; + + g_assert(words[1] !=3D NULL); + g_assert(words[2] !=3D NULL); + + ret =3D qemu_strtol(words[2], NULL, 0, &irq); + g_assert(!ret); + g_assert_cmpint(irq, >=3D, 0); + g_assert_cmpint(irq, <, MAX_IRQ); + + if (strcmp(words[1], "raise") =3D=3D 0) { + s->irq_level[irq] =3D true; + } else { + s->irq_level[irq] =3D false; + } + + g_strfreev(words); + goto redo; + } + + g_assert(words[0] !=3D NULL); + g_assert_cmpstr(words[0], =3D=3D, "OK"); + + if (expected_args) { + for (i =3D 0; i < expected_args; i++) { + g_assert(words[i] !=3D NULL); + } + } else { + g_strfreev(words); + } + + return words; +} + +static int qtest_query_target_endianness(QTestState *s) +{ + gchar **args; + int big_endian; + + qtest_sendf(s, "endianness\n"); + args =3D qtest_rsp(s, 1); + g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); + big_endian =3D strcmp(args[1], "big") =3D=3D 0; + g_strfreev(args); + + return big_endian; +} + static void cleanup_sigabrt_handler(void) { sigaction(SIGABRT, &sigact_old, NULL); @@ -252,137 +382,6 @@ void qtest_quit(QTestState *s) g_free(s); } -static void socket_send(int fd, const char *buf, ssize_t size) -{ - size_t offset; - - if (size < 0) { - size =3D strlen(buf); - } - offset =3D 0; - while (offset < size) { - ssize_t len; - - len =3D write(fd, buf + offset, size - offset); - if (len =3D=3D -1 && errno =3D=3D EINTR) { - continue; - } - - g_assert_no_errno(len); - g_assert_cmpint(len, >, 0); - - offset +=3D len; - } -} - -static void socket_sendf(int fd, const char *fmt, va_list ap) -{ - gchar *str =3D g_strdup_vprintf(fmt, ap); - - socket_send(fd, str, -1); - g_free(str); -} - -static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt,= ...) -{ - va_list ap; - - va_start(ap, fmt); - socket_sendf(s->fd, fmt, ap); - va_end(ap); -} - -static GString *qtest_recv_line(QTestState *s) -{ - GString *line; - size_t offset; - char *eol; - - while ((eol =3D strchr(s->rx->str, '\n')) =3D=3D NULL) { - ssize_t len; - char buffer[1024]; - - len =3D read(s->fd, buffer, sizeof(buffer)); - if (len =3D=3D -1 && errno =3D=3D EINTR) { - continue; - } - - if (len =3D=3D -1 || len =3D=3D 0) { - fprintf(stderr, "Broken pipe\n"); - exit(1); - } - - g_string_append_len(s->rx, buffer, len); - } - - offset =3D eol - s->rx->str; - line =3D g_string_new_len(s->rx->str, offset); - g_string_erase(s->rx, 0, offset + 1); - - return line; -} - -static gchar **qtest_rsp(QTestState *s, int expected_args) -{ - GString *line; - gchar **words; - int i; - -redo: - line =3D qtest_recv_line(s); - words =3D g_strsplit(line->str, " ", 0); - g_string_free(line, TRUE); - - if (strcmp(words[0], "IRQ") =3D=3D 0) { - long irq; - int ret; - - g_assert(words[1] !=3D NULL); - g_assert(words[2] !=3D NULL); - - ret =3D qemu_strtol(words[2], NULL, 0, &irq); - g_assert(!ret); - g_assert_cmpint(irq, >=3D, 0); - g_assert_cmpint(irq, <, MAX_IRQ); - - if (strcmp(words[1], "raise") =3D=3D 0) { - s->irq_level[irq] =3D true; - } else { - s->irq_level[irq] =3D false; - } - - g_strfreev(words); - goto redo; - } - - g_assert(words[0] !=3D NULL); - g_assert_cmpstr(words[0], =3D=3D, "OK"); - - if (expected_args) { - for (i =3D 0; i < expected_args; i++) { - g_assert(words[i] !=3D NULL); - } - } else { - g_strfreev(words); - } - - return words; -} - -static int qtest_query_target_endianness(QTestState *s) -{ - gchar **args; - int big_endian; - - qtest_sendf(s, "endianness\n"); - args =3D qtest_rsp(s, 1); - g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); - big_endian =3D strcmp(args[1], "big") =3D=3D 0; - g_strfreev(args); - - return big_endian; -} - typedef struct { JSONMessageParser parser; QDict *response; --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091388064772.1457146531399; Fri, 18 Aug 2017 14:23:08 -0700 (PDT) Received: from localhost ([::1]:34184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diojS-0003pd-6F for importer@patchew.org; Fri, 18 Aug 2017 17:23:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocS-0006sb-Ry for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocS-0000fm-4B for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocR-0000e3-QV for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:51 -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 E358681DFA for ; Fri, 18 Aug 2017 21:15:50 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F4E260179; Fri, 18 Aug 2017 21:15:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E358681DFA 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:36 -0500 Message-Id: <20170818211542.5380-8-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 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 v5 07/13] libqtest: Inline qtest_query_target_endianness() 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 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" There was only one caller; it's easier to inline things. Signed-off-by: Eric Blake --- tests/libqtest.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 5d16351e24..b6dd26e54a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -244,20 +244,6 @@ redo: return words; } -static int qtest_query_target_endianness(QTestState *s) -{ - gchar **args; - int big_endian; - - qtest_sendf(s, "endianness\n"); - args =3D qtest_rsp(s, 1); - g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); - big_endian =3D strcmp(args[1], "big") =3D=3D 0; - g_strfreev(args); - - return big_endian; -} - static void cleanup_sigabrt_handler(void) { sigaction(SIGABRT, &sigact_old, NULL); @@ -288,6 +274,7 @@ QTestState *qtest_init_without_qmp_handshake(const char= *extra_args) gchar *qmp_socket_path; gchar *command; const char *qemu_binary; + gchar **args; qemu_binary =3D getenv("QTEST_QEMU_BINARY"); if (!qemu_binary) { @@ -351,8 +338,11 @@ QTestState *qtest_init_without_qmp_handshake(const cha= r *extra_args) } /* ask endianness of the target */ - - s->big_endian =3D qtest_query_target_endianness(s); + qtest_sendf(s, "endianness\n"); + args =3D qtest_rsp(s, 1); + g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); + s->big_endian =3D strcmp(args[1], "big") =3D=3D 0; + g_strfreev(args); return s; } --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091795016382.5648393618882; Fri, 18 Aug 2017 14:29:55 -0700 (PDT) Received: from localhost ([::1]:34885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioq1-00011C-P5 for importer@patchew.org; Fri, 18 Aug 2017 17:29:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocb-000739-UJ for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dioca-0000wq-5h for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocU-0000jz-Jl; Fri, 18 Aug 2017 17:15:54 -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 A60864E4C8; Fri, 18 Aug 2017 21:15:53 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3075960468; Fri, 18 Aug 2017 21:15:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A60864E4C8 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:37 -0500 Message-Id: <20170818211542.5380-9-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 2017 21:15:53 +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 v5 08/13] tests: Rely more on global_qtest 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: John Snow , armbru@redhat.com, "open list:Floppy" 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" libqtest provides two layers of functions: qtest_*() that operate on an explicit object, and a plain version that operates on the 'global_qtest' object. However, very few tests care about the distinction, and even the tests that manipulate multiple qtest connections at once are just fine reassigning global_qtest around the blocks of code that will then operate on the updated global, rather than calling the verbose form. Before the next few patches get rid of the qtest_* layer, we first need to update the remaining few spots that were using the long form where we can instead rely on the short form. Signed-off-by: Eric Blake Acked-by: John Snow --- tests/fdc-test.c | 2 +- tests/ide-test.c | 10 +++++----- tests/ipmi-bt-test.c | 2 +- tests/ipmi-kcs-test.c | 2 +- tests/libqos/libqos-pc.c | 2 +- tests/postcopy-test.c | 14 +++++++------- tests/rtc-test.c | 9 +++------ tests/tco-test.c | 5 ++--- tests/wdt_ib700-test.c | 30 +++++++++++++++++------------- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/fdc-test.c b/tests/fdc-test.c index 325712e0f2..0b68d9aec4 100644 --- a/tests/fdc-test.c +++ b/tests/fdc-test.c @@ -565,7 +565,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); qtest_start("-device floppy,id=3Dfloppy0"); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); qtest_add_func("/fdc/cmos", test_cmos); qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start); qtest_add_func("/fdc/read_without_media", test_read_without_media); diff --git a/tests/ide-test.c b/tests/ide-test.c index aa9de065fc..505a800b44 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -462,7 +462,7 @@ static void test_bmdma_setup(void) "-drive file=3D%s,if=3Dide,serial=3D%s,cache=3Dwriteback,format=3D= raw " "-global ide-hd.ver=3D%s", tmp_path, "testdisk", "version"); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); } static void test_bmdma_teardown(void) @@ -584,7 +584,7 @@ static void test_flush(void) dev =3D get_pci_device(&bmdma_bar, &ide_bar); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); /* Dirty media so that CMD_FLUSH_CACHE will actually go to disk */ make_dirty(0); @@ -635,7 +635,7 @@ static void test_retry_flush(const char *machine) dev =3D get_pci_device(&bmdma_bar, &ide_bar); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); /* Dirty media so that CMD_FLUSH_CACHE will actually go to disk */ make_dirty(0); @@ -826,7 +826,7 @@ static void cdrom_pio_impl(int nblocks) ide_test_start("-drive if=3Dnone,file=3D%s,media=3Dcdrom,format=3Draw,= id=3Dsr0,index=3D0 " "-device ide-cd,drive=3Dsr0,bus=3Dide.0", tmp_path); dev =3D get_pci_device(&bmdma_bar, &ide_bar); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); /* PACKET command on device 0 */ qpci_io_writeb(dev, ide_bar, reg_device, 0); @@ -909,7 +909,7 @@ static void test_cdrom_dma(void) ide_test_start("-drive if=3Dnone,file=3D%s,media=3Dcdrom,format=3Draw,= id=3Dsr0,index=3D0 " "-device ide-cd,drive=3Dsr0,bus=3Dide.0", tmp_path); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); guest_buf =3D guest_alloc(guest_malloc, len); prdt[0].addr =3D cpu_to_le32(guest_buf); diff --git a/tests/ipmi-bt-test.c b/tests/ipmi-bt-test.c index 7e21a9bbcb..891f5bfb13 100644 --- a/tests/ipmi-bt-test.c +++ b/tests/ipmi-bt-test.c @@ -421,7 +421,7 @@ int main(int argc, char **argv) " -device isa-ipmi-bt,bmc=3Dbmc0", emu_port); qtest_start(cmdline); g_free(cmdline); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); qtest_add_func("/ipmi/extern/connect", test_connect); qtest_add_func("/ipmi/extern/bt_base", test_bt_base); qtest_add_func("/ipmi/extern/bt_enable_irq", test_enable_irq); diff --git a/tests/ipmi-kcs-test.c b/tests/ipmi-kcs-test.c index 178ffc1797..53127d2884 100644 --- a/tests/ipmi-kcs-test.c +++ b/tests/ipmi-kcs-test.c @@ -280,7 +280,7 @@ int main(int argc, char **argv) " -device isa-ipmi-kcs,bmc=3Dbmc0"); qtest_start(cmdline); g_free(cmdline); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); qtest_add_func("/ipmi/local/kcs_base", test_kcs_base); qtest_add_func("/ipmi/local/kcs_abort", test_kcs_abort); qtest_add_func("/ipmi/local/kcs_enable_irq", test_enable_irq); diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c index b554758802..6a2ff6608b 100644 --- a/tests/libqos/libqos-pc.c +++ b/tests/libqos/libqos-pc.c @@ -25,7 +25,7 @@ QOSState *qtest_pc_boot(const char *cmdline_fmt, ...) qs =3D qtest_vboot(&qos_ops, cmdline_fmt, ap); va_end(ap); - qtest_irq_intercept_in(global_qtest, "ioapic"); + irq_intercept_in("ioapic"); return qs; } diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index 8142f2ab90..9c4e37473d 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -236,7 +236,7 @@ static QDict *return_or_event(QDict *response) got_stop =3D true; } QDECREF(response); - return return_or_event(qtest_qmp_receive(global_qtest)); + return return_or_event(qmp_receive()); } @@ -318,13 +318,13 @@ static void check_guests_ram(void) bool hit_edge =3D false; bool bad =3D false; - qtest_memread(global_qtest, start_address, &first_byte, 1); + memread(start_address, &first_byte, 1); last_byte =3D first_byte; for (address =3D start_address + 4096; address < end_address; address = +=3D 4096) { uint8_t b; - qtest_memread(global_qtest, address, &b, 1); + memread(address, &b, 1); if (b !=3D last_byte) { if (((b + 1) % 256) =3D=3D last_byte && !hit_edge) { /* This is OK, the guest stopped at the point of @@ -474,19 +474,19 @@ static void test_migrate(void) global_qtest =3D to; - qtest_memread(to, start_address, &dest_byte_a, 1); + memread(start_address, &dest_byte_a, 1); /* Destination still running, wait for a byte to change */ do { - qtest_memread(to, start_address, &dest_byte_b, 1); + memread(start_address, &dest_byte_b, 1); usleep(10 * 1000); } while (dest_byte_a =3D=3D dest_byte_b); qmp_discard_response("{ 'execute' : 'stop'}"); /* With it stopped, check nothing changes */ - qtest_memread(to, start_address, &dest_byte_c, 1); + memread(start_address, &dest_byte_c, 1); sleep(1); - qtest_memread(to, start_address, &dest_byte_d, 1); + memread(start_address, &dest_byte_d, 1); g_assert_cmpint(dest_byte_c, =3D=3D, dest_byte_d); check_guests_ram(); diff --git a/tests/rtc-test.c b/tests/rtc-test.c index d7a96cbd79..bdd234d316 100644 --- a/tests/rtc-test.c +++ b/tests/rtc-test.c @@ -685,13 +685,12 @@ static void periodic_timer(void) int main(int argc, char **argv) { - QTestState *s =3D NULL; int ret; g_test_init(&argc, &argv, NULL); - s =3D qtest_start("-rtc clock=3Dvm"); - qtest_irq_intercept_in(s, "ioapic"); + qtest_start("-rtc clock=3Dvm"); + irq_intercept_in("ioapic"); qtest_add_func("/rtc/check-time/bcd", bcd_check_time); qtest_add_func("/rtc/check-time/dec", dec_check_time); @@ -711,9 +710,7 @@ int main(int argc, char **argv) ret =3D g_test_run(); - if (s) { - qtest_quit(s); - } + qtest_end(); return ret; } diff --git a/tests/tco-test.c b/tests/tco-test.c index c4c264eb3d..5b87bc16b9 100644 --- a/tests/tco-test.c +++ b/tests/tco-test.c @@ -54,14 +54,13 @@ static void test_end(TestData *d) static void test_init(TestData *d) { - QTestState *qs; char *s; s =3D g_strdup_printf("-machine q35 %s %s", d->noreboot ? "" : "-global ICH9-LPC.noreboot=3Dfa= lse", !d->args ? "" : d->args); - qs =3D qtest_start(s); - qtest_irq_intercept_in(qs, "ioapic"); + qtest_start(s); + irq_intercept_in("ioapic"); g_free(s); d->bus =3D qpci_init_pc(NULL); diff --git a/tests/wdt_ib700-test.c b/tests/wdt_ib700-test.c index 49f4f0c221..59ba184a82 100644 --- a/tests/wdt_ib700-test.c +++ b/tests/wdt_ib700-test.c @@ -36,7 +36,7 @@ static QDict *qmp_get_event(const char *name) return data; } -static QDict *ib700_program_and_wait(QTestState *s) +static QDict *ib700_program_and_wait(void) { clock_step(NANOSECONDS_PER_SECOND * 40); qmp_check_no_event(); @@ -68,9 +68,10 @@ static QDict *ib700_program_and_wait(QTestState *s) static void ib700_pause(void) { QDict *d; - QTestState *s =3D qtest_start("-watchdog-action pause -device ib700"); - qtest_irq_intercept_in(s, "ioapic"); - d =3D ib700_program_and_wait(s); + + qtest_start("-watchdog-action pause -device ib700"); + irq_intercept_in("ioapic"); + d =3D ib700_program_and_wait(); g_assert(!strcmp(qdict_get_str(d, "action"), "pause")); QDECREF(d); d =3D qmp_get_event("STOP"); @@ -81,9 +82,10 @@ static void ib700_pause(void) static void ib700_reset(void) { QDict *d; - QTestState *s =3D qtest_start("-watchdog-action reset -device ib700"); - qtest_irq_intercept_in(s, "ioapic"); - d =3D ib700_program_and_wait(s); + + qtest_start("-watchdog-action reset -device ib700"); + irq_intercept_in("ioapic"); + d =3D ib700_program_and_wait(); g_assert(!strcmp(qdict_get_str(d, "action"), "reset")); QDECREF(d); d =3D qmp_get_event("RESET"); @@ -94,9 +96,10 @@ static void ib700_reset(void) static void ib700_shutdown(void) { QDict *d; - QTestState *s =3D qtest_start("-watchdog-action reset -no-reboot -devi= ce ib700"); - qtest_irq_intercept_in(s, "ioapic"); - d =3D ib700_program_and_wait(s); + + qtest_start("-watchdog-action reset -no-reboot -device ib700"); + irq_intercept_in("ioapic"); + d =3D ib700_program_and_wait(); g_assert(!strcmp(qdict_get_str(d, "action"), "reset")); QDECREF(d); d =3D qmp_get_event("SHUTDOWN"); @@ -107,9 +110,10 @@ static void ib700_shutdown(void) static void ib700_none(void) { QDict *d; - QTestState *s =3D qtest_start("-watchdog-action none -device ib700"); - qtest_irq_intercept_in(s, "ioapic"); - d =3D ib700_program_and_wait(s); + + qtest_start("-watchdog-action none -device ib700"); + irq_intercept_in("ioapic"); + d =3D ib700_program_and_wait(); g_assert(!strcmp(qdict_get_str(d, "action"), "none")); QDECREF(d); qtest_end(); --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091388216543.7786684448411; Fri, 18 Aug 2017 14:23:08 -0700 (PDT) Received: from localhost ([::1]:34185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diojS-0003qN-Pv for importer@patchew.org; Fri, 18 Aug 2017 17:23:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioca-00071E-0x for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocW-0000qS-QQ for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocW-0000oF-Ex; Fri, 18 Aug 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 381B513A9D; Fri, 18 Aug 2017 21:15:55 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2E7F5C7A2; Fri, 18 Aug 2017 21:15:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 381B513A9D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:38 -0500 Message-Id: <20170818211542.5380-10-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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.29]); Fri, 18 Aug 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 v5 09/13] libqtest: Shorten a couple more qtest_* functions 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: Alexander Graf , "open list:sPAPR" , armbru@redhat.com, David Gibson 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" qtest_rtas_call() and qtest_big_endian() did not have a short version with an implied global_qtest; but changing these two functions fits with the theme of the previous patch. It doesn't hurt that we are now no longer ambiguous with the qtest_rtas_call() of include/hw/ppc/spapr_rtos.h. Signed-off-by: Eric Blake --- tests/libqos/virtio.h | 2 +- tests/libqtest.h | 18 ++++++++---------- tests/libqtest.c | 13 ++++++------- tests/libqos/rtas.c | 3 +-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 8fbcd1869c..7bca1b418a 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -93,7 +93,7 @@ struct QVirtioBus { static inline bool qvirtio_is_big_endian(QVirtioDevice *d) { /* FIXME: virtio 1.0 is always little-endian */ - return qtest_big_endian(global_qtest); + return big_endian(); } static inline uint32_t qvring_size(uint32_t num, uint32_t align) diff --git a/tests/libqtest.h b/tests/libqtest.h index 3ae570927a..28945b3f7f 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -338,19 +338,17 @@ uint64_t qtest_readq(QTestState *s, uint64_t addr); void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); /** - * qtest_rtas_call: - * @s: #QTestState instance to operate on. + * rtas_call: * @name: name of the command to call. * @nargs: Number of args. * @args: Guest address to read args from. * @nret: Number of return value. * @ret: Guest address to write return values to. * - * Call an RTAS function + * Call an RTAS function, using #global_qtest */ -uint64_t qtest_rtas_call(QTestState *s, const char *name, - uint32_t nargs, uint64_t args, - uint32_t nret, uint64_t ret); +uint64_t rtas_call(const char *name, uint32_t nargs, uint64_t args, + uint32_t nret, uint64_t ret); /** * qtest_bufread: @@ -430,12 +428,12 @@ int64_t qtest_clock_step(QTestState *s, int64_t step); int64_t qtest_clock_set(QTestState *s, int64_t val); /** - * qtest_big_endian: - * @s: QTestState instance to operate on. + * big_endian: * - * Returns: True if the architecture under test has a big endian configura= tion. + * Returns: True if the architecture under test, via #global_qtest, + * has a big endian configuration. */ -bool qtest_big_endian(QTestState *s); +bool big_endian(void); /** * qtest_get_arch: diff --git a/tests/libqtest.c b/tests/libqtest.c index b6dd26e54a..261d86df5a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -816,13 +816,12 @@ void qtest_memread(QTestState *s, uint64_t addr, void= *data, size_t size) g_strfreev(args); } -uint64_t qtest_rtas_call(QTestState *s, const char *name, - uint32_t nargs, uint64_t args, - uint32_t nret, uint64_t ret) +uint64_t rtas_call(const char *name, uint32_t nargs, uint64_t args, + uint32_t nret, uint64_t ret) { - qtest_sendf(s, "rtas %s %u 0x%"PRIx64" %u 0x%"PRIx64"\n", + qtest_sendf(global_qtest, "rtas %s %u 0x%"PRIx64" %u 0x%"PRIx64"\n", name, nargs, args, nret, ret); - qtest_rsp(s, 0); + qtest_rsp(global_qtest, 0); return 0; } @@ -947,9 +946,9 @@ char *hmp(const char *fmt, ...) return ret; } -bool qtest_big_endian(QTestState *s) +bool big_endian(void) { - return s->big_endian; + return global_qtest->big_endian; } void qtest_cb_for_every_machine(void (*cb)(const char *machine)) diff --git a/tests/libqos/rtas.c b/tests/libqos/rtas.c index 0269803ce0..e7ba7ab18f 100644 --- a/tests/libqos/rtas.c +++ b/tests/libqos/rtas.c @@ -37,8 +37,7 @@ static uint64_t qrtas_call(QGuestAllocator *alloc, const = char *name, target_ret =3D guest_alloc(alloc, nret * sizeof(uint32_t)); qrtas_copy_args(target_args, nargs, args); - res =3D qtest_rtas_call(global_qtest, name, - nargs, target_args, nret, target_ret); + res =3D rtas_call(name, nargs, target_args, nret, target_ret); qrtas_copy_ret(target_ret, nret, ret); guest_free(alloc, target_ret); --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091538110971.8757783641594; Fri, 18 Aug 2017 14:25:38 -0700 (PDT) Received: from localhost ([::1]:34416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diols-0005v9-Q9 for importer@patchew.org; Fri, 18 Aug 2017 17:25:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioca-00071F-1A for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocX-0000rl-9T for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocW-0000pA-ST for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:57 -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 EBDD6C04B952 for ; Fri, 18 Aug 2017 21:15:55 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75E9B60468; Fri, 18 Aug 2017 21:15:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EBDD6C04B952 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:39 -0500 Message-Id: <20170818211542.5380-11-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 2017 21:15:56 +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 v5 10/13] libqtest: Drop qtest_init() and qtest_qmp_discard_response() 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 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" Most of our tests were using qtest_start() to initialize the connection and then set global_qtest; the few tests that were using qtest_init() instead are still setting global_qtest shortly afterwards. So it makes more sense to just always set global_qtest, and have all callers go through a single entry point. Furthermore, we already have another qtest_init() in include/sysemu/qtest.h, with a different signature - which makes it hard to trace which version is being called based on what was being included. So, morph qtest_init() into qtest_start(), and hoist the setting of global_qtest earlier during initialization; which in turn lets the initialization sequence also benefit from the global variable. For now, having a separate qtest_end() and qtest_quit() still makes some tests easier, but hoisting the declaration so the two are side-by-side makes the overall lifecycle management of global_qtest easier to see. While reworking things, prefer 0-initialization, and simplify the initial handshake work; rendering qtest_qmp_discard_response() unused. As a bonus: it removes one spot passing an empty string through varargs, so we are one step closer to using compile-time format checking on qmp() without tripping over -Wformat-zero-length. Signed-off-by: Eric Blake --- tests/libqtest.h | 61 ++++++++++++---------------------------------= ---- tests/libqtest.c | 45 +++++++++++++----------------------- tests/postcopy-test.c | 2 +- tests/qmp-test.c | 2 +- tests/vhost-user-test.c | 3 ++- 5 files changed, 35 insertions(+), 78 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 28945b3f7f..dca62fd8da 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -24,20 +24,23 @@ typedef struct QTestState QTestState; extern QTestState *global_qtest; /** - * qtest_init: + * qtest_start: * @extra_args: other arguments to pass to QEMU. * + * Start QEMU, and complete the QMP handshake. Sets #global_qtest, which + * is returned for convenience. + * * Returns: #QTestState instance. */ -QTestState *qtest_init(const char *extra_args); +QTestState *qtest_start(const char *extra_args); /** - * qtest_init_without_qmp_handshake: + * qtest_start_without_qmp_handshake: * @extra_args: other arguments to pass to QEMU. * - * Returns: #QTestState instance. + * Starts the connection, but does no handshakes; sets #global_qtest. */ -QTestState *qtest_init_without_qmp_handshake(const char *extra_args); +void qtest_start_without_qmp_handshake(const char *extra_args); /** * qtest_quit: @@ -48,13 +51,15 @@ QTestState *qtest_init_without_qmp_handshake(const char= *extra_args); void qtest_quit(QTestState *s); /** - * qtest_qmp_discard_response: - * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * qtest_end: * - * Sends a QMP message to QEMU and consumes the response. + * Shut down the current #global_qtest QEMU process. */ -void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...); +static inline void qtest_end(void) +{ + qtest_quit(global_qtest); + global_qtest =3D NULL; +} /** * qtest_qmp: @@ -75,16 +80,6 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); 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 - * @ap: QMP message arguments - * - * Sends a QMP message to QEMU and consumes the response. - */ -void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p); - -/** * qtest_qmpv: * @s: #QTestState instance to operate on. * @fmt: QMP message to send to QEMU @@ -506,32 +501,6 @@ void qtest_add_data_func_full(const char *str, void *d= ata, void qtest_add_abrt_handler(GHookFunc fn, const void *data); /** - * qtest_start: - * @args: other arguments to pass to QEMU - * - * Start QEMU and assign the resulting #QTestState to a global variable. - * The global variable is used by "shortcut" functions documented below. - * - * Returns: #QTestState instance. - */ -static inline QTestState *qtest_start(const char *args) -{ - global_qtest =3D qtest_init(args); - return global_qtest; -} - -/** - * qtest_end: - * - * Shut down the QEMU process started by qtest_start(). - */ -static inline void qtest_end(void) -{ - qtest_quit(global_qtest); - global_qtest =3D NULL; -} - -/** * qmp: * @fmt...: QMP message to send to qemu * diff --git a/tests/libqtest.c b/tests/libqtest.c index 261d86df5a..c4e41261ab 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -266,7 +266,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *d= ata) g_hook_prepend(&abrt_hooks, hook); } -QTestState *qtest_init_without_qmp_handshake(const char *extra_args) +void qtest_start_without_qmp_handshake(const char *extra_args) { QTestState *s; int sock, qmpsock, i; @@ -282,7 +282,7 @@ QTestState *qtest_init_without_qmp_handshake(const char= *extra_args) exit(1); } - s =3D g_malloc(sizeof(*s)); + global_qtest =3D s =3D g_malloc0(sizeof(*s)); socket_path =3D g_strdup_printf("/tmp/qtest-%d.sock", getpid()); qmp_socket_path =3D g_strdup_printf("/tmp/qtest-%d.qmp", getpid()); @@ -338,24 +338,26 @@ QTestState *qtest_init_without_qmp_handshake(const ch= ar *extra_args) } /* ask endianness of the target */ - qtest_sendf(s, "endianness\n"); - args =3D qtest_rsp(s, 1); + qtest_sendf(global_qtest, "endianness\n"); + args =3D qtest_rsp(global_qtest, 1); g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); s->big_endian =3D strcmp(args[1], "big") =3D=3D 0; g_strfreev(args); - - return s; } -QTestState *qtest_init(const char *extra_args) +QTestState *qtest_start(const char *extra_args) { - QTestState *s =3D qtest_init_without_qmp_handshake(extra_args); + QDict *rsp; + + qtest_start_without_qmp_handshake(extra_args); /* Read the QMP greeting and then do the handshake */ - qtest_qmp_discard_response(s, ""); - qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); + rsp =3D qmp_fd_receive(global_qtest->qmp_fd); + QDECREF(rsp); + rsp =3D qmp("{ 'execute': 'qmp_capabilities' }"); + QDECREF(rsp); - return s; + return global_qtest; } void qtest_quit(QTestState *s) @@ -539,23 +541,6 @@ void qtest_async_qmp(QTestState *s, const char *fmt, .= ..) va_end(ap); } -void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p) -{ - QDict *response =3D qtest_qmpv(s, fmt, ap); - QDECREF(response); -} - -void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...) -{ - va_list ap; - QDict *response; - - va_start(ap, fmt); - response =3D qtest_qmpv(s, fmt, ap); - va_end(ap); - QDECREF(response); -} - QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event) { QDict *response; @@ -930,10 +915,12 @@ void qmp_async(const char *fmt, ...) void qmp_discard_response(const char *fmt, ...) { va_list ap; + QDict *response; va_start(ap, fmt); - qtest_qmpv_discard_response(global_qtest, fmt, ap); + response =3D qtest_qmpv(global_qtest, fmt, ap); va_end(ap); + QDECREF(response); } char *hmp(const char *fmt, ...) { diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index 9c4e37473d..91419ee3cb 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -404,7 +404,7 @@ static void test_migrate(void) from =3D qtest_start(cmd_src); g_free(cmd_src); - to =3D qtest_init(cmd_dst); + to =3D qtest_start(cmd_dst); g_free(cmd_dst); global_qtest =3D from; diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 5d0260b2be..3f1176f7f8 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -75,7 +75,7 @@ static void test_qmp_protocol(void) QDict *resp, *q, *ret; QList *capabilities; - global_qtest =3D qtest_init_without_qmp_handshake(common_args); + qtest_start_without_qmp_handshake(common_args); /* Test greeting */ resp =3D qmp_receive(); diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index d4da09f147..0518474b3a 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -646,7 +646,8 @@ static void test_migrate(void) g_assert_cmpint(size, =3D=3D, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)= ); cmd =3D GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri); - to =3D qtest_init(cmd); + to =3D qtest_start(cmd); + global_qtest =3D from; g_free(cmd); source =3D g_source_new(&test_migrate_source_funcs, --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091397891990.3707928488491; Fri, 18 Aug 2017 14:23:17 -0700 (PDT) Received: from localhost ([::1]:34191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diojc-0003yl-Be for importer@patchew.org; Fri, 18 Aug 2017 17:23:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocb-00073A-UM for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocY-0000tS-4m for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36084) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocX-0000rB-MW for qemu-devel@nongnu.org; Fri, 18 Aug 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 C3AFD80460 for ; Fri, 18 Aug 2017 21:15:56 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3265A60468; Fri, 18 Aug 2017 21:15:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C3AFD80460 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:40 -0500 Message-Id: <20170818211542.5380-12-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 2017 21:15:56 +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 v5 11/13] libqtest: Drop many static inline qtest_ wrappers 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 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" None of the tests were calling the long qtest_*() form, except via the static inline short forms. Remove a layer of indirection by only supporting the short form, and using global_qtest directly in the .c file. (Yes, this flies in the face of thread-safety, by relying on a global instead of passing all state through parameters, but ease of writing/maintaining tests trumps ivory-tower design, and our tests aren't really multi-threaded.) The list of affected functions (by their short name): qmp_receive qmp_eventwait qmp_eventwait_ref get_irq irq_intercept_in irq_intercept_out outb outw outl inb inw inl writeb writew writel writeq readb readw readl readq memread bufread memwrite bufwrite qmemset clock_step_next clock_step clock_set Signed-off-by: Eric Blake --- tests/libqtest.h | 563 ++++++++++-----------------------------------------= ---- tests/libqtest.c | 173 ++++++++--------- 2 files changed, 190 insertions(+), 546 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index dca62fd8da..431e546193 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -21,6 +21,15 @@ typedef struct QTestState QTestState; +/** + * global_qtest: + * The current test object. + * + * Many functions in this file implicitly operate on the current + * object; tests that need to alternate between two parallel + * connections can do so by switching which test state is current + * before issuing commands. + */ extern QTestState *global_qtest; /** @@ -46,7 +55,8 @@ void qtest_start_without_qmp_handshake(const char *extra_= args); * qtest_quit: * @s: #QTestState instance to operate on. * - * Shut down the QEMU process associated to @s. + * Shut down the QEMU process associated to @s. See also qtest_end() + * for clearing #global_qtest. */ void qtest_quit(QTestState *s); @@ -100,31 +110,31 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_= list ap); void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap); /** - * qtest_receive: - * @s: #QTestState instance to operate on. + * qmp_receive: * - * Reads a QMP message from QEMU and returns the response. + * Reads a QMP message from QEMU, using #global_qtest, and returns the + * response. */ -QDict *qtest_qmp_receive(QTestState *s); +QDict *qmp_receive(void); /** - * qtest_qmp_eventwait: - * @s: #QTestState instance to operate on. + * qmp_eventwait: * @s: #event event to wait for. * - * Continuously polls for QMP responses until it receives the desired even= t. + * Continuously polls for QMP responses, using #global_qtest, until it + * receives the desired event. */ -void qtest_qmp_eventwait(QTestState *s, const char *event); +void qmp_eventwait(const char *event); /** - * qtest_qmp_eventwait_ref: - * @s: #QTestState instance to operate on. + * qmp_eventwait_ref: * @s: #event event to wait for. * - * Continuously polls for QMP responses until it receives the desired even= t. - * Returns a copy of the event for further investigation. + * Continuously polls for QMP responses, using #global_qtest, until it + * receives the desired event. Returns a copy of the event for + * further investigation. */ -QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event); +QDict *qmp_eventwait_ref(const char *event); /** * qtest_hmp: @@ -152,185 +162,167 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...= ); char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap); /** - * qtest_get_irq: - * @s: #QTestState instance to operate on. + * get_irq: * @num: Interrupt to observe. * - * Returns: The level of the @num interrupt. + * Returns: The level of the @num interrupt, using #global_qtest. */ -bool qtest_get_irq(QTestState *s, int num); +bool get_irq(int num); /** - * qtest_irq_intercept_in: - * @s: #QTestState instance to operate on. + * irq_intercept_in: * @string: QOM path of a device. * * Associate qtest irqs with the GPIO-in pins of the device - * whose path is specified by @string. + * whose path is specified by @string, using #global_qtest. */ -void qtest_irq_intercept_in(QTestState *s, const char *string); +void irq_intercept_in(const char *string); /** - * qtest_irq_intercept_out: - * @s: #QTestState instance to operate on. + * irq_intercept_out: * @string: QOM path of a device. * * Associate qtest irqs with the GPIO-out pins of the device - * whose path is specified by @string. + * whose path is specified by @string, using #global_qtest. */ -void qtest_irq_intercept_out(QTestState *s, const char *string); +void irq_intercept_out(const char *string); /** - * qtest_outb: - * @s: #QTestState instance to operate on. + * outb: * @addr: I/O port to write to. * @value: Value being written. * - * Write an 8-bit value to an I/O port. + * Write an 8-bit value to an I/O port, using #global_qtest. */ -void qtest_outb(QTestState *s, uint16_t addr, uint8_t value); +void outb(uint16_t addr, uint8_t value); /** - * qtest_outw: - * @s: #QTestState instance to operate on. + * outw: * @addr: I/O port to write to. * @value: Value being written. * - * Write a 16-bit value to an I/O port. + * Write a 16-bit value to an I/O port, using #global_qtest. */ -void qtest_outw(QTestState *s, uint16_t addr, uint16_t value); +void outw(uint16_t addr, uint16_t value); /** - * qtest_outl: - * @s: #QTestState instance to operate on. + * outl: * @addr: I/O port to write to. * @value: Value being written. * - * Write a 32-bit value to an I/O port. + * Write a 32-bit value to an I/O port, using #global_qtest. */ -void qtest_outl(QTestState *s, uint16_t addr, uint32_t value); +void outl(uint16_t addr, uint32_t value); /** - * qtest_inb: - * @s: #QTestState instance to operate on. + * inb: * @addr: I/O port to read from. * - * Returns an 8-bit value from an I/O port. + * Returns an 8-bit value from an I/O port, using #global_qtest. */ -uint8_t qtest_inb(QTestState *s, uint16_t addr); +uint8_t inb(uint16_t addr); /** - * qtest_inw: - * @s: #QTestState instance to operate on. + * inw: * @addr: I/O port to read from. * - * Returns a 16-bit value from an I/O port. + * Returns a 16-bit value from an I/O port, using #global_qtest. */ -uint16_t qtest_inw(QTestState *s, uint16_t addr); +uint16_t inw(uint16_t addr); /** - * qtest_inl: - * @s: #QTestState instance to operate on. + * inl: * @addr: I/O port to read from. * - * Returns a 32-bit value from an I/O port. + * Returns a 32-bit value from an I/O port, using #global_qtest. */ -uint32_t qtest_inl(QTestState *s, uint16_t addr); +uint32_t inl(uint16_t addr); /** - * qtest_writeb: - * @s: #QTestState instance to operate on. + * writeb: * @addr: Guest address to write to. * @value: Value being written. * - * Writes an 8-bit value to memory. + * Writes an 8-bit value to memory, using #global_qtest. */ -void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value); +void writeb(uint64_t addr, uint8_t value); /** - * qtest_writew: - * @s: #QTestState instance to operate on. + * writew: * @addr: Guest address to write to. * @value: Value being written. * - * Writes a 16-bit value to memory. + * Writes a 16-bit value to memory, using #global_qtest. */ -void qtest_writew(QTestState *s, uint64_t addr, uint16_t value); +void writew(uint64_t addr, uint16_t value); /** - * qtest_writel: - * @s: #QTestState instance to operate on. + * writel: * @addr: Guest address to write to. * @value: Value being written. * - * Writes a 32-bit value to memory. + * Writes a 32-bit value to memory, using #global_qtest. */ -void qtest_writel(QTestState *s, uint64_t addr, uint32_t value); +void writel(uint64_t addr, uint32_t value); /** - * qtest_writeq: - * @s: #QTestState instance to operate on. + * writeq: * @addr: Guest address to write to. * @value: Value being written. * - * Writes a 64-bit value to memory. + * Writes a 64-bit value to memory, using #global_qtest. */ -void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value); +void writeq(uint64_t addr, uint64_t value); /** - * qtest_readb: - * @s: #QTestState instance to operate on. + * readb: * @addr: Guest address to read from. * - * Reads an 8-bit value from memory. + * Reads an 8-bit value from memory, using #global_qtest. * * Returns: Value read. */ -uint8_t qtest_readb(QTestState *s, uint64_t addr); +uint8_t readb(uint64_t addr); /** - * qtest_readw: - * @s: #QTestState instance to operate on. + * readw: * @addr: Guest address to read from. * - * Reads a 16-bit value from memory. + * Reads a 16-bit value from memory, using #global_qtest. * * Returns: Value read. */ -uint16_t qtest_readw(QTestState *s, uint64_t addr); +uint16_t readw(uint64_t addr); /** - * qtest_readl: - * @s: #QTestState instance to operate on. + * readl: * @addr: Guest address to read from. * - * Reads a 32-bit value from memory. + * Reads a 32-bit value from memory, using #global_qtest. * * Returns: Value read. */ -uint32_t qtest_readl(QTestState *s, uint64_t addr); +uint32_t readl(uint64_t addr); /** - * qtest_readq: - * @s: #QTestState instance to operate on. + * readq: * @addr: Guest address to read from. * - * Reads a 64-bit value from memory. + * Reads a 64-bit value from memory, using #global_qtest. * * Returns: Value read. */ -uint64_t qtest_readq(QTestState *s, uint64_t addr); +uint64_t readq(uint64_t addr); /** - * qtest_memread: - * @s: #QTestState instance to operate on. + * memread: * @addr: Guest address to read from. * @data: Pointer to where memory contents will be stored. * @size: Number of bytes to read. * - * Read guest memory into a buffer. + * Read guest memory into a buffer, using #global_qtest. */ -void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); +void memread(uint64_t addr, void *data, size_t size); /** * rtas_call: @@ -346,81 +338,76 @@ uint64_t rtas_call(const char *name, uint32_t nargs, = uint64_t args, uint32_t nret, uint64_t ret); /** - * qtest_bufread: - * @s: #QTestState instance to operate on. + * bufread: * @addr: Guest address to read from. * @data: Pointer to where memory contents will be stored. * @size: Number of bytes to read. * - * Read guest memory into a buffer and receive using a base64 encoding. + * Read guest memory into a buffer and receive using a base64 + * encoding, using #global_qtest. */ -void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size); +void bufread(uint64_t addr, void *data, size_t size); /** - * qtest_memwrite: - * @s: #QTestState instance to operate on. + * memwrite: * @addr: Guest address to write to. * @data: Pointer to the bytes that will be written to guest memory. * @size: Number of bytes to write. * - * Write a buffer to guest memory. + * Write a buffer to guest memory, using #global_qtest. */ -void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t= size); +void memwrite(uint64_t addr, const void *data, size_t size); /** - * qtest_bufwrite: - * @s: #QTestState instance to operate on. + * bufwrite: * @addr: Guest address to write to. * @data: Pointer to the bytes that will be written to guest memory. * @size: Number of bytes to write. * - * Write a buffer to guest memory and transmit using a base64 encoding. + * Write a buffer to guest memory and transmit using a base64 + * encoding, using #global_qtest. */ -void qtest_bufwrite(QTestState *s, uint64_t addr, - const void *data, size_t size); +void bufwrite(uint64_t addr, const void *data, size_t size); /** - * qtest_memset: - * @s: #QTestState instance to operate on. + * qmemset: * @addr: Guest address to write to. * @patt: Byte pattern to fill the guest memory region with. * @size: Number of bytes to write. * - * Write a pattern to guest memory. + * Write a pattern to guest memory, using #global_qtest. */ -void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size); +void qmemset(uint64_t addr, uint8_t patt, size_t size); /** - * qtest_clock_step_next: - * @s: #QTestState instance to operate on. + * clock_step_next: * - * Advance the QEMU_CLOCK_VIRTUAL to the next deadline. + * Advance the QEMU_CLOCK_VIRTUAL to the next deadline, using #global_qtes= t. * * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_step_next(QTestState *s); +int64_t clock_step_next(void); /** - * qtest_clock_step: - * @s: QTestState instance to operate on. + * clock_step: * @step: Number of nanoseconds to advance the clock by. * - * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds. + * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds, using #global_qtes= t. * * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_step(QTestState *s, int64_t step); +int64_t clock_step(int64_t step); /** - * qtest_clock_set: - * @s: QTestState instance to operate on. + * clock_set: * @val: Nanoseconds value to advance the clock to. * - * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was lau= nched. + * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was + * launched, using #global_qtest. * * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_set(QTestState *s, int64_t val); +int64_t clock_set(int64_t val); /** * big_endian: @@ -525,39 +512,6 @@ void qmp_async(const char *fmt, ...); void qmp_discard_response(const char *fmt, ...); /** - * qmp_receive: - * - * Reads a QMP message from QEMU and returns the response. - */ -static inline QDict *qmp_receive(void) -{ - return qtest_qmp_receive(global_qtest); -} - -/** - * qmp_eventwait: - * @s: #event event to wait for. - * - * Continuously polls for QMP responses until it receives the desired even= t. - */ -static inline void qmp_eventwait(const char *event) -{ - return qtest_qmp_eventwait(global_qtest, event); -} - -/** - * qmp_eventwait_ref: - * @s: #event event to wait for. - * - * Continuously polls for QMP responses until it receives the desired even= t. - * Returns a copy of the event for further investigation. - */ -static inline QDict *qmp_eventwait_ref(const char *event) -{ - return qtest_qmp_eventwait_ref(global_qtest, event); -} - -/** * hmp: * @fmt...: HMP command to send to QEMU * @@ -567,319 +521,6 @@ static inline QDict *qmp_eventwait_ref(const char *ev= ent) */ char *hmp(const char *fmt, ...); -/** - * get_irq: - * @num: Interrupt to observe. - * - * Returns: The level of the @num interrupt. - */ -static inline bool get_irq(int num) -{ - return qtest_get_irq(global_qtest, num); -} - -/** - * irq_intercept_in: - * @string: QOM path of a device. - * - * Associate qtest irqs with the GPIO-in pins of the device - * whose path is specified by @string. - */ -static inline void irq_intercept_in(const char *string) -{ - qtest_irq_intercept_in(global_qtest, string); -} - -/** - * qtest_irq_intercept_out: - * @string: QOM path of a device. - * - * Associate qtest irqs with the GPIO-out pins of the device - * whose path is specified by @string. - */ -static inline void irq_intercept_out(const char *string) -{ - qtest_irq_intercept_out(global_qtest, string); -} - -/** - * outb: - * @addr: I/O port to write to. - * @value: Value being written. - * - * Write an 8-bit value to an I/O port. - */ -static inline void outb(uint16_t addr, uint8_t value) -{ - qtest_outb(global_qtest, addr, value); -} - -/** - * outw: - * @addr: I/O port to write to. - * @value: Value being written. - * - * Write a 16-bit value to an I/O port. - */ -static inline void outw(uint16_t addr, uint16_t value) -{ - qtest_outw(global_qtest, addr, value); -} - -/** - * outl: - * @addr: I/O port to write to. - * @value: Value being written. - * - * Write a 32-bit value to an I/O port. - */ -static inline void outl(uint16_t addr, uint32_t value) -{ - qtest_outl(global_qtest, addr, value); -} - -/** - * inb: - * @addr: I/O port to read from. - * - * Reads an 8-bit value from an I/O port. - * - * Returns: Value read. - */ -static inline uint8_t inb(uint16_t addr) -{ - return qtest_inb(global_qtest, addr); -} - -/** - * inw: - * @addr: I/O port to read from. - * - * Reads a 16-bit value from an I/O port. - * - * Returns: Value read. - */ -static inline uint16_t inw(uint16_t addr) -{ - return qtest_inw(global_qtest, addr); -} - -/** - * inl: - * @addr: I/O port to read from. - * - * Reads a 32-bit value from an I/O port. - * - * Returns: Value read. - */ -static inline uint32_t inl(uint16_t addr) -{ - return qtest_inl(global_qtest, addr); -} - -/** - * writeb: - * @addr: Guest address to write to. - * @value: Value being written. - * - * Writes an 8-bit value to guest memory. - */ -static inline void writeb(uint64_t addr, uint8_t value) -{ - qtest_writeb(global_qtest, addr, value); -} - -/** - * writew: - * @addr: Guest address to write to. - * @value: Value being written. - * - * Writes a 16-bit value to guest memory. - */ -static inline void writew(uint64_t addr, uint16_t value) -{ - qtest_writew(global_qtest, addr, value); -} - -/** - * writel: - * @addr: Guest address to write to. - * @value: Value being written. - * - * Writes a 32-bit value to guest memory. - */ -static inline void writel(uint64_t addr, uint32_t value) -{ - qtest_writel(global_qtest, addr, value); -} - -/** - * writeq: - * @addr: Guest address to write to. - * @value: Value being written. - * - * Writes a 64-bit value to guest memory. - */ -static inline void writeq(uint64_t addr, uint64_t value) -{ - qtest_writeq(global_qtest, addr, value); -} - -/** - * readb: - * @addr: Guest address to read from. - * - * Reads an 8-bit value from guest memory. - * - * Returns: Value read. - */ -static inline uint8_t readb(uint64_t addr) -{ - return qtest_readb(global_qtest, addr); -} - -/** - * readw: - * @addr: Guest address to read from. - * - * Reads a 16-bit value from guest memory. - * - * Returns: Value read. - */ -static inline uint16_t readw(uint64_t addr) -{ - return qtest_readw(global_qtest, addr); -} - -/** - * readl: - * @addr: Guest address to read from. - * - * Reads a 32-bit value from guest memory. - * - * Returns: Value read. - */ -static inline uint32_t readl(uint64_t addr) -{ - return qtest_readl(global_qtest, addr); -} - -/** - * readq: - * @addr: Guest address to read from. - * - * Reads a 64-bit value from guest memory. - * - * Returns: Value read. - */ -static inline uint64_t readq(uint64_t addr) -{ - return qtest_readq(global_qtest, addr); -} - -/** - * memread: - * @addr: Guest address to read from. - * @data: Pointer to where memory contents will be stored. - * @size: Number of bytes to read. - * - * Read guest memory into a buffer. - */ -static inline void memread(uint64_t addr, void *data, size_t size) -{ - qtest_memread(global_qtest, addr, data, size); -} - -/** - * bufread: - * @addr: Guest address to read from. - * @data: Pointer to where memory contents will be stored. - * @size: Number of bytes to read. - * - * Read guest memory into a buffer, receive using a base64 encoding. - */ -static inline void bufread(uint64_t addr, void *data, size_t size) -{ - qtest_bufread(global_qtest, addr, data, size); -} - -/** - * memwrite: - * @addr: Guest address to write to. - * @data: Pointer to the bytes that will be written to guest memory. - * @size: Number of bytes to write. - * - * Write a buffer to guest memory. - */ -static inline void memwrite(uint64_t addr, const void *data, size_t size) -{ - qtest_memwrite(global_qtest, addr, data, size); -} - -/** - * bufwrite: - * @addr: Guest address to write to. - * @data: Pointer to the bytes that will be written to guest memory. - * @size: Number of bytes to write. - * - * Write a buffer to guest memory, transmit using a base64 encoding. - */ -static inline void bufwrite(uint64_t addr, const void *data, size_t size) -{ - qtest_bufwrite(global_qtest, addr, data, size); -} - -/** - * qmemset: - * @addr: Guest address to write to. - * @patt: Byte pattern to fill the guest memory region with. - * @size: Number of bytes to write. - * - * Write a pattern to guest memory. - */ -static inline void qmemset(uint64_t addr, uint8_t patt, size_t size) -{ - qtest_memset(global_qtest, addr, patt, size); -} - -/** - * clock_step_next: - * - * Advance the QEMU_CLOCK_VIRTUAL to the next deadline. - * - * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. - */ -static inline int64_t clock_step_next(void) -{ - return qtest_clock_step_next(global_qtest); -} - -/** - * clock_step: - * @step: Number of nanoseconds to advance the clock by. - * - * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds. - * - * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. - */ -static inline int64_t clock_step(int64_t step) -{ - return qtest_clock_step(global_qtest, step); -} - -/** - * clock_set: - * @val: Nanoseconds value to advance the clock to. - * - * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was lau= nched. - * - * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. - */ -static inline int64_t clock_set(int64_t val) -{ - return qtest_clock_set(global_qtest, 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, ...); diff --git a/tests/libqtest.c b/tests/libqtest.c index c4e41261ab..2998b173f0 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -426,9 +426,9 @@ QDict *qmp_fd_receive(int fd) return qmp.response; } -QDict *qtest_qmp_receive(QTestState *s) +QDict *qmp_receive(void) { - return qmp_fd_receive(s->qmp_fd); + return qmp_fd_receive(global_qtest->qmp_fd); } /** @@ -498,7 +498,7 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_li= st ap) qtest_async_qmpv(s, fmt, ap); /* Receive reply */ - return qtest_qmp_receive(s); + return qmp_fd_receive(s->qmp_fd); } QDict *qmp_fd(int fd, const char *fmt, ...) @@ -541,12 +541,12 @@ void qtest_async_qmp(QTestState *s, const char *fmt, = ...) va_end(ap); } -QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event) +QDict *qmp_eventwait_ref(const char *event) { QDict *response; for (;;) { - response =3D qtest_qmp_receive(s); + response =3D qmp_receive(); if ((qdict_haskey(response, "event")) && (strcmp(qdict_get_str(response, "event"), event) =3D=3D 0)) { return response; @@ -555,11 +555,11 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const c= har *event) } } -void qtest_qmp_eventwait(QTestState *s, const char *event) +void qmp_eventwait(const char *event) { QDict *response; - response =3D qtest_qmp_eventwait_ref(s, event); + response =3D qmp_eventwait_ref(event); QDECREF(response); } @@ -577,7 +577,7 @@ char *qtest_hmpv(QTestState *s, const char *fmt, va_lis= t ap) while (ret =3D=3D NULL && qdict_get_try_str(resp, "event")) { /* Ignore asynchronous QMP events */ QDECREF(resp); - resp =3D qtest_qmp_receive(s); + resp =3D qmp_fd_receive(s->qmp_fd); ret =3D g_strdup(qdict_get_try_str(resp, "return")); } g_assert(ret); @@ -606,83 +606,83 @@ const char *qtest_get_arch(void) return end + strlen("/qemu-system-"); } -bool qtest_get_irq(QTestState *s, int num) +bool get_irq(int num) { /* dummy operation in order to make sure irq is up to date */ - qtest_inb(s, 0); + inb(0); - return s->irq_level[num]; + return global_qtest->irq_level[num]; } -static int64_t qtest_clock_rsp(QTestState *s) +static int64_t qtest_clock_rsp(void) { gchar **words; int64_t clock; - words =3D qtest_rsp(s, 2); + words =3D qtest_rsp(global_qtest, 2); clock =3D g_ascii_strtoll(words[1], NULL, 0); g_strfreev(words); return clock; } -int64_t qtest_clock_step_next(QTestState *s) +int64_t clock_step_next(void) { - qtest_sendf(s, "clock_step\n"); - return qtest_clock_rsp(s); + qtest_sendf(global_qtest, "clock_step\n"); + return qtest_clock_rsp(); } -int64_t qtest_clock_step(QTestState *s, int64_t step) +int64_t clock_step(int64_t step) { - qtest_sendf(s, "clock_step %"PRIi64"\n", step); - return qtest_clock_rsp(s); + qtest_sendf(global_qtest, "clock_step %"PRIi64"\n", step); + return qtest_clock_rsp(); } -int64_t qtest_clock_set(QTestState *s, int64_t val) +int64_t clock_set(int64_t val) { - qtest_sendf(s, "clock_set %"PRIi64"\n", val); - return qtest_clock_rsp(s); + qtest_sendf(global_qtest, "clock_set %"PRIi64"\n", val); + return qtest_clock_rsp(); } -void qtest_irq_intercept_out(QTestState *s, const char *qom_path) +void irq_intercept_out(const char *qom_path) { - qtest_sendf(s, "irq_intercept_out %s\n", qom_path); - qtest_rsp(s, 0); + qtest_sendf(global_qtest, "irq_intercept_out %s\n", qom_path); + qtest_rsp(global_qtest, 0); } -void qtest_irq_intercept_in(QTestState *s, const char *qom_path) +void irq_intercept_in(const char *qom_path) { - qtest_sendf(s, "irq_intercept_in %s\n", qom_path); - qtest_rsp(s, 0); + qtest_sendf(global_qtest, "irq_intercept_in %s\n", qom_path); + qtest_rsp(global_qtest, 0); } -static void qtest_out(QTestState *s, const char *cmd, uint16_t addr, uint3= 2_t value) +static void out(const char *cmd, uint16_t addr, uint32_t value) { - qtest_sendf(s, "%s 0x%x 0x%x\n", cmd, addr, value); - qtest_rsp(s, 0); + qtest_sendf(global_qtest, "%s 0x%x 0x%x\n", cmd, addr, value); + qtest_rsp(global_qtest, 0); } -void qtest_outb(QTestState *s, uint16_t addr, uint8_t value) +void outb(uint16_t addr, uint8_t value) { - qtest_out(s, "outb", addr, value); + out("outb", addr, value); } -void qtest_outw(QTestState *s, uint16_t addr, uint16_t value) +void outw(uint16_t addr, uint16_t value) { - qtest_out(s, "outw", addr, value); + out("outw", addr, value); } -void qtest_outl(QTestState *s, uint16_t addr, uint32_t value) +void outl(uint16_t addr, uint32_t value) { - qtest_out(s, "outl", addr, value); + out("outl", addr, value); } -static uint32_t qtest_in(QTestState *s, const char *cmd, uint16_t addr) +static uint32_t in(const char *cmd, uint16_t addr) { gchar **args; int ret; unsigned long value; - qtest_sendf(s, "%s 0x%x\n", cmd, addr); - args =3D qtest_rsp(s, 2); + qtest_sendf(global_qtest, "%s 0x%x\n", cmd, addr); + args =3D qtest_rsp(global_qtest, 2); ret =3D qemu_strtoul(args[1], NULL, 0, &value); g_assert(!ret && value <=3D UINT32_MAX); g_strfreev(args); @@ -690,56 +690,57 @@ static uint32_t qtest_in(QTestState *s, const char *c= md, uint16_t addr) return value; } -uint8_t qtest_inb(QTestState *s, uint16_t addr) +uint8_t inb(uint16_t addr) { - return qtest_in(s, "inb", addr); + return in("inb", addr); } -uint16_t qtest_inw(QTestState *s, uint16_t addr) +uint16_t inw(uint16_t addr) { - return qtest_in(s, "inw", addr); + return in("inw", addr); } -uint32_t qtest_inl(QTestState *s, uint16_t addr) +uint32_t inl(uint16_t addr) { - return qtest_in(s, "inl", addr); + return in("inl", addr); } -static void qtest_write(QTestState *s, const char *cmd, uint64_t addr, +static void qtest_write(const char *cmd, uint64_t addr, uint64_t value) { - qtest_sendf(s, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value); - qtest_rsp(s, 0); + qtest_sendf(global_qtest, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, add= r, + value); + qtest_rsp(global_qtest, 0); } -void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value) +void writeb(uint64_t addr, uint8_t value) { - qtest_write(s, "writeb", addr, value); + qtest_write("writeb", addr, value); } -void qtest_writew(QTestState *s, uint64_t addr, uint16_t value) +void writew(uint64_t addr, uint16_t value) { - qtest_write(s, "writew", addr, value); + qtest_write("writew", addr, value); } -void qtest_writel(QTestState *s, uint64_t addr, uint32_t value) +void writel(uint64_t addr, uint32_t value) { - qtest_write(s, "writel", addr, value); + qtest_write("writel", addr, value); } -void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value) +void writeq(uint64_t addr, uint64_t value) { - qtest_write(s, "writeq", addr, value); + qtest_write("writeq", addr, value); } -static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr) +static uint64_t qtest_read(const char *cmd, uint64_t addr) { gchar **args; int ret; uint64_t value; - qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr); - args =3D qtest_rsp(s, 2); + qtest_sendf(global_qtest, "%s 0x%" PRIx64 "\n", cmd, addr); + args =3D qtest_rsp(global_qtest, 2); ret =3D qemu_strtou64(args[1], NULL, 0, &value); g_assert(!ret); g_strfreev(args); @@ -747,24 +748,24 @@ static uint64_t qtest_read(QTestState *s, const char = *cmd, uint64_t addr) return value; } -uint8_t qtest_readb(QTestState *s, uint64_t addr) +uint8_t readb(uint64_t addr) { - return qtest_read(s, "readb", addr); + return qtest_read("readb", addr); } -uint16_t qtest_readw(QTestState *s, uint64_t addr) +uint16_t readw(uint64_t addr) { - return qtest_read(s, "readw", addr); + return qtest_read("readw", addr); } -uint32_t qtest_readl(QTestState *s, uint64_t addr) +uint32_t readl(uint64_t addr) { - return qtest_read(s, "readl", addr); + return qtest_read("readl", addr); } -uint64_t qtest_readq(QTestState *s, uint64_t addr) +uint64_t readq(uint64_t addr) { - return qtest_read(s, "readq", addr); + return qtest_read("readq", addr); } static int hex2nib(char ch) @@ -780,7 +781,7 @@ static int hex2nib(char ch) } } -void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size) +void memread(uint64_t addr, void *data, size_t size) { uint8_t *ptr =3D data; gchar **args; @@ -790,8 +791,8 @@ void qtest_memread(QTestState *s, uint64_t addr, void *= data, size_t size) return; } - qtest_sendf(s, "read 0x%" PRIx64 " 0x%zx\n", addr, size); - args =3D qtest_rsp(s, 2); + qtest_sendf(global_qtest, "read 0x%" PRIx64 " 0x%zx\n", addr, size); + args =3D qtest_rsp(global_qtest, 2); for (i =3D 0; i < size; i++) { ptr[i] =3D hex2nib(args[1][2 + (i * 2)]) << 4; @@ -834,25 +835,25 @@ void qtest_add_data_func(const char *str, const void = *data, g_free(path); } -void qtest_bufwrite(QTestState *s, uint64_t addr, const void *data, size_t= size) +void bufwrite(uint64_t addr, const void *data, size_t size) { gchar *bdata; bdata =3D g_base64_encode(data, size); - qtest_sendf(s, "b64write 0x%" PRIx64 " 0x%zx ", addr, size); - socket_send(s->fd, bdata, -1); - socket_send(s->fd, "\n", 1); - qtest_rsp(s, 0); + qtest_sendf(global_qtest, "b64write 0x%" PRIx64 " 0x%zx ", addr, size); + socket_send(global_qtest->fd, bdata, -1); + socket_send(global_qtest->fd, "\n", 1); + qtest_rsp(global_qtest, 0); g_free(bdata); } -void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size) +void bufread(uint64_t addr, void *data, size_t size) { gchar **args; size_t len; - qtest_sendf(s, "b64read 0x%" PRIx64 " 0x%zx\n", addr, size); - args =3D qtest_rsp(s, 2); + qtest_sendf(global_qtest, "b64read 0x%" PRIx64 " 0x%zx\n", addr, size); + args =3D qtest_rsp(global_qtest, 2); g_base64_decode_inplace(args[1], &len); if (size !=3D len) { @@ -865,7 +866,7 @@ void qtest_bufread(QTestState *s, uint64_t addr, void *= data, size_t size) g_strfreev(args); } -void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t= size) +void memwrite(uint64_t addr, const void *data, size_t size) { const uint8_t *ptr =3D data; size_t i; @@ -881,15 +882,17 @@ void qtest_memwrite(QTestState *s, uint64_t addr, con= st void *data, size_t size) sprintf(&enc[i * 2], "%02x", ptr[i]); } - qtest_sendf(s, "write 0x%" PRIx64 " 0x%zx 0x%s\n", addr, size, enc); - qtest_rsp(s, 0); + qtest_sendf(global_qtest, "write 0x%" PRIx64 " 0x%zx 0x%s\n", addr, si= ze, + enc); + qtest_rsp(global_qtest, 0); g_free(enc); } -void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t si= ze) +void qmemset(uint64_t addr, uint8_t pattern, size_t size) { - qtest_sendf(s, "memset 0x%" PRIx64 " 0x%zx 0x%02x\n", addr, size, patt= ern); - qtest_rsp(s, 0); + qtest_sendf(global_qtest, "memset 0x%" PRIx64 " 0x%zx 0x%02x\n", addr,= size, + pattern); + qtest_rsp(global_qtest, 0); } QDict *qmp(const char *fmt, ...) --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091659217114.84678548788031; Fri, 18 Aug 2017 14:27:39 -0700 (PDT) Received: from localhost ([::1]:34548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dionq-0007VN-0s for importer@patchew.org; Fri, 18 Aug 2017 17:27:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioca-00071b-Bk for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocY-0000te-NN for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocY-0000sr-Cg for qemu-devel@nongnu.org; Fri, 18 Aug 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 7C7A8C047B64 for ; Fri, 18 Aug 2017 21:15:57 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 076BD5C7A2; Fri, 18 Aug 2017 21:15:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C7A8C047B64 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:41 -0500 Message-Id: <20170818211542.5380-13-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 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 v5 12/13] libqtest: Use global_qtest in qtest_sendf() and qtest_rsp() 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 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" All callers are now passing global_qtest, just remove the parameter instead. While at it, improve the naming of the va_list variant of socket_sendf() to be more like the printf/vprintf naming scheme. Signed-off-by: Eric Blake --- tests/libqtest.c | 77 +++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 2998b173f0..0ec8668c88 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -150,7 +150,7 @@ static void socket_send(int fd, const char *buf, ssize_= t size) } } -static void socket_sendf(int fd, const char *fmt, va_list ap) +static void socket_vsendf(int fd, const char *fmt, va_list ap) { gchar *str =3D g_strdup_vprintf(fmt, ap); @@ -158,12 +158,12 @@ static void socket_sendf(int fd, const char *fmt, va_= list ap) g_free(str); } -static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt,= ...) +static void GCC_FMT_ATTR(1, 2) qtest_sendf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - socket_sendf(s->fd, fmt, ap); + socket_vsendf(global_qtest->fd, fmt, ap); va_end(ap); } @@ -197,14 +197,14 @@ static GString *qtest_recv_line(QTestState *s) return line; } -static gchar **qtest_rsp(QTestState *s, int expected_args) +static gchar **qtest_rsp(int expected_args) { GString *line; gchar **words; int i; redo: - line =3D qtest_recv_line(s); + line =3D qtest_recv_line(global_qtest); words =3D g_strsplit(line->str, " ", 0); g_string_free(line, TRUE); @@ -221,9 +221,9 @@ redo: g_assert_cmpint(irq, <, MAX_IRQ); if (strcmp(words[1], "raise") =3D=3D 0) { - s->irq_level[irq] =3D true; + global_qtest->irq_level[irq] =3D true; } else { - s->irq_level[irq] =3D false; + global_qtest->irq_level[irq] =3D false; } g_strfreev(words); @@ -338,8 +338,8 @@ void qtest_start_without_qmp_handshake(const char *extr= a_args) } /* ask endianness of the target */ - qtest_sendf(global_qtest, "endianness\n"); - args =3D qtest_rsp(global_qtest, 1); + qtest_sendf("endianness\n"); + args =3D qtest_rsp(1); g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); s->big_endian =3D strcmp(args[1], "big") =3D=3D 0; g_strfreev(args); @@ -618,7 +618,7 @@ static int64_t qtest_clock_rsp(void) { gchar **words; int64_t clock; - words =3D qtest_rsp(global_qtest, 2); + words =3D qtest_rsp(2); clock =3D g_ascii_strtoll(words[1], NULL, 0); g_strfreev(words); return clock; @@ -626,38 +626,38 @@ static int64_t qtest_clock_rsp(void) int64_t clock_step_next(void) { - qtest_sendf(global_qtest, "clock_step\n"); + qtest_sendf("clock_step\n"); return qtest_clock_rsp(); } int64_t clock_step(int64_t step) { - qtest_sendf(global_qtest, "clock_step %"PRIi64"\n", step); + qtest_sendf("clock_step %"PRIi64"\n", step); return qtest_clock_rsp(); } int64_t clock_set(int64_t val) { - qtest_sendf(global_qtest, "clock_set %"PRIi64"\n", val); + qtest_sendf("clock_set %"PRIi64"\n", val); return qtest_clock_rsp(); } void irq_intercept_out(const char *qom_path) { - qtest_sendf(global_qtest, "irq_intercept_out %s\n", qom_path); - qtest_rsp(global_qtest, 0); + qtest_sendf("irq_intercept_out %s\n", qom_path); + qtest_rsp(0); } void irq_intercept_in(const char *qom_path) { - qtest_sendf(global_qtest, "irq_intercept_in %s\n", qom_path); - qtest_rsp(global_qtest, 0); + qtest_sendf("irq_intercept_in %s\n", qom_path); + qtest_rsp(0); } static void out(const char *cmd, uint16_t addr, uint32_t value) { - qtest_sendf(global_qtest, "%s 0x%x 0x%x\n", cmd, addr, value); - qtest_rsp(global_qtest, 0); + qtest_sendf("%s 0x%x 0x%x\n", cmd, addr, value); + qtest_rsp(0); } void outb(uint16_t addr, uint8_t value) @@ -681,8 +681,8 @@ static uint32_t in(const char *cmd, uint16_t addr) int ret; unsigned long value; - qtest_sendf(global_qtest, "%s 0x%x\n", cmd, addr); - args =3D qtest_rsp(global_qtest, 2); + qtest_sendf("%s 0x%x\n", cmd, addr); + args =3D qtest_rsp(2); ret =3D qemu_strtoul(args[1], NULL, 0, &value); g_assert(!ret && value <=3D UINT32_MAX); g_strfreev(args); @@ -708,9 +708,8 @@ uint32_t inl(uint16_t addr) static void qtest_write(const char *cmd, uint64_t addr, uint64_t value) { - qtest_sendf(global_qtest, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, add= r, - value); - qtest_rsp(global_qtest, 0); + qtest_sendf("%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value); + qtest_rsp(0); } void writeb(uint64_t addr, uint8_t value) @@ -739,8 +738,8 @@ static uint64_t qtest_read(const char *cmd, uint64_t ad= dr) int ret; uint64_t value; - qtest_sendf(global_qtest, "%s 0x%" PRIx64 "\n", cmd, addr); - args =3D qtest_rsp(global_qtest, 2); + qtest_sendf("%s 0x%" PRIx64 "\n", cmd, addr); + args =3D qtest_rsp(2); ret =3D qemu_strtou64(args[1], NULL, 0, &value); g_assert(!ret); g_strfreev(args); @@ -791,8 +790,8 @@ void memread(uint64_t addr, void *data, size_t size) return; } - qtest_sendf(global_qtest, "read 0x%" PRIx64 " 0x%zx\n", addr, size); - args =3D qtest_rsp(global_qtest, 2); + qtest_sendf("read 0x%" PRIx64 " 0x%zx\n", addr, size); + args =3D qtest_rsp(2); for (i =3D 0; i < size; i++) { ptr[i] =3D hex2nib(args[1][2 + (i * 2)]) << 4; @@ -805,9 +804,9 @@ void memread(uint64_t addr, void *data, size_t size) uint64_t rtas_call(const char *name, uint32_t nargs, uint64_t args, uint32_t nret, uint64_t ret) { - qtest_sendf(global_qtest, "rtas %s %u 0x%"PRIx64" %u 0x%"PRIx64"\n", + qtest_sendf("rtas %s %u 0x%"PRIx64" %u 0x%"PRIx64"\n", name, nargs, args, nret, ret); - qtest_rsp(global_qtest, 0); + qtest_rsp(0); return 0; } @@ -840,10 +839,10 @@ void bufwrite(uint64_t addr, const void *data, size_t= size) gchar *bdata; bdata =3D g_base64_encode(data, size); - qtest_sendf(global_qtest, "b64write 0x%" PRIx64 " 0x%zx ", addr, size); + qtest_sendf("b64write 0x%" PRIx64 " 0x%zx ", addr, size); socket_send(global_qtest->fd, bdata, -1); socket_send(global_qtest->fd, "\n", 1); - qtest_rsp(global_qtest, 0); + qtest_rsp(0); g_free(bdata); } @@ -852,8 +851,8 @@ void bufread(uint64_t addr, void *data, size_t size) gchar **args; size_t len; - qtest_sendf(global_qtest, "b64read 0x%" PRIx64 " 0x%zx\n", addr, size); - args =3D qtest_rsp(global_qtest, 2); + qtest_sendf("b64read 0x%" PRIx64 " 0x%zx\n", addr, size); + args =3D qtest_rsp(2); g_base64_decode_inplace(args[1], &len); if (size !=3D len) { @@ -882,17 +881,15 @@ void memwrite(uint64_t addr, const void *data, size_t= size) sprintf(&enc[i * 2], "%02x", ptr[i]); } - qtest_sendf(global_qtest, "write 0x%" PRIx64 " 0x%zx 0x%s\n", addr, si= ze, - enc); - qtest_rsp(global_qtest, 0); + qtest_sendf("write 0x%" PRIx64 " 0x%zx 0x%s\n", addr, size, enc); + qtest_rsp(0); g_free(enc); } void qmemset(uint64_t addr, uint8_t pattern, size_t size) { - qtest_sendf(global_qtest, "memset 0x%" PRIx64 " 0x%zx 0x%02x\n", addr,= size, - pattern); - qtest_rsp(global_qtest, 0); + qtest_sendf("memset 0x%" PRIx64 " 0x%zx 0x%02x\n", addr, size, pattern= ); + qtest_rsp(0); } QDict *qmp(const char *fmt, ...) --=20 2.13.5 From nobody Wed May 1 23:12:28 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 1503091674131546.4290711917391; Fri, 18 Aug 2017 14:27:54 -0700 (PDT) Received: from localhost ([::1]:34554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioo5-0007e3-2n for importer@patchew.org; Fri, 18 Aug 2017 17:27:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioca-000723-LT for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocZ-0000vm-L4 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:16:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52348) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocZ-0000ta-6s for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:59 -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 4D308C04B94A for ; Fri, 18 Aug 2017 21:15:58 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id B49C360468; Fri, 18 Aug 2017 21:15:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4D308C04B94A 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:42 -0500 Message-Id: <20170818211542.5380-14-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-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]); Fri, 18 Aug 2017 21:15:58 +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 v5 13/13] numa-test: Use 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 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" Don't open-code something that has a convenient helper available. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/numa-test.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/tests/numa-test.c b/tests/numa-test.c index 3f636840b1..e1b6152244 100644 --- a/tests/numa-test.c +++ b/tests/numa-test.c @@ -17,21 +17,6 @@ static char *make_cli(const char *generic_cli, const cha= r *test_cli) return g_strdup_printf("%s %s", generic_cli ? generic_cli : "", test_c= li); } -static char *hmp_info_numa(void) -{ - QDict *resp; - char *s; - - resp =3D qmp("{ 'execute': 'human-monitor-command', 'arguments': " - "{ 'command-line': 'info numa '} }"); - g_assert(resp); - g_assert(qdict_haskey(resp, "return")); - s =3D g_strdup(qdict_get_str(resp, "return")); - g_assert(s); - QDECREF(resp); - return s; -} - static void test_mon_explicit(const void *data) { char *s; @@ -42,7 +27,7 @@ static void test_mon_explicit(const void *data) "-numa node,nodeid=3D1,cpus=3D4-7 "); qtest_start(cli); - s =3D hmp_info_numa(); + s =3D hmp("info numa"); g_assert(strstr(s, "node 0 cpus: 0 1 2 3")); g_assert(strstr(s, "node 1 cpus: 4 5 6 7")); g_free(s); @@ -59,7 +44,7 @@ static void test_mon_default(const void *data) cli =3D make_cli(data, "-smp 8 -numa node -numa node"); qtest_start(cli); - s =3D hmp_info_numa(); + s =3D hmp("info numa"); g_assert(strstr(s, "node 0 cpus: 0 2 4 6")); g_assert(strstr(s, "node 1 cpus: 1 3 5 7")); g_free(s); @@ -78,7 +63,7 @@ static void test_mon_partial(const void *data) "-numa node,nodeid=3D1,cpus=3D4-5 "); qtest_start(cli); - s =3D hmp_info_numa(); + s =3D hmp("info numa"); g_assert(strstr(s, "node 0 cpus: 0 1 2 3 6 7")); g_assert(strstr(s, "node 1 cpus: 4 5")); g_free(s); --=20 2.13.5