Commit e5758de4 authored by Thomas Huth's avatar Thomas Huth
Browse files

tests/libqtest: Make qtest_qmp_device_add/del independent from global_qtest



Generic library functions like qtest_qmp_device_add() and _del()
should not depend on the global_qtest variable. Pass the test
state via parameter instead.

Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20190813093047.27948-6-thuth@redhat.com>
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
parent 17de4741
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -77,18 +77,19 @@ static void test_plug_with_device_add_x86(gconstpointer data)
    const PlugTestData *td = data;
    char *args;
    unsigned int s, c, t;
    QTestState *qts;

    args = g_strdup_printf("-machine %s -cpu %s "
                           "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
                           td->machine, td->cpu_model,
                           td->sockets, td->cores, td->threads, td->maxcpus);
    qtest_start(args);
    qts = qtest_init(args);

    for (s = 1; s < td->sockets; s++) {
        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,
                qtest_qmp_device_add(qts, td->device_model, id,
                                     "{'socket-id':%u, 'core-id':%u,"
                                     " 'thread-id':%u}",
                                     s, c, t);
@@ -97,7 +98,7 @@ static void test_plug_with_device_add_x86(gconstpointer data)
        }
    }

    qtest_end();
    qtest_quit(qts);
    g_free(args);
}

@@ -106,20 +107,22 @@ static void test_plug_with_device_add_coreid(gconstpointer data)
    const PlugTestData *td = data;
    char *args;
    unsigned int c;
    QTestState *qts;

    args = g_strdup_printf("-machine %s -cpu %s "
                           "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
                           td->machine, td->cpu_model,
                           td->sockets, td->cores, td->threads, td->maxcpus);
    qtest_start(args);
    qts = qtest_init(args);

    for (c = 1; c < td->cores; 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(qts, td->device_model, id,
                             "{'core-id':%u}", c);
        g_free(id);
    }

    qtest_end();
    qtest_quit(qts);
    g_free(args);
}

+1 −1
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ static void test_e1000e_hotplug(void *obj, void *data, QGuestAllocator * alloc)
{
    QTestState *qts = global_qtest;  /* TODO: get rid of global_qtest here */

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

+1 −1
Original line number Diff line number Diff line
@@ -389,7 +389,7 @@ static void test_ivshmem_hotplug(void)
    qts = qtest_init("-object memory-backend-ram,size=1M,id=mb1");

    global_qtest = qts;  /* TODO: Get rid of global_qtest here */
    qtest_qmp_device_add("ivshmem-plain", "iv1",
    qtest_qmp_device_add(qts, "ivshmem-plain", "iv1",
                         "{'addr': %s, 'memdev': 'mb1'}",
                         stringify(PCI_SLOT_HP));
    if (strcmp(arch, "ppc64") != 0) {
+3 −3
Original line number Diff line number Diff line
@@ -37,20 +37,20 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t expect)
    g_assert((value & mask) == (expect & mask));
}

void usb_test_hotplug(const char *hcd_id, const char *port,
void usb_test_hotplug(QTestState *qts, const char *hcd_id, const char *port,
                      void (*port_check)(void))
{
    char *id = g_strdup_printf("usbdev%s", port);
    char *bus = g_strdup_printf("%s.0", hcd_id);

    qtest_qmp_device_add("usb-tablet", id, "{'port': %s, 'bus': %s}",
    qtest_qmp_device_add(qts, "usb-tablet", id, "{'port': %s, 'bus': %s}",
                         port, bus);

    if (port_check) {
        port_check();
    }

    qtest_qmp_device_del(id);
    qtest_qmp_device_del(qts, id);

    g_free(bus);
    g_free(id);
+1 −1
Original line number Diff line number Diff line
@@ -13,6 +13,6 @@ void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc,
void uhci_port_test(struct qhc *hc, int port, uint16_t expect);
void uhci_deinit(struct qhc *hc);

void usb_test_hotplug(const char *bus_name, const char *port,
void usb_test_hotplug(QTestState *qts, const char *bus_name, const char *port,
                      void (*port_check)(void));
#endif
Loading