From patchwork Thu Feb 8 20:09:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 10207983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E05FE602D8 for ; Thu, 8 Feb 2018 20:34:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDD8E29666 for ; Thu, 8 Feb 2018 20:34:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF49529677; Thu, 8 Feb 2018 20:34:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CF24A29666 for ; Thu, 8 Feb 2018 20:34:53 +0000 (UTC) Received: from localhost ([::1]:46095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejsuD-0008Pe-17 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Feb 2018 15:34:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejsW6-0002NC-B4 for qemu-devel@nongnu.org; Thu, 08 Feb 2018 15:10:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejsW4-0002Mj-KV for qemu-devel@nongnu.org; Thu, 08 Feb 2018 15:09:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43662 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ejsW4-0002MT-E3 for qemu-devel@nongnu.org; Thu, 08 Feb 2018 15:09:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17A7640FB62E for ; Thu, 8 Feb 2018 20:09:56 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-204-120.brq.redhat.com [10.40.204.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4885CB07B8; Thu, 8 Feb 2018 20:09:55 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org Date: Thu, 8 Feb 2018 21:09:36 +0100 Message-Id: <1518120582-26647-9-git-send-email-thuth@redhat.com> In-Reply-To: <1518120582-26647-1-git-send-email-thuth@redhat.com> References: <1518120582-26647-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 08 Feb 2018 20:09:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 08 Feb 2018 20:09:56 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 08/14] libqos: Use explicit QTestState for remaining libqos operations 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake Drop one more client of global_qtest by teaching all remaining libqos stragglers to pass in an explicit QTestState. Change the setting of global_qtest from being implicit in libqos' call to qtest_start() to instead be explicit in all clients that are still relying on global_qtest. Note that qmp_execute() can be greatly simplified in the process, and that we also get rid of interpolation of a JSON string into a temporary variable when qtest_qmp() can do it more reliably. Signed-off-by: Eric Blake Acked-by: Greg Kurz Reviewed-by: John Snow Signed-off-by: Thomas Huth --- tests/ahci-test.c | 1 + tests/ivshmem-test.c | 1 + tests/libqos/libqos-pc.c | 2 +- tests/libqos/libqos.c | 30 ++++++++++-------------------- tests/megasas-test.c | 5 ++++- tests/rtas-test.c | 1 + tests/usb-hcd-uhci-test.c | 1 + tests/virtio-9p-test.c | 1 + tests/virtio-blk-test.c | 1 + tests/virtio-net-test.c | 15 +++++++++------ tests/virtio-scsi-test.c | 16 +++++++++------- 11 files changed, 39 insertions(+), 35 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index d9c99b7..f2a3926 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -157,6 +157,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap) s = g_new0(AHCIQState, 1); s->parent = qtest_pc_vboot(cli, ap); + global_qtest = s->parent->qts; alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT); /* Verify that we have an AHCI device present. */ diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c index 3776342..8af16ee 100644 --- a/tests/ivshmem-test.c +++ b/tests/ivshmem-test.c @@ -131,6 +131,7 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix) g_printerr("ivshmem-test tests are only available on x86 or ppc64\n"); exit(EXIT_FAILURE); } + global_qtest = s->qs->qts; s->dev = get_device(s->qs->pcibus); s->reg_bar = qpci_iomap(s->dev, 0, &barsize); diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c index b554758..a9c1ace 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 = qtest_vboot(&qos_ops, cmdline_fmt, ap); va_end(ap); - qtest_irq_intercept_in(global_qtest, "ioapic"); + qtest_irq_intercept_in(qs->qts, "ioapic"); return qs; } diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 40018b9..9798e1d 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -20,7 +20,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) QOSState *qs = g_new0(QOSState, 1); cmdline = g_strdup_vprintf(cmdline_fmt, ap); - qs->qts = qtest_start(cmdline); + qs->qts = qtest_init(cmdline); qs->ops = ops; if (ops) { qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS); @@ -80,29 +80,21 @@ void set_context(QOSState *s) global_qtest = s->qts; } -static QDict *qmp_execute(const char *command) +static QDict *qmp_execute(QTestState *qts, const char *command) { - char *fmt; - QDict *rsp; - - fmt = g_strdup_printf("{ 'execute': '%s' }", command); - rsp = qmp(fmt); - g_free(fmt); - - return rsp; + return qtest_qmp(qts, "{ 'execute': %s }", command); } void migrate(QOSState *from, QOSState *to, const char *uri) { const char *st; - char *s; QDict *rsp, *sub; bool running; set_context(from); /* Is the machine currently running? */ - rsp = qmp_execute("query-status"); + rsp = qmp_execute(from->qts, "query-status"); g_assert(qdict_haskey(rsp, "return")); sub = qdict_get_qdict(rsp, "return"); g_assert(qdict_haskey(sub, "running")); @@ -110,30 +102,28 @@ void migrate(QOSState *from, QOSState *to, const char *uri) QDECREF(rsp); /* Issue the migrate command. */ - s = g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp = qmp(s); - g_free(s); + rsp = qtest_qmp(from->qts, + "{ 'execute': 'migrate', 'arguments': { 'uri': %s }}", + uri); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); /* Wait for STOP event, but only if we were running: */ if (running) { - qmp_eventwait("STOP"); + qtest_qmp_eventwait(from->qts, "STOP"); } /* If we were running, we can wait for an event. */ if (running) { migrate_allocator(from->alloc, to->alloc); set_context(to); - qmp_eventwait("RESUME"); + qtest_qmp_eventwait(to->qts, "RESUME"); return; } /* Otherwise, we need to wait: poll until migration is completed. */ while (1) { - rsp = qmp_execute("query-migrate"); + rsp = qmp_execute(from->qts, "query-migrate"); g_assert(qdict_haskey(rsp, "return")); sub = qdict_get_qdict(rsp, "return"); g_assert(qdict_haskey(sub, "status")); diff --git a/tests/megasas-test.c b/tests/megasas-test.c index ce960e7..81837e1 100644 --- a/tests/megasas-test.c +++ b/tests/megasas-test.c @@ -15,13 +15,16 @@ static QOSState *qmegasas_start(const char *extra_opts) { + QOSState *qs; const char *arch = qtest_get_arch(); const char *cmd = "-drive id=hd0,if=none,file=null-co://,format=raw " "-device megasas,id=scsi0,addr=04.0 " "-device scsi-hd,bus=scsi0.0,drive=hd0 %s"; if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - return qtest_pc_boot(cmd, extra_opts ? : ""); + qs = qtest_pc_boot(cmd, extra_opts ? : ""); + global_qtest = qs->qts; + return qs; } g_printerr("virtio-scsi tests are only available on x86 or ppc64\n"); diff --git a/tests/rtas-test.c b/tests/rtas-test.c index 34a6921..009bda6 100644 --- a/tests/rtas-test.c +++ b/tests/rtas-test.c @@ -14,6 +14,7 @@ static void test_rtas_get_time_of_day(void) time_t t1, t2; qs = qtest_spapr_boot("-machine pseries"); + global_qtest = qs->qts; t1 = time(NULL); ret = qrtas_get_time_of_day(qs->qts, qs->alloc, &tm, &ns); diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c index 62e0c78..6a7e5a2 100644 --- a/tests/usb-hcd-uhci-test.c +++ b/tests/usb-hcd-uhci-test.c @@ -77,6 +77,7 @@ int main(int argc, char **argv) "available on x86 or ppc64\n"); exit(EXIT_FAILURE); } + global_qtest = qs->qts; ret = g_test_run(); qtest_shutdown(qs); diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index 54edcb9..a2b3108 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -44,6 +44,7 @@ static QVirtIO9P *qvirtio_9p_start(const char *driver) g_printerr("virtio-9p tests are only available on x86 or ppc64\n"); exit(EXIT_FAILURE); } + global_qtest = v9p->qs->qts; return v9p; } diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 2ac64e5..9be9ffb 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -77,6 +77,7 @@ static QOSState *pci_test_start(void) g_printerr("virtio-blk tests are only available on x86 or ppc64\n"); exit(EXIT_FAILURE); } + global_qtest = qs->qts; unlink(tmp_path); g_free(tmp_path); return qs; diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index ea634dc..e15bc48 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -53,18 +53,21 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) static QOSState *pci_test_start(int socket) { + QOSState *qs; const char *arch = qtest_get_arch(); const char *cmd = "-netdev socket,fd=%d,id=hs0 -device " "virtio-net-pci,netdev=hs0"; if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - return qtest_pc_boot(cmd, socket); - } - if (strcmp(arch, "ppc64") == 0) { - return qtest_spapr_boot(cmd, socket); + qs = qtest_pc_boot(cmd, socket); + } else if (strcmp(arch, "ppc64") == 0) { + qs = qtest_spapr_boot(cmd, socket); + } else { + g_printerr("virtio-net tests are only available on x86 or ppc64\n"); + exit(EXIT_FAILURE); } - g_printerr("virtio-net tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); + global_qtest = qs->qts; + return qs; } static void driver_init(QVirtioDevice *dev) diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index bcf408f..7393d69 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -34,20 +34,22 @@ typedef struct { static QOSState *qvirtio_scsi_start(const char *extra_opts) { + QOSState *qs; const char *arch = qtest_get_arch(); const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw " "-device virtio-scsi-pci,id=vs0 " "-device scsi-hd,bus=vs0.0,drive=drv0 %s"; if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - return qtest_pc_boot(cmd, extra_opts ? : ""); - } - if (strcmp(arch, "ppc64") == 0) { - return qtest_spapr_boot(cmd, extra_opts ? : ""); + qs = qtest_pc_boot(cmd, extra_opts ? : ""); + } else if (strcmp(arch, "ppc64") == 0) { + qs = qtest_spapr_boot(cmd, extra_opts ? : ""); + } else { + g_printerr("virtio-scsi tests are only available on x86 or ppc64\n"); + exit(EXIT_FAILURE); } - - g_printerr("virtio-scsi tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); + global_qtest = qs->qts; + return qs; } static void qvirtio_scsi_stop(QOSState *qs)