Commit eb5937ba authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

tests/libqos: embed allocators instead of malloc-ing them separately



qgraph will embed these objects instead of allocating them in a separate
object.  Expose a new API "generic_alloc_init" and "generic_alloc_destroy"
for that, and rename the existing API with s/init/new/ and s/uninit/free/.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 143e6db6
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)
    s = g_new0(AHCIQState, 1);
    s->parent = qtest_pc_vboot(cli, ap);
    global_qtest = s->parent->qts;
    alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
    alloc_set_flags(&s->parent->alloc, ALLOC_LEAK_ASSERT);

    /* Verify that we have an AHCI device present. */
    s->dev = get_ahci_device(s->parent->qts, &s->fingerprint);
@@ -1039,7 +1039,7 @@ static void test_dma_fragmented(void)
    generate_pattern(tx, bufsize, AHCI_SECTOR_SIZE);

    /* Create a DMA buffer in guest memory, and write our pattern to it. */
    ptr = guest_alloc(ahci->parent->alloc, bufsize);
    ptr = guest_alloc(&ahci->parent->alloc, bufsize);
    g_assert(ptr);
    bufwrite(ptr, tx, bufsize);

@@ -1059,7 +1059,7 @@ static void test_dma_fragmented(void)

    /* Read back the guest's receive buffer into local memory */
    bufread(ptr, rx, bufsize);
    guest_free(ahci->parent->alloc, ptr);
    guest_free(&ahci->parent->alloc, ptr);

    g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);

+10 −12
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ typedef struct e1000e_device {
} e1000e_device;

static int test_sockets[2];
static QGuestAllocator *test_alloc;
static QGuestAllocator test_alloc;
static QPCIBus *test_bus;

static void e1000e_pci_foreach_callback(QPCIDevice *dev, int devfn, void *data)
@@ -165,7 +165,7 @@ static void e1000e_device_init(QPCIBus *bus, e1000e_device *d)
        val | E1000E_CTRL_EXT_DRV_LOAD | E1000E_CTRL_EXT_TXLSFLOW);

    /* Allocate and setup TX ring */
    d->tx_ring = guest_alloc(test_alloc, E1000E_RING_LEN);
    d->tx_ring = guest_alloc(&test_alloc, E1000E_RING_LEN);
    g_assert(d->tx_ring != 0);

    e1000e_macreg_write(d, E1000E_TDBAL, (uint32_t) d->tx_ring);
@@ -178,7 +178,7 @@ static void e1000e_device_init(QPCIBus *bus, e1000e_device *d)
    e1000e_macreg_write(d, E1000E_TCTL, E1000E_TCTL_EN);

    /* Allocate and setup RX ring */
    d->rx_ring = guest_alloc(test_alloc, E1000E_RING_LEN);
    d->rx_ring = guest_alloc(&test_alloc, E1000E_RING_LEN);
    g_assert(d->rx_ring != 0);

    e1000e_macreg_write(d, E1000E_RDBAL, (uint32_t)d->rx_ring);
@@ -268,7 +268,7 @@ static void e1000e_send_verify(e1000e_device *d)
    uint32_t recv_len;

    /* Prepare test data buffer */
    uint64_t data = guest_alloc(test_alloc, data_len);
    uint64_t data = guest_alloc(&test_alloc, data_len);
    memwrite(data, "TEST", 5);

    /* Prepare TX descriptor */
@@ -296,7 +296,7 @@ static void e1000e_send_verify(e1000e_device *d)
    g_assert_cmpstr(buffer, == , "TEST");

    /* Free test data buffer */
    guest_free(test_alloc, data);
    guest_free(&test_alloc, data);
}

static void e1000e_receive_verify(e1000e_device *d)
@@ -348,7 +348,7 @@ static void e1000e_receive_verify(e1000e_device *d)
    g_assert_cmpint(ret, == , sizeof(test) + sizeof(len));

    /* Prepare test data buffer */
    uint64_t data = guest_alloc(test_alloc, data_len);
    uint64_t data = guest_alloc(&test_alloc, data_len);

    /* Prepare RX descriptor */
    memset(&descr, 0, sizeof(descr));
@@ -369,7 +369,7 @@ static void e1000e_receive_verify(e1000e_device *d)
    g_assert_cmpstr(buffer, == , "TEST");

    /* Free test data buffer */
    guest_free(test_alloc, data);
    guest_free(&test_alloc, data);
}

static void e1000e_device_clear(QPCIBus *bus, e1000e_device *d)
@@ -392,10 +392,8 @@ static void data_test_init(e1000e_device *d)
    qtest_start(cmdline);
    g_free(cmdline);

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

    test_bus = qpci_new_pc(global_qtest, test_alloc);
    pc_alloc_init(&test_alloc, global_qtest, 0);
    test_bus = qpci_new_pc(global_qtest, &test_alloc);
    g_assert_nonnull(test_bus);

    e1000e_device_init(test_bus, d);
@@ -405,7 +403,7 @@ static void data_test_clear(e1000e_device *d)
{
    e1000e_device_clear(test_bus, d);
    close(test_sockets[0]);
    pc_alloc_uninit(test_alloc);
    alloc_destroy(&test_alloc);
    g_free(d->pci_dev);
    qpci_free_pc(test_bus);
    qtest_end();
+8 −9
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ enum {
#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)

static QPCIBus *pcibus = NULL;
static QGuestAllocator *guest_malloc;
static QGuestAllocator guest_malloc;

static char tmp_path[] = "/tmp/qtest.XXXXXX";
static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
@@ -135,7 +135,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
    va_end(ap);

    qtest_start(cmdline);
    guest_malloc = pc_alloc_init(global_qtest);
    pc_alloc_init(&guest_malloc, global_qtest, 0);

    g_free(cmdline);
}
@@ -146,8 +146,7 @@ static void ide_test_quit(void)
        qpci_free_pc(pcibus);
        pcibus = NULL;
    }
    pc_alloc_uninit(guest_malloc);
    guest_malloc = NULL;
    alloc_destroy(&guest_malloc);
    qtest_end();
}

@@ -246,7 +245,7 @@ static int send_dma_request(int cmd, uint64_t sector, int nb_sectors,

    /* Setup PRDT */
    len = sizeof(*prdt) * prdt_entries;
    guest_prdt = guest_alloc(guest_malloc, len);
    guest_prdt = guest_alloc(&guest_malloc, len);
    memwrite(guest_prdt, prdt, len);
    qpci_io_writel(dev, bmdma_bar, bmreg_prdt, guest_prdt);

@@ -311,7 +310,7 @@ static void test_bmdma_simple_rw(void)
    uint8_t *buf;
    uint8_t *cmpbuf;
    size_t len = 512;
    uintptr_t guest_buf = guest_alloc(guest_malloc, len);
    uintptr_t guest_buf = guest_alloc(&guest_malloc, len);

    PrdtEntry prdt[] = {
        {
@@ -381,7 +380,7 @@ static void test_bmdma_trim(void)
    const uint64_t bad_range = trim_range_le(TEST_IMAGE_SIZE / 512 - 1, 2);
    size_t len = 512;
    uint8_t *buf;
    uintptr_t guest_buf = guest_alloc(guest_malloc, len);
    uintptr_t guest_buf = guest_alloc(&guest_malloc, len);

    PrdtEntry prdt[] = {
        {
@@ -625,7 +624,7 @@ static void make_dirty(uint8_t device)

    dev = get_pci_device(&bmdma_bar, &ide_bar);

    guest_buf = guest_alloc(guest_malloc, len);
    guest_buf = guest_alloc(&guest_malloc, len);
    buf = g_malloc(len);
    memset(buf, rand() % 255 + 1, len);
    g_assert(guest_buf);
@@ -986,7 +985,7 @@ static void test_cdrom_dma(void)
                   "-device ide-cd,drive=sr0,bus=ide.0", tmp_path);
    qtest_irq_intercept_in(global_qtest, "ioapic");

    guest_buf = guest_alloc(guest_malloc, len);
    guest_buf = guest_alloc(&guest_malloc, len);
    prdt[0].addr = cpu_to_le32(guest_buf);
    prdt[0].size = cpu_to_le32(len | PRDT_EOT);

+1 −2
Original line number Diff line number Diff line
@@ -4,8 +4,7 @@
#include "libqos/pci-pc.h"

static QOSOps qos_ops = {
    .init_allocator = pc_alloc_init_flags,
    .uninit_allocator = pc_alloc_uninit,
    .alloc_init = pc_alloc_init,
    .qpci_new = qpci_new_pc,
    .qpci_free = qpci_free_pc,
    .shutdown = qtest_pc_shutdown,
+1 −2
Original line number Diff line number Diff line
@@ -4,8 +4,7 @@
#include "libqos/pci-spapr.h"

static QOSOps qos_ops = {
    .init_allocator = spapr_alloc_init_flags,
    .uninit_allocator = spapr_alloc_uninit,
    .alloc_init = spapr_alloc_init,
    .qpci_new = qpci_new_spapr,
    .qpci_free = qpci_free_spapr,
    .shutdown = qtest_spapr_shutdown,
Loading