aboutsummaryrefslogtreecommitdiff
path: root/tests/nvme-test.c
diff options
context:
space:
mode:
authorEmanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>2018-08-17 13:16:07 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2019-03-07 17:28:46 +0100
commit3157ed330ed4df2a598fe533dced1ea566810bcb (patch)
tree04895cb698e4dcbe46f2be837493d280eb1969ee /tests/nvme-test.c
parent941e33170916bc5bea8373807f2bfe5dc396d339 (diff)
qos-test: nvme test node
Convert tests/nvme-test to a driver node; the code to discover the PCI device is replaced by generic qgraph code, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/nvme-test.c')
-rw-r--r--tests/nvme-test.c78
1 files changed, 42 insertions, 36 deletions
diff --git a/tests/nvme-test.c b/tests/nvme-test.c
index 2700ba838a..b48d3a24b9 100644
--- a/tests/nvme-test.c
+++ b/tests/nvme-test.c
@@ -10,49 +10,47 @@
#include "qemu/osdep.h"
#include "qemu/units.h"
#include "libqtest.h"
-#include "libqos/libqos-pc.h"
+#include "libqos/qgraph.h"
+#include "libqos/pci.h"
-static QOSState *qnvme_start(const char *extra_opts)
+typedef struct QNvme QNvme;
+
+struct QNvme {
+ QOSGraphObject obj;
+ QPCIDevice dev;
+};
+
+static void *nvme_get_driver(void *obj, const char *interface)
{
- QOSState *qs;
- const char *arch = qtest_get_arch();
- const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw "
- "-device nvme,addr=0x4.0,serial=foo,drive=drv0 %s";
-
- if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
- qs = qtest_pc_boot(cmd, extra_opts ? : "");
- global_qtest = qs->qts;
- return qs;
+ QNvme *nvme = obj;
+
+ if (!g_strcmp0(interface, "pci-device")) {
+ return &nvme->dev;
}
- g_printerr("nvme tests are only available on x86\n");
- exit(EXIT_FAILURE);
+ fprintf(stderr, "%s not present in nvme\n", interface);
+ g_assert_not_reached();
}
-static void qnvme_stop(QOSState *qs)
+static void *nvme_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
{
- qtest_shutdown(qs);
-}
+ QNvme *nvme = g_new0(QNvme, 1);
+ QPCIBus *bus = pci_bus;
-static void nop(void)
-{
- QOSState *qs;
+ qpci_device_init(&nvme->dev, bus, addr);
+ nvme->obj.get_driver = nvme_get_driver;
- qs = qnvme_start(NULL);
- qnvme_stop(qs);
+ return &nvme->obj;
}
-static void nvmetest_cmb_test(void)
+/* This used to cause a NULL pointer dereference. */
+static void nvmetest_oob_cmb_test(void *obj, void *data, QGuestAllocator *alloc)
{
const int cmb_bar_size = 2 * MiB;
- QOSState *qs;
- QPCIDevice *pdev;
+ QNvme *nvme = obj;
+ QPCIDevice *pdev = &nvme->dev;
QPCIBar bar;
- qs = qnvme_start("-global nvme.cmb_size_mb=2");
- pdev = qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0));
- g_assert(pdev != NULL);
-
qpci_device_enable(pdev);
bar = qpci_iomap(pdev, 2, NULL);
@@ -65,16 +63,24 @@ static void nvmetest_cmb_test(void)
g_assert_cmpint(qpci_io_readb(pdev, bar, cmb_bar_size - 1), ==, 0x11);
g_assert_cmpint(qpci_io_readw(pdev, bar, cmb_bar_size - 1), !=, 0x2211);
g_assert_cmpint(qpci_io_readl(pdev, bar, cmb_bar_size - 1), !=, 0x44332211);
- g_free(pdev);
-
- qnvme_stop(qs);
}
-int main(int argc, char **argv)
+static void nvme_register_nodes(void)
{
- g_test_init(&argc, &argv, NULL);
- qtest_add_func("/nvme/nop", nop);
- qtest_add_func("/nvme/cmb_test", nvmetest_cmb_test);
+ QOSGraphEdgeOptions opts = {
+ .extra_device_opts = "addr=04.0,drive=drv0,serial=foo",
+ .before_cmd_line = "-drive id=drv0,if=none,file=null-co://,format=raw",
+ };
+
+ add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
- return g_test_run();
+ qos_node_create_driver("nvme", nvme_create);
+ qos_node_consumes("nvme", "pci-bus", &opts);
+ qos_node_produces("nvme", "pci-device");
+
+ qos_add_test("oob-cmb-access", "nvme", nvmetest_oob_cmb_test, &(QOSGraphTestOptions) {
+ .edge.extra_device_opts = "cmb_size_mb=2"
+ });
}
+
+libqos_init(nvme_register_nodes);