diff mbox series

[v3,5/5] tests/qtest/nvme-test: add mmio read test

Message ID 20210714060125.994882-6-its@irrelevant.dk
State New
Headers show
Series hw/nvme: fix mmio read | expand

Commit Message

Klaus Jensen July 14, 2021, 6:01 a.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

Add a regression test for mmio read on big-endian hosts.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 tests/qtest/nvme-test.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Gollu Appalanaidu July 14, 2021, 11:58 a.m. UTC | #1
On Wed, Jul 14, 2021 at 08:01:25AM +0200, Klaus Jensen wrote:
>From: Klaus Jensen <k.jensen@samsung.com>
>
>Add a regression test for mmio read on big-endian hosts.
>
>Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
>---
> tests/qtest/nvme-test.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
>diff --git a/tests/qtest/nvme-test.c b/tests/qtest/nvme-test.c
>index 47e757d7e2af..f8bafb5d70fb 100644
>--- a/tests/qtest/nvme-test.c
>+++ b/tests/qtest/nvme-test.c
>@@ -67,6 +67,30 @@ static void nvmetest_oob_cmb_test(void *obj, void *data, QGuestAllocator *alloc)
>     g_assert_cmpint(qpci_io_readl(pdev, bar, cmb_bar_size - 1), !=, 0x44332211);
> }
>
>+static void nvmetest_reg_read_test(void *obj, void *data, QGuestAllocator *alloc)
>+{
>+    QNvme *nvme = obj;
>+    QPCIDevice *pdev = &nvme->dev;
>+    QPCIBar bar;
>+    uint32_t cap_lo, cap_hi;
>+    uint64_t cap;
>+
>+    qpci_device_enable(pdev);
>+    bar = qpci_iomap(pdev, 0, NULL);
>+
>+    cap_lo = qpci_io_readl(pdev, bar, 0x0);
>+    g_assert_cmpint(NVME_CAP_MQES(cap_lo), ==, 0x7ff);
>+
>+    cap_hi = qpci_io_readl(pdev, bar, 0x4);
>+    g_assert_cmpint(NVME_CAP_MPSMAX((uint64_t)cap_hi << 32), ==, 0x4);
>+
>+    cap = qpci_io_readq(pdev, bar, 0x0);
>+    g_assert_cmpint(NVME_CAP_MQES(cap), ==, 0x7ff);
>+    g_assert_cmpint(NVME_CAP_MPSMAX(cap), ==, 0x4);
>+
>+    qpci_iounmap(pdev, bar);
>+}
>+
> static void nvmetest_pmr_reg_test(void *obj, void *data, QGuestAllocator *alloc)
> {
>     QNvme *nvme = obj;
>@@ -142,6 +166,8 @@ static void nvme_register_nodes(void)
>                  &(QOSGraphTestOptions) {
>         .edge.extra_device_opts = "pmrdev=pmr0"
>     });
>+
>+    qos_add_test("reg-read", "nvme", nvmetest_reg_read_test, NULL);
> }
>
> libqos_init(nvme_register_nodes);
>-- 
>2.32.0
>
>

Reviewed-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
diff mbox series

Patch

diff --git a/tests/qtest/nvme-test.c b/tests/qtest/nvme-test.c
index 47e757d7e2af..f8bafb5d70fb 100644
--- a/tests/qtest/nvme-test.c
+++ b/tests/qtest/nvme-test.c
@@ -67,6 +67,30 @@  static void nvmetest_oob_cmb_test(void *obj, void *data, QGuestAllocator *alloc)
     g_assert_cmpint(qpci_io_readl(pdev, bar, cmb_bar_size - 1), !=, 0x44332211);
 }
 
+static void nvmetest_reg_read_test(void *obj, void *data, QGuestAllocator *alloc)
+{
+    QNvme *nvme = obj;
+    QPCIDevice *pdev = &nvme->dev;
+    QPCIBar bar;
+    uint32_t cap_lo, cap_hi;
+    uint64_t cap;
+
+    qpci_device_enable(pdev);
+    bar = qpci_iomap(pdev, 0, NULL);
+
+    cap_lo = qpci_io_readl(pdev, bar, 0x0);
+    g_assert_cmpint(NVME_CAP_MQES(cap_lo), ==, 0x7ff);
+
+    cap_hi = qpci_io_readl(pdev, bar, 0x4);
+    g_assert_cmpint(NVME_CAP_MPSMAX((uint64_t)cap_hi << 32), ==, 0x4);
+
+    cap = qpci_io_readq(pdev, bar, 0x0);
+    g_assert_cmpint(NVME_CAP_MQES(cap), ==, 0x7ff);
+    g_assert_cmpint(NVME_CAP_MPSMAX(cap), ==, 0x4);
+
+    qpci_iounmap(pdev, bar);
+}
+
 static void nvmetest_pmr_reg_test(void *obj, void *data, QGuestAllocator *alloc)
 {
     QNvme *nvme = obj;
@@ -142,6 +166,8 @@  static void nvme_register_nodes(void)
                  &(QOSGraphTestOptions) {
         .edge.extra_device_opts = "pmrdev=pmr0"
     });
+
+    qos_add_test("reg-read", "nvme", nvmetest_reg_read_test, NULL);
 }
 
 libqos_init(nvme_register_nodes);