summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-03-02 04:08:37 +0100
committerSimon Glass <sjg@chromium.org>2023-03-08 13:14:29 -0800
commit6c28594bf6472ec693336be23ac041a4eae47df9 (patch)
treea5c925f632cac0e5d8d6c3d7eb0d80aeaf6a548d /test
parent8bd49a87d912b585bade35e96afd29634dab605f (diff)
downloadu-boot-6c28594bf6472ec693336be23ac041a4eae47df9.tar.gz
test: cmd: fdt: Test fdt mknode
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@mailbox.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/cmd/fdt.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index dabd35fbb5..4d45afaa29 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -779,6 +779,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@1234 */
+ ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("fdt mknode /test-node@1234 newsubnode"));
+ ut_assertok(run_commandf("fdt list /test-node@1234/newsubnode"));
+ ut_assert_nextline("newsubnode {");
+ ut_assert_nextline("};");
+ ut_assertok(ut_check_console_end(uts));
+
+ /* Test creation of new node in /test-node@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@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@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);