qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, lviver@redhat.com,
	Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
Subject: [Qemu-devel] [PULL 14/57] qos-test: sdhci test node
Date: Thu,  7 Mar 2019 18:29:21 +0100	[thread overview]
Message-ID: <1551979804-6060-15-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com>

From: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>

Convert tests/sdhci-test in first qgraph test node, sdhci-test. This test
consumes an sdhci interface and checks that its function return the
expected values.

Note that this test does not allocate any sdhci structure, it's all done by the
qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/Makefile.include |   7 +-
 tests/sdhci-test.c     | 185 ++++++-------------------------------------------
 2 files changed, 24 insertions(+), 168 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index d675ad8..4b545ac 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -229,7 +229,6 @@ check-qtest-i386-y += tests/test-announce-self$(EXESUF)
 check-qtest-i386-y += tests/test-x86-cpuid-compat$(EXESUF)
 check-qtest-i386-y += tests/numa-test$(EXESUF)
 check-qtest-x86_64-y += $(check-qtest-i386-y)
-check-qtest-x86_64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
 
 check-qtest-alpha-y += tests/boot-serial-test$(EXESUF)
 check-qtest-alpha-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF)
@@ -299,11 +298,9 @@ check-qtest-arm-y += tests/m25p80-test$(EXESUF)
 check-qtest-arm-$(CONFIG_VIRTIO_BLK) += tests/virtio-blk-test$(EXESUF)
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
-check-qtest-arm-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
 check-qtest-arm-y += tests/hexloader-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
-check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
 check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
@@ -762,6 +759,9 @@ qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o
 qos-test-obj-y += tests/libqos/arm-xilinx-zynq-a9-machine.o
 qos-test-obj-y += tests/libqos/x86_64_pc-machine.o
 
+# Tests
+qos-test-obj-y += tests/sdhci-test.o
+
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
 
@@ -857,7 +857,6 @@ tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o
 tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y)
 tests/numa-test$(EXESUF): tests/numa-test.o
 tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o tests/acpi-utils.o
-tests/sdhci-test$(EXESUF): tests/sdhci-test.o $(libqos-pc-obj-y)
 tests/cdrom-test$(EXESUF): tests/cdrom-test.o tests/boot-sector.o $(libqos-obj-y)
 
 tests/migration/stress$(EXESUF): tests/migration/stress.o
diff --git a/tests/sdhci-test.c b/tests/sdhci-test.c
index 28d481b..2f177e5 100644
--- a/tests/sdhci-test.c
+++ b/tests/sdhci-test.c
@@ -12,6 +12,8 @@
 #include "libqtest.h"
 #include "libqos/pci-pc.h"
 #include "hw/pci/pci.h"
+#include "libqos/qgraph.h"
+#include "libqos/sdhci.h"
 
 #define SDHC_CAPAB                      0x40
 FIELD(SDHC_CAPAB, BASECLKFREQ,               8, 8); /* since v2 */
@@ -20,99 +22,11 @@ FIELD(SDHC_CAPAB, SDR,                      32, 3); /* since v3 */
 FIELD(SDHC_CAPAB, DRIVER,                   36, 3); /* since v3 */
 #define SDHC_HCVER                      0xFE
 
-static const struct sdhci_t {
-    const char *arch, *machine;
-    struct {
-        uintptr_t addr;
-        uint8_t version;
-        uint8_t baseclock;
-        struct {
-            bool sdma;
-            uint64_t reg;
-        } capab;
-    } sdhci;
-    struct {
-        uint16_t vendor_id, device_id;
-    } pci;
-} models[] = {
-    /* PC via PCI */
-    { "x86_64", "pc",
-        {-1,         2, 0,  {1, 0x057834b4} },
-        .pci = { PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_SDHCI } },
-
-    /* Exynos4210 */
-    { "arm",    "smdkc210",
-        {0x12510000, 2, 0,  {1, 0x5e80080} } },
-
-    /* i.MX 6 */
-    { "arm",    "sabrelite",
-        {0x02190000, 3, 0,  {1, 0x057834b4} } },
-
-    /* BCM2835 */
-    { "arm",    "raspi2",
-        {0x3f300000, 3, 52, {0, 0x052134b4} } },
-
-    /* Zynq-7000 */
-    { "arm",    "xilinx-zynq-a9",   /* Datasheet: UG585 (v1.12.1) */
-        {0xe0100000, 2, 0,  {1, 0x69ec0080} } },
-
-    /* ZynqMP */
-    { "aarch64", "xlnx-zcu102",     /* Datasheet: UG1085 (v1.7) */
-        {0xff160000, 3, 0,  {1, 0x280737ec6481} } },
-
-};
-
-typedef struct QSDHCI {
-    struct {
-        QPCIBus *bus;
-        QPCIDevice *dev;
-    } pci;
-    union {
-        QPCIBar mem_bar;
-        uint64_t addr;
-    };
-} QSDHCI;
-
-static uint16_t sdhci_readw(QSDHCI *s, uint32_t reg)
-{
-    uint16_t val;
-
-    if (s->pci.dev) {
-        val = qpci_io_readw(s->pci.dev, s->mem_bar, reg);
-    } else {
-        val = qtest_readw(global_qtest, s->addr + reg);
-    }
-
-    return val;
-}
-
-static uint64_t sdhci_readq(QSDHCI *s, uint32_t reg)
-{
-    uint64_t val;
-
-    if (s->pci.dev) {
-        val = qpci_io_readq(s->pci.dev, s->mem_bar, reg);
-    } else {
-        val = qtest_readq(global_qtest, s->addr + reg);
-    }
-
-    return val;
-}
-
-static void sdhci_writeq(QSDHCI *s, uint32_t reg, uint64_t val)
-{
-    if (s->pci.dev) {
-        qpci_io_writeq(s->pci.dev, s->mem_bar, reg, val);
-    } else {
-        qtest_writeq(global_qtest, s->addr + reg, val);
-    }
-}
-
 static void check_specs_version(QSDHCI *s, uint8_t version)
 {
     uint32_t v;
 
-    v = sdhci_readw(s, SDHC_HCVER);
+    v = s->readw(s, SDHC_HCVER);
     v &= 0xff;
     v += 1;
     g_assert_cmpuint(v, ==, version);
@@ -122,7 +36,7 @@ static void check_capab_capareg(QSDHCI *s, uint64_t expec_capab)
 {
     uint64_t capab;
 
-    capab = sdhci_readq(s, SDHC_CAPAB);
+    capab = s->readq(s, SDHC_CAPAB);
     g_assert_cmphex(capab, ==, expec_capab);
 }
 
@@ -131,11 +45,11 @@ static void check_capab_readonly(QSDHCI *s)
     const uint64_t vrand = 0x123456789abcdef;
     uint64_t capab0, capab1;
 
-    capab0 = sdhci_readq(s, SDHC_CAPAB);
+    capab0 = s->readq(s, SDHC_CAPAB);
     g_assert_cmpuint(capab0, !=, vrand);
 
-    sdhci_writeq(s, SDHC_CAPAB, vrand);
-    capab1 = sdhci_readq(s, SDHC_CAPAB);
+    s->writeq(s, SDHC_CAPAB, vrand);
+    capab1 = s->readq(s, SDHC_CAPAB);
     g_assert_cmpuint(capab1, !=, vrand);
     g_assert_cmpuint(capab1, ==, capab0);
 }
@@ -147,7 +61,7 @@ static void check_capab_baseclock(QSDHCI *s, uint8_t expec_freq)
     if (!expec_freq) {
         return;
     }
-    capab = sdhci_readq(s, SDHC_CAPAB);
+    capab = s->readq(s, SDHC_CAPAB);
     capab_freq = FIELD_EX64(capab, SDHC_CAPAB, BASECLKFREQ);
     g_assert_cmpuint(capab_freq, ==, expec_freq);
 }
@@ -156,7 +70,7 @@ static void check_capab_sdma(QSDHCI *s, bool supported)
 {
     uint64_t capab, capab_sdma;
 
-    capab = sdhci_readq(s, SDHC_CAPAB);
+    capab = s->readq(s, SDHC_CAPAB);
     capab_sdma = FIELD_EX64(capab, SDHC_CAPAB, SDMA);
     g_assert_cmpuint(capab_sdma, ==, supported);
 }
@@ -167,7 +81,7 @@ static void check_capab_v3(QSDHCI *s, uint8_t version)
 
     if (version < 3) {
         /* before v3 those fields are RESERVED */
-        capab = sdhci_readq(s, SDHC_CAPAB);
+        capab = s->readq(s, SDHC_CAPAB);
         capab_v3 = FIELD_EX64(capab, SDHC_CAPAB, SDR);
         g_assert_cmpuint(capab_v3, ==, 0);
         capab_v3 = FIELD_EX64(capab, SDHC_CAPAB, DRIVER);
@@ -175,78 +89,21 @@ static void check_capab_v3(QSDHCI *s, uint8_t version)
     }
 }
 
-static QSDHCI *machine_start(const struct sdhci_t *test)
-{
-    QSDHCI *s = g_new0(QSDHCI, 1);
-
-    if (test->pci.vendor_id) {
-        /* PCI */
-        uint16_t vendor_id, device_id;
-        uint64_t barsize;
-
-        global_qtest = qtest_initf("-machine %s -device sdhci-pci",
-                                   test->machine);
-
-        s->pci.bus = qpci_new_pc(global_qtest, NULL);
-
-        /* Find PCI device and verify it's the right one */
-        s->pci.dev = qpci_device_find(s->pci.bus, QPCI_DEVFN(4, 0));
-        g_assert_nonnull(s->pci.dev);
-        vendor_id = qpci_config_readw(s->pci.dev, PCI_VENDOR_ID);
-        device_id = qpci_config_readw(s->pci.dev, PCI_DEVICE_ID);
-        g_assert(vendor_id == test->pci.vendor_id);
-        g_assert(device_id == test->pci.device_id);
-        s->mem_bar = qpci_iomap(s->pci.dev, 0, &barsize);
-        qpci_device_enable(s->pci.dev);
-    } else {
-        /* SysBus */
-        global_qtest = qtest_initf("-machine %s", test->machine);
-        s->addr = test->sdhci.addr;
-    }
-
-    return s;
-}
-
-static void machine_stop(QSDHCI *s)
-{
-    qpci_free_pc(s->pci.bus);
-    g_free(s->pci.dev);
-    qtest_quit(global_qtest);
-    g_free(s);
-}
-
-static void test_machine(const void *data)
+static void test_registers(void *obj, void *data, QGuestAllocator *alloc)
 {
-    const struct sdhci_t *test = data;
-    QSDHCI *s;
+    QSDHCI *s = obj;
 
-    s = machine_start(test);
-
-    check_specs_version(s, test->sdhci.version);
-    check_capab_capareg(s, test->sdhci.capab.reg);
+    check_specs_version(s, s->props.version);
+    check_capab_capareg(s, s->props.capab.reg);
     check_capab_readonly(s);
-    check_capab_v3(s, test->sdhci.version);
-    check_capab_sdma(s, test->sdhci.capab.sdma);
-    check_capab_baseclock(s, test->sdhci.baseclock);
-
-    machine_stop(s);
+    check_capab_v3(s, s->props.version);
+    check_capab_sdma(s, s->props.capab.sdma);
+    check_capab_baseclock(s, s->props.baseclock);
 }
 
-int main(int argc, char *argv[])
+static void register_sdhci_test(void)
 {
-    const char *arch = qtest_get_arch();
-    char *name;
-    int i;
-
-    g_test_init(&argc, &argv, NULL);
-    for (i = 0; i < ARRAY_SIZE(models); i++) {
-        if (strcmp(arch, models[i].arch)) {
-            continue;
-        }
-        name = g_strdup_printf("sdhci/%s", models[i].machine);
-        qtest_add_data_func(name, &models[i], test_machine);
-        g_free(name);
-    }
-
-    return g_test_run();
+    qos_add_test("registers", "sdhci", test_registers, NULL);
 }
+
+libqos_init(register_sdhci_test);
-- 
1.8.3.1

  parent reply	other threads:[~2019-03-07 17:30 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07 17:29 [Qemu-devel] [PULL 00/57] qgraph merge Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 01/57] chardev-socket: do not blindly reset handlers when switching GMainContext Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 02/57] tests/libqos: introduce virtio_start_device Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 03/57] tests/libqos: rename qpci_init_pc and qpci_init_spapr functions Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 04/57] tests/libqos: embed allocators instead of malloc-ing them separately Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 05/57] tests: qgraph API for the qtest driver framework Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 06/57] tests/libqos: pci-pc driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 07/57] tests/libqos: x86_64/pc machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 08/57] tests/libqos: sdhci driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 09/57] tests/libqos: arm/raspi2 machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 10/57] tests/libqos: arm/smdkc210 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 11/57] tests/libqos: arm/sabrelite " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 12/57] tests/libqos: arm/xilinx-zynq-a9 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 13/57] tests/libqos: aarch64/xlnx-zcu102 " Paolo Bonzini
2019-03-07 17:29 ` Paolo Bonzini [this message]
2019-03-07 17:29 ` [Qemu-devel] [PULL 15/57] tests/qgraph: add generic PCI testcases Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 16/57] tests/libqos: pci-spapr driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 17/57] tests/qgraph: ppc64/pseries machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 18/57] tests/libqos: has_buggy_msi flag Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 19/57] tests/libqos: e1000e driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 20/57] qos-test: e1000e test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 21/57] tests/libqos: virtio-pci driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 22/57] tests/libqos: remove global_qtest from virtio endianness checks Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 23/57] tests/libqos: virtio-mmio driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 24/57] tests/libqos: arm/virt machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 25/57] tests/qgraph: add generic virtio testcases Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 26/57] tests/libqos: virtio-serial driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 27/57] qos-test: virtio-console and virtio-serial test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 28/57] tests/libqos: virtio-9p driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 29/57] qos-test: virtio-9p test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 30/57] tests/libqos: virtio-balloon driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 31/57] tests/qgraph: remove virtio-balloon-test Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 32/57] tests/libqos: virtio-rng driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 33/57] qos-test: virtio-rng test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 34/57] tests/libqos: virtio-blk driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 35/57] qos-test: virtio-blk test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 36/57] tests/libqos: virtio-net driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 37/57] qos-test: virtio-net test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 38/57] tests/libqos: support multiqueue for virtio-net Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 39/57] vhost-user-test: always use 256 MiB of guest memory Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 40/57] qos-test: vhost-user test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 41/57] tests/libqos: virtio-scsi driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 42/57] qos-test: virtio-scsi test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 43/57] tests/libqos: remove pre-qgraph QVirtioPCIDevice API Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 44/57] tests: move virtio entirely to qos-test Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 45/57] qos-test: ac97 test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 46/57] qos-test: tpci200 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 47/57] qos-test: ipoctal232 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 48/57] qos-test: ne2k_pci " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 49/57] qos-test: nvme " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 50/57] qos-test: pcnet " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 51/57] qos-test: spapr-phb " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 52/57] qos-test: usb-hcd-ohci " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 53/57] qos-test: vmxnet3 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 54/57] qos-test: es1370 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 55/57] qos-test: eepro100 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 56/57] qos-test: e1000 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 57/57] qos-test: megasas " Paolo Bonzini
2019-03-08 15:16 ` [Qemu-devel] [PULL 00/57] qgraph merge Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1551979804-6060-15-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=e.emanuelegiuseppe@gmail.com \
    --cc=lviver@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).