[PATCH v4 5/5] test: Add gpio-sysinfo test

Sean Anderson sean.anderson at seco.com
Tue Apr 20 16:50:58 CEST 2021


This adds a test for the gpio-sysinfo driver.

Signed-off-by: Sean Anderson <sean.anderson at seco.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
---

Changes in v4:
- Enable sysinfo_gpio test for sandbox

Changes in v3:
- Use SYSINFO_ID_BOARD_MODEL instead of SYSINFO_ID_REVISION

Changes in v2:
- Reorder includes

 arch/sandbox/dts/test.dts          |  7 +++
 configs/sandbox64_defconfig        |  1 +
 configs/sandbox_defconfig          |  1 +
 configs/sandbox_flattree_defconfig |  1 +
 configs/sandbox_noinst_defconfig   |  1 +
 configs/sandbox_spl_defconfig      |  1 +
 test/dm/Makefile                   |  1 +
 test/dm/sysinfo-gpio.c             | 69 ++++++++++++++++++++++++++++++
 8 files changed, 82 insertions(+)
 create mode 100644 test/dm/sysinfo-gpio.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 48240aa26f..78a2fcbc56 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1526,6 +1526,13 @@
 		compatible = "sandbox,sysinfo-sandbox";
 	};
 
+	sysinfo-gpio {
+		compatible = "gpio-sysinfo";
+		gpios = <&gpio_a 15>, <&gpio_a 16>, <&gpio_a 17>;
+		revisions = <19>, <5>;
+		names = "rev_a", "foo";
+	};
+
 	some_regmapped-bus {
 		#address-cells = <0x1>;
 		#size-cells = <0x1>;
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 8a7e519847..80c5be2067 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -204,6 +204,7 @@ CONFIG_SPMI=y
 CONFIG_SPMI_SANDBOX=y
 CONFIG_SYSINFO=y
 CONFIG_SYSINFO_SANDBOX=y
+CONFIG_SYSINFO_GPIO=y
 CONFIG_SYSRESET=y
 CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index d3de9c3155..48dfd194e2 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -247,6 +247,7 @@ CONFIG_SPMI=y
 CONFIG_SPMI_SANDBOX=y
 CONFIG_SYSINFO=y
 CONFIG_SYSINFO_SANDBOX=y
+CONFIG_SYSINFO_GPIO=y
 CONFIG_SYSRESET=y
 CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig
index 97ac46d21f..853c9440ea 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -178,6 +178,7 @@ CONFIG_SPMI=y
 CONFIG_SPMI_SANDBOX=y
 CONFIG_SYSINFO=y
 CONFIG_SYSINFO_SANDBOX=y
+CONFIG_SYSINFO_GPIO=y
 CONFIG_SYSRESET=y
 CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig
index 01905900cb..e47e351e56 100644
--- a/configs/sandbox_noinst_defconfig
+++ b/configs/sandbox_noinst_defconfig
@@ -198,6 +198,7 @@ CONFIG_SPMI=y
 CONFIG_SPMI_SANDBOX=y
 CONFIG_SYSINFO=y
 CONFIG_SYSINFO_SANDBOX=y
+CONFIG_SYSINFO_GPIO=y
 CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_TIMER=y
diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
index 0fac3adba7..d463ee421c 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -200,6 +200,7 @@ CONFIG_SPMI=y
 CONFIG_SPMI_SANDBOX=y
 CONFIG_SYSINFO=y
 CONFIG_SYSINFO_SANDBOX=y
+CONFIG_SYSINFO_GPIO=y
 CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_TIMER=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 100e7701d2..33a6fa9620 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -101,5 +101,6 @@ ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
 obj-$(CONFIG_QFW) += qfw.o
+obj-$(CONFIG_SYSINFO_GPIO) += sysinfo-gpio.o
 endif
 endif # !SPL
diff --git a/test/dm/sysinfo-gpio.c b/test/dm/sysinfo-gpio.c
new file mode 100644
index 0000000000..2e494b3f34
--- /dev/null
+++ b/test/dm/sysinfo-gpio.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Sean Anderson <sean.anderson at seco.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <log.h>
+#include <sysinfo.h>
+#include <asm/gpio.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_sysinfo_gpio(struct unit_test_state *uts)
+{
+	char buf[64];
+	int val;
+	struct udevice *sysinfo, *gpio;
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_SYSINFO, "sysinfo-gpio",
+					      &sysinfo));
+	ut_assertok(uclass_get_device_by_name(UCLASS_GPIO, "base-gpios", &gpio));
+
+	/*
+	 * Set up pins: pull-up (1), pull-down (0) and floating (2). This should
+	 * result in digits 2 0 1, i.e. 2 * 9 + 1 * 3 = 19
+	 */
+	sandbox_gpio_set_flags(gpio, 15, GPIOD_EXT_PULL_UP);
+	sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_DOWN);
+	sandbox_gpio_set_flags(gpio, 17, 0);
+	ut_assertok(sysinfo_detect(sysinfo));
+	ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+	ut_asserteq(19, val);
+	ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+				    buf));
+	ut_asserteq_str("rev_a", buf);
+
+	/*
+	 * Set up pins: floating (2), pull-up (1) and pull-down (0). This should
+	 * result in digits 0 1 2, i.e. 1 * 3 + 2 = 5
+	 */
+	sandbox_gpio_set_flags(gpio, 15, 0);
+	sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_UP);
+	sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_DOWN);
+	ut_assertok(sysinfo_detect(sysinfo));
+	ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+	ut_asserteq(5, val);
+	ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+				    buf));
+	ut_asserteq_str("foo", buf);
+
+	/*
+	 * Set up pins: floating (2), pull-up (1) and pull-down (0). This should
+	 * result in digits 1 2 0, i.e. 1 * 9 + 2 * 3 = 15
+	 */
+	sandbox_gpio_set_flags(gpio, 15, GPIOD_EXT_PULL_DOWN);
+	sandbox_gpio_set_flags(gpio, 16, 0);
+	sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_UP);
+	ut_assertok(sysinfo_detect(sysinfo));
+	ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+	ut_asserteq(15, val);
+	ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+				    buf));
+	ut_asserteq_str("unknown", buf);
+
+	return 0;
+}
+DM_TEST(dm_test_sysinfo_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
-- 
2.25.1



More information about the U-Boot mailing list