Commit 78b27bad authored by Eric Blake's avatar Eric Blake Committed by Cornelia Huck
Browse files

libqtest: Add qtest_[v]startf()



We have several callers that were formatting the argument strings
themselves; consolidate this effort by adding new convenience
functions directly in libqtest, and update some call-sites that
can benefit from it.

Note that the new functions qtest_startf() and qtest_vstartf()
behave more like qtest_init() (the caller must assign global_qtest
after the fact, rather than getting it implicitly set).  This helps
us prepare for future patches that get rid of the global variable,
by explicitly highlighting which tests still depend on it now.

Signed-off-by: default avatarEric Blake <eblake@redhat.com>
[thuth: Dropped the hunks that do not apply cleanly to qemu master
 yet and added the missing g_free(args) in qtest_vstartf()]
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
Message-Id: <1508336428-20511-2-git-send-email-thuth@redhat.com>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarCornelia Huck <cohuck@redhat.com>
parent 6bb6f194
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -28,14 +28,12 @@ static void test_a_boot_order(const char *machine,
                              uint64_t expected_boot,
                              uint64_t expected_reboot)
{
    char *args;
    uint64_t actual;

    args = g_strdup_printf("-nodefaults%s%s %s",
    global_qtest = qtest_startf("-nodefaults%s%s %s",
                                machine ? " -M " : "",
                                machine ?: "",
                                test_args);
    qtest_start(args);
    actual = read_boot_order();
    g_assert_cmphex(actual, ==, expected_boot);
    qmp_discard_response("{ 'execute': 'system_reset' }");
@@ -47,7 +45,6 @@ static void test_a_boot_order(const char *machine,
    actual = read_boot_order();
    g_assert_cmphex(actual, ==, expected_reboot);
    qtest_quit(global_qtest);
    g_free(args);
}

static void test_boot_orders(const char *machine,
+4 −8
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ done:
static void test_machine(const void *data)
{
    const testdef_t *test = data;
    char *args;
    char tmpname[] = "/tmp/qtest-boot-serial-XXXXXX";
    int fd;

@@ -82,18 +81,15 @@ static void test_machine(const void *data)
     * Make sure that this test uses tcg if available: It is used as a
     * fast-enough smoketest for that.
     */
    args = g_strdup_printf("-M %s,accel=tcg:kvm "
    global_qtest = qtest_startf("-M %s,accel=tcg:kvm "
                                "-chardev file,id=serial0,path=%s "
                                "-no-shutdown -serial chardev:serial0 %s",
                                test->machine, tmpname, test->extra);

    qtest_start(args);
    unlink(tmpname);

    check_guest_output(test, fd);
    qtest_quit(global_qtest);

    g_free(args);
    close(fd);
}

+12 −21
Original line number Diff line number Diff line
@@ -114,13 +114,11 @@ static void isa_outl(const TestCase *test, uint16_t addr, uint32_t value)
static void test_endianness(gconstpointer data)
{
    const TestCase *test = data;
    char *args;

    args = g_strdup_printf("-M %s%s%s -device pc-testdev",
    global_qtest = qtest_startf("-M %s%s%s -device pc-testdev",
                                test->machine,
                                test->superio ? " -device " : "",
                                test->superio ?: "");
    qtest_start(args);
    isa_outl(test, 0xe0, 0x87654321);
    g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
    g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
@@ -183,19 +181,16 @@ static void test_endianness(gconstpointer data)
    g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x43);
    g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x21);
    qtest_quit(global_qtest);
    g_free(args);
}

static void test_endianness_split(gconstpointer data)
{
    const TestCase *test = data;
    char *args;

    args = g_strdup_printf("-M %s%s%s -device pc-testdev",
    global_qtest = qtest_startf("-M %s%s%s -device pc-testdev",
                                test->machine,
                                test->superio ? " -device " : "",
                                test->superio ?: "");
    qtest_start(args);
    isa_outl(test, 0xe8, 0x87654321);
    g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
    g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
@@ -230,19 +225,16 @@ static void test_endianness_split(gconstpointer data)
    g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
    g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);
    qtest_quit(global_qtest);
    g_free(args);
}

static void test_endianness_combine(gconstpointer data)
{
    const TestCase *test = data;
    char *args;

    args = g_strdup_printf("-M %s%s%s -device pc-testdev",
    global_qtest = qtest_startf("-M %s%s%s -device pc-testdev",
                                test->machine,
                                test->superio ? " -device " : "",
                                test->superio ?: "");
    qtest_start(args);
    isa_outl(test, 0xe0, 0x87654321);
    g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87654321);
    g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
@@ -277,7 +269,6 @@ static void test_endianness_combine(gconstpointer data)
    g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
    g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4321);
    qtest_quit(global_qtest);
    g_free(args);
}

int main(int argc, char **argv)
+4 −7
Original line number Diff line number Diff line
@@ -401,7 +401,6 @@ static void open_socket(void)
int main(int argc, char **argv)
{
    const char *arch = qtest_get_arch();
    char *cmdline;
    int ret;

    /* Check architecture */
@@ -415,12 +414,10 @@ int main(int argc, char **argv)
    /* Run the tests */
    g_test_init(&argc, &argv, NULL);

    cmdline = g_strdup_printf(
    global_qtest = qtest_startf(
        " -chardev socket,id=ipmi0,host=localhost,port=%d,reconnect=10"
        " -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0"
        " -device isa-ipmi-bt,bmc=bmc0", emu_port);
    qtest_start(cmdline);
    g_free(cmdline);
    qtest_irq_intercept_in(global_qtest, "ioapic");
    qtest_add_func("/ipmi/extern/connect", test_connect);
    qtest_add_func("/ipmi/extern/bt_base", test_bt_base);
+22 −0
Original line number Diff line number Diff line
@@ -244,6 +244,28 @@ QTestState *qtest_init(const char *extra_args)
    return s;
}

QTestState *qtest_vstartf(const char *fmt, va_list ap)
{
    char *args = g_strdup_vprintf(fmt, ap);
    QTestState *s;

    s = qtest_start(args);
    g_free(args);
    global_qtest = NULL;
    return s;
}

QTestState *qtest_startf(const char *fmt, ...)
{
    va_list ap;
    QTestState *s;

    va_start(ap, fmt);
    s = qtest_vstartf(fmt, ap);
    va_end(ap);
    return s;
}

void qtest_quit(QTestState *s)
{
    g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s));
Loading