]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: Add gpio-sysinfo test
authorSean Anderson <sean.anderson@seco.com>
Tue, 20 Apr 2021 14:50:58 +0000 (10:50 -0400)
committerTom Rini <trini@konsulko.com>
Tue, 4 May 2021 11:57:18 +0000 (07:57 -0400)
This adds a test for the gpio-sysinfo driver.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
configs/sandbox64_defconfig
configs/sandbox_defconfig
configs/sandbox_flattree_defconfig
configs/sandbox_noinst_defconfig
configs/sandbox_spl_defconfig
test/dm/Makefile
test/dm/sysinfo-gpio.c [new file with mode: 0644]

index 4fde923e9ad6f3b87b2a0db4710c30708ea30d4a..6fd56c351cfde79606f7a00b616435e102ed3e2a 100644 (file)
                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>;
index 8a7e519847d40c8e68a5817de8f896a7517ccc9a..80c5be2067aff1909be81904dbf7d729ba178c47 100644 (file)
@@ -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
index 00befc8b407ce760330d6c268ca3abf2a43d905a..570af61cbd412527d8cb3c06bb1ec18664d021b3 100644 (file)
@@ -245,6 +245,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
index 97ac46d21f4438908c0b80828b911c07b6ad14dd..853c9440ea02a354b5f0b8bfd6fce4657da2e9a1 100644 (file)
@@ -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
index 2e7b13855822876bde3359b471086a2c93cca55d..c7fc98b5569a01ef9370e52ffff678bc4ce01781 100644 (file)
@@ -197,6 +197,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
index a71349432e353f6796d29a2e065ba9eb642e1e3e..87223a54d87302731e2e52c201b3159f49eacfbc 100644 (file)
@@ -199,6 +199,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
index e7cb1eec960baebf2bbd06c9f946d0b73af1241e..c9644617a1fe17c80c7a85300f6d69c2cb0b2d06 100644 (file)
@@ -96,6 +96,7 @@ obj-$(CONFIG_SPMI) += spmi.o
 obj-y += syscon.o
 obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o
 obj-$(CONFIG_SYSINFO) += sysinfo.o
+obj-$(CONFIG_SYSINFO_GPIO) += sysinfo-gpio.o
 obj-$(CONFIG_TEE) += tee.o
 obj-$(CONFIG_TIMER) += timer.o
 obj-$(CONFIG_DM_USB) += usb.o
diff --git a/test/dm/sysinfo-gpio.c b/test/dm/sysinfo-gpio.c
new file mode 100644 (file)
index 0000000..2e494b3
--- /dev/null
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Sean Anderson <sean.anderson@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);