Commit 82cab70b authored by Markus Armbruster's avatar Markus Armbruster
Browse files

tests: Clean up string interpolation around qtest_qmp_device_add()



Leaving interpolation into JSON to qmp() is more robust than building
QMP input manually, as explained in the commit before previous.

qtest_qmp_device_add() and its wrappers interpolate into JSON as
follows:

* qtest_qmp_device_add() interpolates members into a JSON object.

* So do its wrappers qpci_plug_device_test() and usb_test_hotplug().

* usb_test_hotplug() additionally interpolates strings and numbers
  into JSON strings.

Clean them up:

* Have qtest_qmp_device_add() take its extra device properties as
  arguments for qdict_from_jsonf_nofail() instead of a string
  containing JSON members.

* Drop qpci_plug_device_test(), use qtest_qmp_device_add()
  directly.

* Change usb_test_hotplug() parameter @port to string, to avoid
  interpolation.  Interpolate @hcd_id separately.

Bonus: gets rid of a non-literal format string.  A step towards
compile-time format string checking without triggering
-Wformat-nonliteral.

Cc: Thomas Huth <thuth@redhat.com>
Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Message-Id: <20180806065344.7103-15-armbru@redhat.com>
parent 530e79a8
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -88,8 +88,9 @@ static void test_plug_with_device_add_x86(gconstpointer data)
        for (c = 0; c < td->cores; c++) {
            for (t = 0; t < td->threads; t++) {
                char *id = g_strdup_printf("id-%i-%i-%i", s, c, t);
                qtest_qmp_device_add(td->device_model, id, "'socket-id':%u, "
                                     "'core-id':%u, 'thread-id':%u",
                qtest_qmp_device_add(td->device_model, id,
                                     "{'socket-id':%u, 'core-id':%u,"
                                     " 'thread-id':%u}",
                                     s, c, t);
                g_free(id);
            }
@@ -114,7 +115,7 @@ static void test_plug_with_device_add_coreid(gconstpointer data)

    for (c = td->cores; c < td->maxcpus / td->sockets / td->threads; c++) {
        char *id = g_strdup_printf("id-%i", c);
        qtest_qmp_device_add(td->device_model, id, "'core-id':%u", c);
        qtest_qmp_device_add(td->device_model, id, "{'core-id':%u}", c);
        g_free(id);
    }

+2 −4
Original line number Diff line number Diff line
@@ -456,12 +456,10 @@ static void test_e1000e_multiple_transfers(gconstpointer data)

static void test_e1000e_hotplug(gconstpointer data)
{
    static const uint8_t slot = 0x06;

    qtest_start("-device e1000e");

    qpci_plug_device_test("e1000e", "e1000e_net", slot, NULL);
    qpci_unplug_acpi_device_test("e1000e_net", slot);
    qtest_qmp_device_add("e1000e", "e1000e_net", "{'addr': '0x06'}");
    qpci_unplug_acpi_device_test("e1000e_net", 0x06);

    qtest_end();
}
+3 −5
Original line number Diff line number Diff line
@@ -420,19 +420,17 @@ static void test_ivshmem_server_irq(void)
static void test_ivshmem_hotplug(void)
{
    const char *arch = qtest_get_arch();
    gchar *opts;

    qtest_start("");

    opts = g_strdup_printf("'shm': '%s', 'size': '1M'", tmpshm);

    qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, opts);
    qtest_qmp_device_add("ivshmem",
                         "iv1", "{'addr': %s, 'shm': %s, 'size': '1M'}",
                         stringify(PCI_SLOT_HP), tmpshm);
    if (strcmp(arch, "ppc64") != 0) {
        qpci_unplug_acpi_device_test("iv1", PCI_SLOT_HP);
    }

    qtest_end();
    g_free(opts);
}

static void test_ivshmem_memdev(void)
+0 −7
Original line number Diff line number Diff line
@@ -395,10 +395,3 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr)
    QPCIBar bar = { .addr = addr };
    return bar;
}

void qpci_plug_device_test(const char *driver, const char *id,
                           uint8_t slot, const char *opts)
{
    qtest_qmp_device_add(driver, id, "'addr': '%d'%s%s", slot,
                         opts ? ", " : "", opts ? opts : "");
}
+0 −2
Original line number Diff line number Diff line
@@ -109,7 +109,5 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);
void qpci_iounmap(QPCIDevice *dev, QPCIBar addr);
QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);

void qpci_plug_device_test(const char *driver, const char *id,
                           uint8_t slot, const char *opts);
void qpci_unplug_acpi_device_test(const char *id, uint8_t slot);
#endif
Loading