[PATCH 4/4] test: bdinfo: Add test for command bdinfo

Marek Vasut marek.vasut+renesas at mailbox.org
Sat Apr 22 15:01:34 CEST 2023


Add test for command bdinfo .

Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: Jason Liu <jason.hui.liu at nxp.com>
Cc: Michal Simek <michal.simek at amd.com>
Cc: Ovidiu Panait <ovpanait at gmail.com>
Cc: Simon Glass <sjg at chromium.org>
---
 include/test/suites.h |   1 +
 test/cmd/Makefile     |   1 +
 test/cmd/bdinfo.c     | 179 ++++++++++++++++++++++++++++++++++++++++++
 test/cmd_ut.c         |   6 ++
 4 files changed, 187 insertions(+)
 create mode 100644 test/cmd/bdinfo.c

diff --git a/include/test/suites.h b/include/test/suites.h
index 7349ce5aa60..1c7dc65966a 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -28,6 +28,7 @@ int cmd_ut_category(const char *name, const char *prefix,
 
 int do_ut_addrmap(struct cmd_tbl *cmdtp, int flag, int argc,
 		  char *const argv[]);
+int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_bootstd(struct cmd_tbl *cmdtp, int flag, int argc,
 		  char *const argv[]);
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 055adc65a25..a3cf983739e 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_CMD_PAUSE) += test_pause.o
 endif
 obj-y += exit.o mem.o
 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
+obj-$(CONFIG_CMD_BDI) += bdinfo.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
 obj-$(CONFIG_CMD_LOADM) += loadm.o
diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
new file mode 100644
index 00000000000..2968955d8b2
--- /dev/null
+++ b/test/cmd/bdinfo.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for bdinfo command
+ *
+ * Copyright 2023 Marek Vasut <marek.vasut+renesas at mailbox.org>
+ */
+
+#include <common.h>
+#include <console.h>
+#include <mapmem.h>
+#include <asm/global_data.h>
+#include <dm/uclass.h>
+#include <test/suites.h>
+#include <test/ut.h>
+#include <dm.h>
+#include <env.h>
+#include <lmb.h>
+#include <net.h>
+#include <video.h>
+#include <vsprintf.h>
+#include <asm/cache.h>
+#include <asm/global_data.h>
+#include <display_options.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Declare a new bdinfo test */
+#define BDINFO_TEST(_name, _flags)	UNIT_TEST(_name, _flags, bdinfo_test)
+
+static void bdinfo_test_num_l(struct unit_test_state *uts,
+			      const char *name, ulong value)
+{
+	ut_assert_nextline("%-12s= 0x%0*lx", name, 2 * (int)sizeof(value), value);
+}
+
+static void bdinfo_test_num_ll(struct unit_test_state *uts,
+			       const char *name, unsigned long long value)
+{
+	ut_assert_nextline("%-12s= 0x%.*llx", name, 2 * (int)sizeof(ulong), value);
+}
+
+static void test_eth(struct unit_test_state *uts)
+{
+	const int idx = eth_get_dev_index();
+	uchar enetaddr[6];
+	char name[10];
+	int ret;
+
+	if (idx)
+		sprintf(name, "eth%iaddr", idx);
+	else
+		strcpy(name, "ethaddr");
+
+	ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr);
+
+	ut_assert_nextline("current eth = %s", eth_get_name());
+	if (!ret)
+		ut_assert_nextline("%-12s= (not set)", name);
+	else
+		ut_assert_nextline("%-12s= %pM", name, enetaddr);
+	ut_assert_nextline("IP addr     = %s", env_get("ipaddr"));
+}
+
+static void test_video_info(struct unit_test_state *uts)
+{
+	const struct udevice *dev;
+	struct uclass *uc;
+
+	uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) {
+		ut_assert_nextline("%-12s= %s %sactive", "Video", dev->name,
+				   device_active(dev) ? "" : "in");
+		if (device_active(dev)) {
+			struct video_priv *upriv = dev_get_uclass_priv(dev);
+			struct video_uc_plat *plat = dev_get_uclass_plat(dev);
+
+			bdinfo_test_num_ll(uts, "FB base", (ulong)upriv->fb);
+			if (upriv->copy_fb) {
+				bdinfo_test_num_ll(uts, "FB copy",
+						   (ulong)upriv->copy_fb);
+				bdinfo_test_num_l(uts, " copy size",
+						  plat->copy_size);
+			}
+			ut_assert_nextline("%-12s= %dx%dx%d", "FB size",
+					   upriv->xsize, upriv->ysize,
+					   1 << upriv->bpix);
+		}
+	}
+}
+
+static void lmb_test_dump_region(struct unit_test_state *uts,
+				 struct lmb_region *rgn, char *name)
+{
+	unsigned long long base, size, end;
+	enum lmb_flags flags;
+	int i;
+
+	ut_assert_nextline(" %s.cnt = 0x%lx / max = 0x%lx", name, rgn->cnt, rgn->max);
+
+	for (i = 0; i < rgn->cnt; i++) {
+		base = rgn->region[i].base;
+		size = rgn->region[i].size;
+		end = base + size - 1;
+		flags = rgn->region[i].flags;
+
+		ut_assert_nextline(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x",
+				   name, i, base, end, size, flags);
+	}
+}
+
+static void lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb)
+{
+	ut_assert_nextline("lmb_dump_all:");
+	lmb_test_dump_region(uts, &lmb->memory, "memory");
+	lmb_test_dump_region(uts, &lmb->reserved, "reserved");
+}
+
+static int bdinfo_test_move(struct unit_test_state *uts)
+{
+	/* Test moving the working BDINFO to a new location */
+	ut_assertok(console_record_reset_enable());
+	ut_assertok(run_commandf("bdinfo"));
+
+	bdinfo_test_num_l(uts, "boot_params", 0);
+	bdinfo_test_num_l(uts, "DRAM bank",  0);
+	bdinfo_test_num_ll(uts, "-> start", CFG_SYS_SDRAM_BASE);
+	bdinfo_test_num_ll(uts, "-> size", CFG_SYS_SDRAM_SIZE);
+	/* CONFIG_SYS_HAS_SRAM testing not supported */
+	bdinfo_test_num_l(uts, "flashstart", 0);
+	bdinfo_test_num_l(uts, "flashsize", 0);
+	bdinfo_test_num_l(uts, "flashoffset", 0);
+	ut_assert_nextline("baudrate    = %lu bps",
+			   env_get_ulong("baudrate", 10, 1234));
+	bdinfo_test_num_l(uts, "relocaddr", gd->relocaddr);
+	bdinfo_test_num_l(uts, "reloc off", gd->reloc_off);
+	ut_assert_nextline("%-12s= %u-bit", "Build", (uint)sizeof(void *) * 8);
+
+	if (IS_ENABLED(CONFIG_CMD_NET))
+		test_eth(uts);
+
+	/*
+	 * Make sure environment variable "fdtcontroladdr" address
+	 * matches mapped control DT address.
+	 */
+	ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234));
+	bdinfo_test_num_l(uts, "fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob));
+	bdinfo_test_num_l(uts, "new_fdt", (ulong)map_to_sysmem(gd->new_fdt));
+	bdinfo_test_num_l(uts, "fdt_size", (ulong)gd->fdt_size);
+
+	if (IS_ENABLED(CONFIG_VIDEO))
+		test_video_info(uts);
+
+	/* The gd->multi_dtb_fit may not be available, hence, #if below. */
+#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
+	bdinfo_test_num_l(uts, "multi_dtb_fit", (ulong)gd->multi_dtb_fit);
+#endif
+
+	if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) {
+		struct lmb lmb;
+
+		lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
+		lmb_test_dump_all(uts, &lmb);
+		if (IS_ENABLED(CONFIG_OF_REAL))
+			ut_assert_nextline("devicetree  = %s", fdtdec_get_srcname());
+	}
+
+	ut_assertok(ut_check_console_end(uts));
+
+	return 0;
+}
+
+BDINFO_TEST(bdinfo_test_move, UT_TESTF_CONSOLE_REC);
+
+int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test);
+	const int n_ents = UNIT_TEST_SUITE_COUNT(bdinfo_test);
+
+	return cmd_ut_category("bdinfo", "bdinfo_test_", tests, n_ents, argc, argv);
+}
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index d440da833a9..0cb514490b9 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -54,6 +54,9 @@ int cmd_ut_category(const char *name, const char *prefix,
 static struct cmd_tbl cmd_ut_sub[] = {
 	U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
 	U_BOOT_CMD_MKENT(info, 1, 1, do_ut_info, "", ""),
+#ifdef CONFIG_CMD_BDI
+	U_BOOT_CMD_MKENT(bdinfo, CONFIG_SYS_MAXARGS, 1, do_ut_bdinfo, "", ""),
+#endif
 #ifdef CONFIG_BOOTSTD
 	U_BOOT_CMD_MKENT(bootstd, CONFIG_SYS_MAXARGS, 1, do_ut_bootstd,
 			 "", ""),
@@ -176,6 +179,9 @@ static char ut_help_text[] =
 #ifdef CONFIG_CMD_ADDRMAP
 	"\naddrmap - very basic test of addrmap command"
 #endif
+#ifdef CONFIG_CMD_BDI
+	"\nbdinfo - bdinfo command"
+#endif
 #ifdef CONFIG_SANDBOX
 	"\nbloblist - bloblist implementation"
 #endif
-- 
2.39.2



More information about the U-Boot mailing list