From 46e0cf762985e0a85529efd454402998c5021212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Mar=C3=AD?= Date: Mon, 1 Sep 2014 12:07:55 +0200 Subject: tests: Add virtio device initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add functions to read and write virtio header fields. Add status bit setting in virtio-blk-device. Signed-off-by: Marc MarĂ­ Signed-off-by: Stefan Hajnoczi --- tests/virtio-blk-test.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'tests/virtio-blk-test.c') diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 4d87a3e538..649f7cf94f 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -49,18 +49,41 @@ static void test_end(void) qtest_end(); } -static void pci_basic(void) +static QVirtioPCIDevice *virtio_blk_init(QPCIBus *bus) { QVirtioPCIDevice *dev; - QPCIBus *bus; - - bus = test_start(); dev = qvirtio_pci_device_find(bus, QVIRTIO_BLK_DEVICE_ID); g_assert(dev != NULL); g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_BLK_DEVICE_ID); g_assert_cmphex(dev->pdev->devfn, ==, ((PCI_SLOT << 3) | PCI_FN)); + qvirtio_pci_device_enable(dev); + qvirtio_reset(&qvirtio_pci, &dev->vdev); + qvirtio_set_acknowledge(&qvirtio_pci, &dev->vdev); + qvirtio_set_driver(&qvirtio_pci, &dev->vdev); + + return dev; +} + +static void pci_basic(void) +{ + QVirtioPCIDevice *dev; + QPCIBus *bus; + void *addr; + uint64_t capacity; + + bus = test_start(); + + dev = virtio_blk_init(bus); + + /* MSI-X is not enabled */ + addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_NO_MSIX; + + capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr); + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); + + qvirtio_pci_device_disable(dev); g_free(dev); test_end(); } -- cgit v1.2.3