]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: Add tests for board uclass
authorMario Six <mario.six@gdsys.cc>
Tue, 31 Jul 2018 09:44:13 +0000 (11:44 +0200)
committerSimon Glass <sjg@chromium.org>
Sat, 29 Sep 2018 17:49:35 +0000 (11:49 -0600)
Add tests for the new board uclass.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mario Six <mario.six@gdsys.cc>
12 files changed:
arch/sandbox/dts/test.dts
configs/sandbox64_defconfig
configs/sandbox_defconfig
configs/sandbox_flattree_defconfig
configs/sandbox_noblk_defconfig
configs/sandbox_spl_defconfig
drivers/board/Kconfig
drivers/board/Makefile
drivers/board/sandbox.c [new file with mode: 0644]
drivers/board/sandbox.h [new file with mode: 0644]
test/dm/Makefile
test/dm/board.c [new file with mode: 0644]

index b8524e3b7d69284ec15cf8d43bb1a590388f2277..751c13b51da293f670547ae75fe4a16cffd67f50 100644 (file)
                        };
                };
        };
+
+       board {
+               compatible = "sandbox,board_sandbox";
+       };
 };
 
 #include "sandbox_pmic.dtsi"
index 27797c6990bbc7e54f8c3c13beadc02e0f1f05b2..b80e2eba9c23bcb5c9105146eecce1396fb47c75 100644 (file)
@@ -86,6 +86,8 @@ CONFIG_CPU=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
+CONFIG_BOARD=y
+CONFIG_BOARD_SANDBOX=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_DM_I2C_COMPAT=y
index 0b209686bf9ed8c5572782970e6fb55c1b464680..356c48b2208a3e01718b5d390e4581a0354da50f 100644 (file)
@@ -91,6 +91,8 @@ CONFIG_CPU=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
+CONFIG_BOARD=y
+CONFIG_BOARD_SANDBOX=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_DM_I2C_COMPAT=y
index 618d6462a8c1d7f0ae737a8dce883f2c7cd7293a..1d3dd9f4515a8b2a8cbffed5658f1822d8c00783 100644 (file)
@@ -70,6 +70,8 @@ CONFIG_CPU=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
+CONFIG_BOARD=y
+CONFIG_BOARD_SANDBOX=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_DM_I2C_COMPAT=y
index a7691daa008f35521b1bac698db448c5d3bc5b97..5789cf3c8a182b3e3cc0d125bbcf2ac28942dd2a 100644 (file)
@@ -77,6 +77,8 @@ CONFIG_CPU=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
+CONFIG_BOARD=y
+CONFIG_BOARD_SANDBOX=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_DM_I2C_COMPAT=y
index dad5e1ce770cb20ba97bee62d04970ea4d8203a7..3ee276f085b38196638507c45b3db4497840ee4e 100644 (file)
@@ -91,6 +91,8 @@ CONFIG_CPU=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
+CONFIG_BOARD=y
+CONFIG_BOARD_SANDBOX=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_DM_I2C_COMPAT=y
index cc1cf27205584dcacdefc22a66e593030427a84c..2a3fc9c049be06eec89d29e1923fc16404d1cccc 100644 (file)
@@ -10,8 +10,13 @@ if BOARD
 
 
 config BOARD_GAZERBEAM
-       bool "Enable device information for the Gazerbeam board"
+       bool "Enable board driver for the Gazerbeam board"
        help
          Support querying device information for the gdsys Gazerbeam board.
 
+config BOARD_SANDBOX
+       bool "Enable board driver for the Sandbox board"
+       help
+         Support querying device information for the Sandbox boards.
+
 endif
index 12dd2030cfa155d8ffca3ed680819e5036750444..22243380af8e033345825364b44827a7db89fbc6 100644 (file)
@@ -4,3 +4,4 @@
 # Mario Six,  Guntermann & Drunck GmbH, mario.six@gdsys.cc
 obj-$(CONFIG_BOARD) += board-uclass.o
 obj-$(CONFIG_BOARD_GAZERBEAM) += gazerbeam.o
+obj-$(CONFIG_BOARD_SANDBOX) += sandbox.o
diff --git a/drivers/board/sandbox.c b/drivers/board/sandbox.c
new file mode 100644 (file)
index 0000000..50621e4
--- /dev/null
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <board.h>
+
+#include "sandbox.h"
+
+struct board_sandbox_priv {
+       bool called_detect;
+       int test_i1;
+       int test_i2;
+};
+
+char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng",
+                            "Carcosa", "Yuggoth", "The Nameless City"};
+
+int board_sandbox_detect(struct udevice *dev)
+{
+       struct board_sandbox_priv *priv = dev_get_priv(dev);
+
+       priv->called_detect = true;
+       priv->test_i2 = 100;
+
+       return 0;
+}
+
+int board_sandbox_get_bool(struct udevice *dev, int id, bool *val)
+{
+       struct board_sandbox_priv *priv = dev_get_priv(dev);
+
+       switch (id) {
+       case BOOL_CALLED_DETECT:
+               /* Checks if the dectect method has been called */
+               *val = priv->called_detect;
+               return 0;
+       }
+
+       return -ENOENT;
+}
+
+int board_sandbox_get_int(struct udevice *dev, int id, int *val)
+{
+       struct board_sandbox_priv *priv = dev_get_priv(dev);
+
+       switch (id) {
+       case INT_TEST1:
+               *val = priv->test_i1;
+               /* Increments with every call */
+               priv->test_i1++;
+               return 0;
+       case INT_TEST2:
+               *val = priv->test_i2;
+               /* Decrements with every call */
+               priv->test_i2--;
+               return 0;
+       }
+
+       return -ENOENT;
+}
+
+int board_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val)
+{
+       struct board_sandbox_priv *priv = dev_get_priv(dev);
+       int i1 = priv->test_i1;
+       int i2 = priv->test_i2;
+       int index = (i1 * i2) % ARRAY_SIZE(vacation_spots);
+
+       switch (id) {
+       case STR_VACATIONSPOT:
+               /* Picks a vacation spot depending on i1 and i2 */
+               snprintf(val, size, vacation_spots[index]);
+               return 0;
+       }
+
+       return -ENOENT;
+}
+
+static const struct udevice_id board_sandbox_ids[] = {
+       { .compatible = "sandbox,board_sandbox" },
+       { /* sentinel */ }
+};
+
+static const struct board_ops board_sandbox_ops = {
+       .detect = board_sandbox_detect,
+       .get_bool = board_sandbox_get_bool,
+       .get_int = board_sandbox_get_int,
+       .get_str = board_sandbox_get_str,
+};
+
+int board_sandbox_probe(struct udevice *dev)
+{
+       return 0;
+}
+
+U_BOOT_DRIVER(board_sandbox) = {
+       .name           = "board_sandbox",
+       .id             = UCLASS_BOARD,
+       .of_match       = board_sandbox_ids,
+       .ops            = &board_sandbox_ops,
+       .priv_auto_alloc_size = sizeof(struct board_sandbox_priv),
+       .probe          = board_sandbox_probe,
+};
diff --git a/drivers/board/sandbox.h b/drivers/board/sandbox.h
new file mode 100644 (file)
index 0000000..2cff494
--- /dev/null
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2018
+ * Mario Six,  Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+enum {
+       BOOL_CALLED_DETECT,
+       INT_TEST1,
+       INT_TEST2,
+       STR_VACATIONSPOT,
+};
index 8b1ba915d017e6cf928d3cab8336945ff0bcc66a..d7f5d6b0616604459ab89ffd0f714f2acd29dfcd 100644 (file)
@@ -14,6 +14,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
 obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_BLK) += blk.o
+obj-$(CONFIG_BOARD) += board.o
 obj-$(CONFIG_CLK) += clk.o
 obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
diff --git a/test/dm/board.c b/test/dm/board.c
new file mode 100644 (file)
index 0000000..0f267a1
--- /dev/null
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <board.h>
+#include <test/ut.h>
+
+#include "../../drivers/board/sandbox.h"
+
+static int dm_test_board(struct unit_test_state *uts)
+{
+       struct udevice *board;
+       bool called_detect;
+       char str[64];
+       int i;
+
+       board_get(&board);
+       ut_assert(board);
+
+       board_get_bool(board, BOOL_CALLED_DETECT, &called_detect);
+       ut_assert(!called_detect);
+
+       board_detect(board);
+
+       board_get_bool(board, BOOL_CALLED_DETECT, &called_detect);
+       ut_assert(called_detect);
+
+       board_get_str(board, STR_VACATIONSPOT, sizeof(str), str);
+       ut_assertok(strcmp(str, "R'lyeh"));
+
+       board_get_int(board, INT_TEST1, &i);
+       ut_asserteq(0, i);
+
+       board_get_int(board, INT_TEST2, &i);
+       ut_asserteq(100, i);
+
+       board_get_str(board, STR_VACATIONSPOT, sizeof(str), str);
+       ut_assertok(strcmp(str, "Carcosa"));
+
+       board_get_int(board, INT_TEST1, &i);
+       ut_asserteq(1, i);
+
+       board_get_int(board, INT_TEST2, &i);
+       ut_asserteq(99, i);
+
+       board_get_str(board, STR_VACATIONSPOT, sizeof(str), str);
+       ut_assertok(strcmp(str, "Yuggoth"));
+
+       return 0;
+}
+
+DM_TEST(dm_test_board, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);