Skip to content

Commit

Permalink
tests: rename target_big_endian() as qvirtio_is_big_endian()
Browse files Browse the repository at this point in the history
Move the definition to libqos/virtio.h as it must be used
only with virtio functions.

Add a QVirtioDevice parameter as it will be needed to
know if the virtio device is using virtio 1.0 specification
and thus is always little-endian (to do)

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
vivier authored and dgibson committed Oct 27, 2016
1 parent 6b9cdf4 commit 8b4b80c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tests/libqos/virtio-pci.c
Expand Up @@ -86,7 +86,7 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)
int i;
uint64_t u64 = 0;

if (target_big_endian()) {
if (qvirtio_is_big_endian(d)) {
for (i = 0; i < 8; ++i) {
u64 |= (uint64_t)qpci_io_readb(dev->pdev,
(void *)(uintptr_t)addr + i) << (7 - i) * 8;
Expand Down
6 changes: 6 additions & 0 deletions tests/libqos/virtio.h
Expand Up @@ -89,6 +89,12 @@ struct QVirtioBus {
void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq);
};

static inline bool qvirtio_is_big_endian(QVirtioDevice *d)
{
/* FIXME: virtio 1.0 is always little-endian */
return qtest_big_endian(global_qtest);
}

static inline uint32_t qvring_size(uint32_t num, uint32_t align)
{
return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num)
Expand Down
10 changes: 0 additions & 10 deletions tests/libqtest.h
Expand Up @@ -881,16 +881,6 @@ static inline int64_t clock_set(int64_t val)
return qtest_clock_set(global_qtest, val);
}

/**
* target_big_endian:
*
* Returns: True if the architecture under test has a big endian configuration.
*/
static inline bool target_big_endian(void)
{
return qtest_big_endian(global_qtest);
}

QDict *qmp_fd_receive(int fd);
void qmp_fd_sendv(int fd, const char *fmt, va_list ap);
void qmp_fd_send(int fd, const char *fmt, ...);
Expand Down
36 changes: 18 additions & 18 deletions tests/virtio-blk-test.c
Expand Up @@ -117,31 +117,31 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot)
return dev;
}

static inline void virtio_blk_fix_request(QVirtioBlkReq *req)
static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req)
{
#ifdef HOST_WORDS_BIGENDIAN
bool host_endian = true;
const bool host_is_big_endian = true;
#else
bool host_endian = false;
const bool host_is_big_endian = false;
#endif

if (target_big_endian() != host_endian) {
if (qvirtio_is_big_endian(d) != host_is_big_endian) {
req->type = bswap32(req->type);
req->ioprio = bswap32(req->ioprio);
req->sector = bswap64(req->sector);
}
}

static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,
uint64_t data_size)
static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,
QVirtioBlkReq *req, uint64_t data_size)
{
uint64_t addr;
uint8_t status = 0xFF;

g_assert_cmpuint(data_size % 512, ==, 0);
addr = guest_alloc(alloc, sizeof(*req) + data_size);

virtio_blk_fix_request(req);
virtio_blk_fix_request(d, req);

memwrite(addr, req, 16);
memwrite(addr + 16, req->data, data_size);
Expand Down Expand Up @@ -182,7 +182,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
req.data = g_malloc0(512);
strcpy(req.data, "TEST");

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, dev, &req, 512);

g_free(req.data);

Expand All @@ -204,7 +204,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
req.sector = 0;
req.data = g_malloc0(512);

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, dev, &req, 512);

g_free(req.data);

Expand Down Expand Up @@ -234,7 +234,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
req.data = g_malloc0(512);
strcpy(req.data, "TEST");

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, dev, &req, 512);

g_free(req.data);

Expand All @@ -254,7 +254,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
req.sector = 1;
req.data = g_malloc0(512);

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, dev, &req, 512);

g_free(req.data);

Expand Down Expand Up @@ -348,7 +348,7 @@ static void pci_indirect(void)
req.data = g_malloc0(512);
strcpy(req.data, "TEST");

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);

g_free(req.data);

Expand All @@ -373,7 +373,7 @@ static void pci_indirect(void)
req.data = g_malloc0(512);
strcpy(req.data, "TEST");

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);

g_free(req.data);

Expand Down Expand Up @@ -495,7 +495,7 @@ static void pci_msix(void)
req.data = g_malloc0(512);
strcpy(req.data, "TEST");

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);

g_free(req.data);

Expand All @@ -518,7 +518,7 @@ static void pci_msix(void)
req.sector = 0;
req.data = g_malloc0(512);

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);

g_free(req.data);

Expand Down Expand Up @@ -600,7 +600,7 @@ static void pci_idx(void)
req.data = g_malloc0(512);
strcpy(req.data, "TEST");

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);

g_free(req.data);

Expand All @@ -618,7 +618,7 @@ static void pci_idx(void)
req.data = g_malloc0(512);
strcpy(req.data, "TEST");

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);

g_free(req.data);

Expand All @@ -643,7 +643,7 @@ static void pci_idx(void)
req.sector = 1;
req.data = g_malloc0(512);

req_addr = virtio_blk_request(alloc, &req, 512);
req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);

g_free(req.data);

Expand Down

0 comments on commit 8b4b80c

Please sign in to comment.