From nobody Mon Feb 9 13:59:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543852305018543.4162082824281; Mon, 3 Dec 2018 07:51:45 -0800 (PST) Received: from localhost ([::1]:50265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTqVb-0001dF-Ex for importer@patchew.org; Mon, 03 Dec 2018 10:51:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTqEl-0000LB-Bb for qemu-devel@nongnu.org; Mon, 03 Dec 2018 10:34:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTqEh-0004k6-SP for qemu-devel@nongnu.org; Mon, 03 Dec 2018 10:34:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gTqEh-0004iy-Ji for qemu-devel@nongnu.org; Mon, 03 Dec 2018 10:34:15 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC081307D91D; Mon, 3 Dec 2018 15:34:14 +0000 (UTC) Received: from 640k.localdomain.com (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id A936E17D42; Mon, 3 Dec 2018 15:34:13 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 3 Dec 2018 16:32:41 +0100 Message-Id: <1543851204-41186-29-git-send-email-pbonzini@redhat.com> In-Reply-To: <1543851204-41186-1-git-send-email-pbonzini@redhat.com> References: <1543851204-41186-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 03 Dec 2018 15:34:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 28/71] qos-test: sdhci test node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Emanuele Giuseppe Esposito , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito 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 Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- 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 752f2c2..e6be21c 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -216,7 +216,6 @@ check-qtest-i386-y +=3D tests/migration-test$(EXESUF) check-qtest-i386-y +=3D tests/test-x86-cpuid-compat$(EXESUF) check-qtest-i386-y +=3D tests/numa-test$(EXESUF) check-qtest-x86_64-y +=3D $(check-qtest-i386-y) -check-qtest-x86_64-$(CONFIG_SDHCI) +=3D tests/sdhci-test$(EXESUF) =20 check-qtest-alpha-y +=3D tests/boot-serial-test$(EXESUF) =20 @@ -278,11 +277,9 @@ check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) check-qtest-arm-y +=3D tests/virtio-blk-test$(EXESUF) check-qtest-arm-y +=3D tests/test-arm-mptimer$(EXESUF) check-qtest-arm-y +=3D tests/boot-serial-test$(EXESUF) -check-qtest-arm-$(CONFIG_SDHCI) +=3D tests/sdhci-test$(EXESUF) check-qtest-arm-y +=3D tests/hexloader-test$(EXESUF) =20 check-qtest-aarch64-y =3D tests/numa-test$(EXESUF) -check-qtest-aarch64-$(CONFIG_SDHCI) +=3D tests/sdhci-test$(EXESUF) check-qtest-aarch64-y +=3D tests/boot-serial-test$(EXESUF) check-qtest-aarch64-y +=3D tests/migration-test$(EXESUF) =20 @@ -688,6 +685,9 @@ qos-test-obj-y +=3D tests/libqos/arm-smdkc210-machine.o qos-test-obj-y +=3D tests/libqos/arm-xilinx-zynq-a9-machine.o qos-test-obj-y +=3D tests/libqos/x86_64_pc-machine.o =20 +# Tests +qos-test-obj-y +=3D tests/sdhci-test.o + check-unit-y +=3D tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) =20 @@ -780,7 +780,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 test= s/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) =20 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" =20 #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 =20 -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[] =3D { - /* PC via PCI */ - { "x86_64", "pc", - {-1, 2, 0, {1, 0x057834b4} }, - .pci =3D { 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 =3D qpci_io_readw(s->pci.dev, s->mem_bar, reg); - } else { - val =3D 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 =3D qpci_io_readq(s->pci.dev, s->mem_bar, reg); - } else { - val =3D 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; =20 - v =3D sdhci_readw(s, SDHC_HCVER); + v =3D s->readw(s, SDHC_HCVER); v &=3D 0xff; v +=3D 1; g_assert_cmpuint(v, =3D=3D, version); @@ -122,7 +36,7 @@ static void check_capab_capareg(QSDHCI *s, uint64_t expe= c_capab) { uint64_t capab; =20 - capab =3D sdhci_readq(s, SDHC_CAPAB); + capab =3D s->readq(s, SDHC_CAPAB); g_assert_cmphex(capab, =3D=3D, expec_capab); } =20 @@ -131,11 +45,11 @@ static void check_capab_readonly(QSDHCI *s) const uint64_t vrand =3D 0x123456789abcdef; uint64_t capab0, capab1; =20 - capab0 =3D sdhci_readq(s, SDHC_CAPAB); + capab0 =3D s->readq(s, SDHC_CAPAB); g_assert_cmpuint(capab0, !=3D, vrand); =20 - sdhci_writeq(s, SDHC_CAPAB, vrand); - capab1 =3D sdhci_readq(s, SDHC_CAPAB); + s->writeq(s, SDHC_CAPAB, vrand); + capab1 =3D s->readq(s, SDHC_CAPAB); g_assert_cmpuint(capab1, !=3D, vrand); g_assert_cmpuint(capab1, =3D=3D, capab0); } @@ -147,7 +61,7 @@ static void check_capab_baseclock(QSDHCI *s, uint8_t exp= ec_freq) if (!expec_freq) { return; } - capab =3D sdhci_readq(s, SDHC_CAPAB); + capab =3D s->readq(s, SDHC_CAPAB); capab_freq =3D FIELD_EX64(capab, SDHC_CAPAB, BASECLKFREQ); g_assert_cmpuint(capab_freq, =3D=3D, expec_freq); } @@ -156,7 +70,7 @@ static void check_capab_sdma(QSDHCI *s, bool supported) { uint64_t capab, capab_sdma; =20 - capab =3D sdhci_readq(s, SDHC_CAPAB); + capab =3D s->readq(s, SDHC_CAPAB); capab_sdma =3D FIELD_EX64(capab, SDHC_CAPAB, SDMA); g_assert_cmpuint(capab_sdma, =3D=3D, supported); } @@ -167,7 +81,7 @@ static void check_capab_v3(QSDHCI *s, uint8_t version) =20 if (version < 3) { /* before v3 those fields are RESERVED */ - capab =3D sdhci_readq(s, SDHC_CAPAB); + capab =3D s->readq(s, SDHC_CAPAB); capab_v3 =3D FIELD_EX64(capab, SDHC_CAPAB, SDR); g_assert_cmpuint(capab_v3, =3D=3D, 0); capab_v3 =3D FIELD_EX64(capab, SDHC_CAPAB, DRIVER); @@ -175,78 +89,21 @@ static void check_capab_v3(QSDHCI *s, uint8_t version) } } =20 -static QSDHCI *machine_start(const struct sdhci_t *test) -{ - QSDHCI *s =3D g_new0(QSDHCI, 1); - - if (test->pci.vendor_id) { - /* PCI */ - uint16_t vendor_id, device_id; - uint64_t barsize; - - global_qtest =3D qtest_initf("-machine %s -device sdhci-pci", - test->machine); - - s->pci.bus =3D qpci_new_pc(global_qtest, NULL); - - /* Find PCI device and verify it's the right one */ - s->pci.dev =3D qpci_device_find(s->pci.bus, QPCI_DEVFN(4, 0)); - g_assert_nonnull(s->pci.dev); - vendor_id =3D qpci_config_readw(s->pci.dev, PCI_VENDOR_ID); - device_id =3D qpci_config_readw(s->pci.dev, PCI_DEVICE_ID); - g_assert(vendor_id =3D=3D test->pci.vendor_id); - g_assert(device_id =3D=3D test->pci.device_id); - s->mem_bar =3D qpci_iomap(s->pci.dev, 0, &barsize); - qpci_device_enable(s->pci.dev); - } else { - /* SysBus */ - global_qtest =3D qtest_initf("-machine %s", test->machine); - s->addr =3D 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 =3D data; - QSDHCI *s; + QSDHCI *s =3D obj; =20 - s =3D 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); } =20 -int main(int argc, char *argv[]) +static void register_sdhci_test(void) { - const char *arch =3D qtest_get_arch(); - char *name; - int i; - - g_test_init(&argc, &argv, NULL); - for (i =3D 0; i < ARRAY_SIZE(models); i++) { - if (strcmp(arch, models[i].arch)) { - continue; - } - name =3D 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); --=20 1.8.3.1