qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, armbru@redhat.com, pbonzini@redhat.com,
	thuth@redhat.com, John Snow <jsnow@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	Alexander Graf <agraf@suse.de>, Gerd Hoffmann <kraxel@redhat.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	"open list:IDE" <qemu-block@nongnu.org>,
	"open list:sPAPR" <qemu-ppc@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v7 17/38] libqos: Use explicit QTestState for remaining libqos operations
Date: Mon, 11 Sep 2017 23:30:08 +0200	[thread overview]
Message-ID: <20170911233008.0c807473@bahia.lan> (raw)
In-Reply-To: <20170911172022.4738-18-eblake@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 10806 bytes --]

On Mon, 11 Sep 2017 12:20:01 -0500
Eric Blake <eblake@redhat.com> wrote:

> 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 <eblake@redhat.com>
> 
> ---
> v7: split libqos changes from test-ahci, catch more spots
> ---

For tests/virtio-9p-test.c.

Acked-by: Greg Kurz <groug@kaod.org>

>  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 +
>  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 c94d1bd712..d6696cc370 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_malloc0(sizeof(AHCIQState));
>      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 d35c922254..d8f8530a4d 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 b554758802..a9c1aceaa7 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 40018b9c07..9798e1d027 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 ce960e7f81..81837e14af 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 34a692163f..009bda6d23 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 0fb7f8d223..290416d845 100644
> --- a/tests/usb-hcd-uhci-test.c
> +++ b/tests/usb-hcd-uhci-test.c
> @@ -95,6 +95,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 ad33d96387..07cbb7f37c 100644
> --- a/tests/virtio-9p-test.c
> +++ b/tests/virtio-9p-test.c
> @@ -46,6 +46,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 99bb6f26cd..0cf33b6810 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 8b43d3dd65..acecef0a3e 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);
> +        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);
>      }
> -    if (strcmp(arch, "ppc64") == 0) {
> -        return qtest_spapr_boot(cmd, socket);
> -    }
> -    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 87a3b6e81a..4d544ddbc3 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 ? : "");
> +        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);
>      }
> -    if (strcmp(arch, "ppc64") == 0) {
> -        return qtest_spapr_boot(cmd, extra_opts ? : "");
> -    }
> -
> -    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)


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2017-09-11 21:30 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11 17:19 [Qemu-devel] [PATCH v7 00/38] Preliminary libqtest cleanups Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 01/38] test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 02/38] qtest: Don't perform side effects inside assertion Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 03/38] numa-test: Use hmp() Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 04/38] tests: Clean up wait for event Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 05/38] libqtest: Remove dead qtest_instances variable Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 06/38] libqtest: Use qemu_strtoul() Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 07/38] libqtest: Inline qtest_query_target_endianness() Eric Blake
2017-09-12  6:32   ` Thomas Huth
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 08/38] libqos: Track QTestState with QPCIBus Eric Blake
2017-09-11 23:46   ` John Snow
2017-09-12  7:05   ` Thomas Huth
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 09/38] libqos: Track QTestState with QVirtioBus Eric Blake
2017-09-12  7:21   ` Thomas Huth
2017-09-12 13:28     ` Eric Blake
2017-09-13  7:10       ` Thomas Huth
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 10/38] libqos: Move/rename qpci_unplug_acpi_device_test() to pci.c Eric Blake
2017-09-12  7:29   ` Thomas Huth
2017-09-12 13:28     ` Eric Blake
2017-09-13  7:15       ` Thomas Huth
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 11/38] libqos: Use explicit QTestState for pci operations Eric Blake
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 12/38] libqos: Use explicit QTestState for virtio operations Eric Blake
2017-09-12  7:38   ` Thomas Huth
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 13/38] libqos: Use explicit QTestState for fw_cfg operations Eric Blake
2017-09-11 23:49   ` John Snow
2017-09-12  8:55   ` Thomas Huth
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 14/38] libqos: Use explicit QTestState for rtas operations Eric Blake
2017-09-12  9:01   ` Thomas Huth
2017-09-11 17:19 ` [Qemu-devel] [PATCH v7 15/38] libqos: Use explicit QTestState for i2c operations Eric Blake
2017-09-12  9:04   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 16/38] libqos: Use explicit QTestState for ahci operations Eric Blake
2017-09-11 23:54   ` John Snow
2017-09-12  9:09   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 17/38] libqos: Use explicit QTestState for remaining libqos operations Eric Blake
2017-09-11 21:30   ` Greg Kurz [this message]
2017-09-12  0:01   ` John Snow
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 18/38] ahci-test: Drop dependence on global_qtest Eric Blake
2017-09-12  0:20   ` John Snow
2017-09-12  0:21     ` John Snow
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 19/38] ivshmem-test: " Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 20/38] postcopy-test: " Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 21/38] vhost-user-test: " Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 22/38] qmp-test: " Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 23/38] tests/boot-sector: " Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 24/38] tests/acpi-utils: " Eric Blake
2017-09-12  9:26   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 25/38] wdt_ib700-test: " Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 26/38] libqtest: Merge qtest_end() into qtest_quit() Eric Blake
2017-09-12  0:31   ` John Snow
2017-09-12  9:30   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 27/38] libqtest: Swap order of qtest_init() and qtest_start() Eric Blake
2017-09-12  9:57   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 28/38] libqtest: Add qtest_[v]startf() Eric Blake
2017-09-12 10:14   ` Thomas Huth
2017-09-12 13:32     ` Eric Blake
2017-09-13  7:19       ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 29/38] libqtest: Merge qtest_init() into qtest_start() Eric Blake
2017-09-12 10:37   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 30/38] qtest: Avoid passing raw strings through hmp() Eric Blake
2017-09-11 17:42   ` Dr. David Alan Gilbert
2017-09-12 10:40   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 31/38] libqtest: Merge qtest_clock_*() with clock_*() Eric Blake
2017-09-12 10:45   ` Thomas Huth
2017-09-12 13:35     ` Eric Blake
2017-09-14  4:35       ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 32/38] libqtest: Merge qtest_irq*() with irq*() Eric Blake
2017-09-12 10:47   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 33/38] libqtest: Merge qtest_{in, out}[bwl]() with {in, out}[bwl]() Eric Blake
2017-09-12 10:49   ` Thomas Huth
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 34/38] libqtest: Merge qtest_{read, write}[bwlq]() with {read, write}[bwlq]() Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 35/38] libqtest: Merge qtest_{mem, buf}{read, write}() with {mem, buf}{read, write}() Eric Blake
2017-09-11 21:35   ` Greg Kurz
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 36/38] libqtest: Merge qtest_memset() with qmemset() Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 37/38] libqtest: Separate qmp_discard_response() from command Eric Blake
2017-09-11 17:20 ` [Qemu-devel] [PATCH v7 38/38] libqtest: Merge qtest_hmp() with hmp() Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170911233008.0c807473@bahia.lan \
    --to=groug@kaod.org \
    --cc=agraf@suse.de \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=eblake@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).