]> git.proxmox.com Git - mirror_qemu.git/blame - tests/nvme-test.c
tests/boot_linux_console: add a test for s390x + s390-ccw-virtio
[mirror_qemu.git] / tests / nvme-test.c
CommitLineData
fc967791
AF
1/*
2 * QTest testcase for NVMe
3 *
4 * Copyright (c) 2014 SUSE LINUX Products GmbH
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9
681c28a3 10#include "qemu/osdep.h"
87ad860c 11#include "qemu/units.h"
fc967791 12#include "libqtest.h"
3157ed33
EGE
13#include "libqos/qgraph.h"
14#include "libqos/pci.h"
87ad860c 15
3157ed33
EGE
16typedef struct QNvme QNvme;
17
18struct QNvme {
19 QOSGraphObject obj;
20 QPCIDevice dev;
21};
22
23static void *nvme_get_driver(void *obj, const char *interface)
87ad860c 24{
3157ed33
EGE
25 QNvme *nvme = obj;
26
27 if (!g_strcmp0(interface, "pci-device")) {
28 return &nvme->dev;
87ad860c
PB
29 }
30
3157ed33
EGE
31 fprintf(stderr, "%s not present in nvme\n", interface);
32 g_assert_not_reached();
87ad860c
PB
33}
34
3157ed33 35static void *nvme_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
87ad860c 36{
3157ed33
EGE
37 QNvme *nvme = g_new0(QNvme, 1);
38 QPCIBus *bus = pci_bus;
fc967791 39
3157ed33
EGE
40 qpci_device_init(&nvme->dev, bus, addr);
41 nvme->obj.get_driver = nvme_get_driver;
87ad860c 42
3157ed33 43 return &nvme->obj;
fc967791
AF
44}
45
3157ed33
EGE
46/* This used to cause a NULL pointer dereference. */
47static void nvmetest_oob_cmb_test(void *obj, void *data, QGuestAllocator *alloc)
fc967791 48{
87ad860c 49 const int cmb_bar_size = 2 * MiB;
3157ed33
EGE
50 QNvme *nvme = obj;
51 QPCIDevice *pdev = &nvme->dev;
87ad860c 52 QPCIBar bar;
fc967791 53
87ad860c
PB
54 qpci_device_enable(pdev);
55 bar = qpci_iomap(pdev, 2, NULL);
56
57 qpci_io_writel(pdev, bar, 0, 0xccbbaa99);
58 g_assert_cmpint(qpci_io_readb(pdev, bar, 0), ==, 0x99);
59 g_assert_cmpint(qpci_io_readw(pdev, bar, 0), ==, 0xaa99);
60
61 /* Test partially out-of-bounds accesses. */
62 qpci_io_writel(pdev, bar, cmb_bar_size - 1, 0x44332211);
63 g_assert_cmpint(qpci_io_readb(pdev, bar, cmb_bar_size - 1), ==, 0x11);
64 g_assert_cmpint(qpci_io_readw(pdev, bar, cmb_bar_size - 1), !=, 0x2211);
65 g_assert_cmpint(qpci_io_readl(pdev, bar, cmb_bar_size - 1), !=, 0x44332211);
87ad860c 66}
fc967791 67
3157ed33 68static void nvme_register_nodes(void)
87ad860c 69{
3157ed33
EGE
70 QOSGraphEdgeOptions opts = {
71 .extra_device_opts = "addr=04.0,drive=drv0,serial=foo",
72 .before_cmd_line = "-drive id=drv0,if=none,file=null-co://,format=raw",
73 };
74
75 add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
fc967791 76
3157ed33
EGE
77 qos_node_create_driver("nvme", nvme_create);
78 qos_node_consumes("nvme", "pci-bus", &opts);
79 qos_node_produces("nvme", "pci-device");
80
81 qos_add_test("oob-cmb-access", "nvme", nvmetest_oob_cmb_test, &(QOSGraphTestOptions) {
82 .edge.extra_device_opts = "cmb_size_mb=2"
83 });
fc967791 84}
3157ed33
EGE
85
86libqos_init(nvme_register_nodes);