Commit 05e520f1 authored by Eric Blake's avatar Eric Blake Committed by Thomas Huth
Browse files

libqos: Use explicit QTestState for fw_cfg operations



Drop one more client of global_qtest by teaching all fw_cfg test
functionality (invoked through alloc-pc) to pass in an explicit
QTestState, adjusting all callers.  In particular, fw_cfg-test
had to reorder things to create the test state prior to creating
the fw_cfg (and drop a pointless strdup in the meantime), but that
test now no longer depends on global_qtest.

Signed-off-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarJohn Snow <jsnow@redhat.com>
Reviewed-by: default avatarThomas Huth <thuth@redhat.com>
[thuth: Fixed conflict wrt pc_alloc_init() in vhost-user-test.c]
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
parent e5d1730d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ static void test_prep_boot_order(void)

static uint64_t read_boot_order_pmac(void)
{
    QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510);
    QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xf0000510);

    return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
}
@@ -157,7 +157,7 @@ static void test_pmac_newworld_boot_order(void)

static uint64_t read_boot_order_sun4m(void)
{
    QFWCFG *fw_cfg = mm_fw_cfg_init(0xd00000510ULL);
    QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xd00000510ULL);

    return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
}
@@ -169,7 +169,7 @@ static void test_sun4m_boot_order(void)

static uint64_t read_boot_order_sun4u(void)
{
    QFWCFG *fw_cfg = io_fw_cfg_init(0x510);
    QFWCFG *fw_cfg = io_fw_cfg_init(global_qtest, 0x510);

    return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
}
+1 −1
Original line number Diff line number Diff line
@@ -392,7 +392,7 @@ static void data_test_init(e1000e_device *d)
    qtest_start(cmdline);
    g_free(cmdline);

    test_alloc = pc_alloc_init();
    test_alloc = pc_alloc_init(global_qtest);
    g_assert_nonnull(test_alloc);

    test_bus = qpci_init_pc(global_qtest, test_alloc);
+4 −9
Original line number Diff line number Diff line
@@ -102,12 +102,13 @@ static void test_fw_cfg_boot_menu(void)
int main(int argc, char **argv)
{
    QTestState *s;
    char *cmdline;
    int ret;

    g_test_init(&argc, &argv, NULL);

    fw_cfg = pc_fw_cfg_init();
    s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");

    fw_cfg = pc_fw_cfg_init(s);

    qtest_add_func("fw_cfg/signature", test_fw_cfg_signature);
    qtest_add_func("fw_cfg/id", test_fw_cfg_id);
@@ -125,15 +126,9 @@ int main(int argc, char **argv)
    qtest_add_func("fw_cfg/numa", test_fw_cfg_numa);
    qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu);

    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
    s = qtest_start(cmdline);
    g_free(cmdline);

    ret = g_test_run();

    if (s) {
    qtest_quit(s);
    }

    return ret;
}
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
    va_end(ap);

    qtest_start(cmdline);
    guest_malloc = pc_alloc_init();
    guest_malloc = pc_alloc_init(global_qtest);

    g_free(cmdline);
}
+8 −6
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key)

static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
{
    writew(fw_cfg->base, key);
    qtest_writew(fw_cfg->qts, fw_cfg->base, key);
}

static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
@@ -65,15 +65,16 @@ static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
    int i;

    for (i = 0; i < len; i++) {
        ptr[i] = readb(fw_cfg->base + 2);
        ptr[i] = qtest_readb(fw_cfg->qts, fw_cfg->base + 2);
    }
}

QFWCFG *mm_fw_cfg_init(uint64_t base)
QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base)
{
    QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));

    fw_cfg->base = base;
    fw_cfg->qts = qts;
    fw_cfg->select = mm_fw_cfg_select;
    fw_cfg->read = mm_fw_cfg_read;

@@ -82,7 +83,7 @@ QFWCFG *mm_fw_cfg_init(uint64_t base)

static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
{
    outw(fw_cfg->base, key);
    qtest_outw(fw_cfg->qts, fw_cfg->base, key);
}

static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
@@ -91,15 +92,16 @@ static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
    int i;

    for (i = 0; i < len; i++) {
        ptr[i] = inb(fw_cfg->base + 1);
        ptr[i] = qtest_inb(fw_cfg->qts, fw_cfg->base + 1);
    }
}

QFWCFG *io_fw_cfg_init(uint16_t base)
QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base)
{
    QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));

    fw_cfg->base = base;
    fw_cfg->qts = qts;
    fw_cfg->select = io_fw_cfg_select;
    fw_cfg->read = io_fw_cfg_read;

Loading