[PATCH v2 24/32] test: cmd: fdt: Test fdt mknode

Marek Vasut marek.vasut+renesas at mailbox.org
Thu Mar 2 04:08:37 CET 2023


Add 'fdt mknode' test which works as follows:
- Create fuller FDT, map it to sysmem
- Create node either in / or subnode
- Attempt to create node over existing node, which fails
- Attempt to create subnodes in non-existing nodes or aliases
- Verify created nodes using fdt list command

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
Cc: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tom Rini <trini at konsulko.com>
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 64d04f2f2ed..5e395e23fed 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -922,6 +922,74 @@ static int fdt_test_set(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_set, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_mknode(struct unit_test_state *uts)
+{
+	char fdt[8192];
+	ulong addr;
+
+	ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+	fdt_shrink_to_minimum(fdt, 4096);	/* Resize with 4096 extra bytes */
+	addr = map_to_sysmem(fdt);
+	set_working_fdt_addr(addr);
+
+	/* Test creation of new node in / */
+	ut_assertok(console_record_reset_enable());
+	ut_assertok(run_commandf("fdt mknode / newnode"));
+	ut_assertok(run_commandf("fdt list /newnode"));
+	ut_assert_nextline("newnode {");
+	ut_assert_nextline("};");
+	ut_assertok(ut_check_console_end(uts));
+
+	/* Test creation of new node in /test-node at 1234 */
+	ut_assertok(console_record_reset_enable());
+	ut_assertok(run_commandf("fdt mknode /test-node at 1234 newsubnode"));
+	ut_assertok(run_commandf("fdt list /test-node at 1234/newsubnode"));
+	ut_assert_nextline("newsubnode {");
+	ut_assert_nextline("};");
+	ut_assertok(ut_check_console_end(uts));
+
+	/* Test creation of new node in /test-node at 1234 by alias */
+	ut_assertok(console_record_reset_enable());
+	ut_assertok(run_commandf("fdt mknode testnodealias newersubnode"));
+	ut_assertok(run_commandf("fdt list testnodealias/newersubnode"));
+	ut_assert_nextline("newersubnode {");
+	ut_assert_nextline("};");
+	ut_assertok(ut_check_console_end(uts));
+
+	/* Test creation of new node in /test-node at 1234 over existing node */
+	ut_assertok(console_record_reset_enable());
+	ut_asserteq(1, run_commandf("fdt mknode testnodealias newsubnode"));
+	ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS");
+	ut_assertok(ut_check_console_end(uts));
+
+	/* Test creation of new node in /test-node at 1234 by alias over existing node */
+	ut_assertok(console_record_reset_enable());
+	ut_asserteq(1, run_commandf("fdt mknode testnodealias newersubnode"));
+	ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS");
+	ut_assertok(ut_check_console_end(uts));
+
+	/* Test creation of new node in non-existent node */
+	ut_assertok(console_record_reset_enable());
+	ut_asserteq(1, run_commandf("fdt mknode /no-node newnosubnode"));
+	ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
+	ut_assertok(ut_check_console_end(uts));
+
+	/* Test creation of new node in non-existent alias */
+	ut_assertok(console_record_reset_enable());
+	ut_asserteq(1, run_commandf("fdt mknode noalias newfailsubnode"));
+	ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
+	ut_assertok(ut_check_console_end(uts));
+
+	/* Test creation of new node in bad alias */
+	ut_assertok(console_record_reset_enable());
+	ut_asserteq(1, run_commandf("fdt mknode badalias newbadsubnode"));
+	ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
+	ut_assertok(ut_check_console_end(uts));
+
+	return 0;
+}
+FDT_TEST(fdt_test_mknode, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



More information about the U-Boot mailing list