[PATCH 15/32] test: cmd: fdt: Test alias resolution in 'fdt get value'
Marek Vasut
marek.vasut+renesas at mailbox.org
Mon Feb 27 20:53:40 CET 2023
The 'fdt' command help contains the following note:
"
Dereference aliases by omitting the leading '/', e.g. fdt print ethernet0.
"
Add test for it.
Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tom Rini <trini at konsulko.com>
---
test/cmd/fdt.c | 65 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 45 insertions(+), 20 deletions(-)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 21553a2f3dc..e04ba37f19f 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -239,56 +239,81 @@ static int fdt_test_addr_resize(struct unit_test_state *uts)
FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
/* Test 'fdt get value' reading an fdt */
-static int fdt_test_get_value(struct unit_test_state *uts)
+static int fdt_test_get_value_common(struct unit_test_state *uts,
+ const char *node)
{
- char fdt[4096];
- ulong addr;
-
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
-
- /* Test getting default element of /test-node at 1234 node clock-names property */
+ /* Test getting default element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
- ut_assertok(run_command("fdt get value fdflt /test-node at 1234 clock-names", 0));
+ ut_assertok(run_commandf("fdt get value fdflt %s clock-names", node));
ut_asserteq_str("fixed", env_get("fdflt"));
ut_assertok(ut_check_console_end(uts));
- /* Test getting 0th element of /test-node at 1234 node clock-names property */
+ /* Test getting 0th element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
- ut_assertok(run_command("fdt get value fzero /test-node at 1234 clock-names 0", 0));
+ ut_assertok(run_commandf("fdt get value fzero %s clock-names 0", node));
ut_asserteq_str("fixed", env_get("fzero"));
ut_assertok(ut_check_console_end(uts));
- /* Test getting 1st element of /test-node at 1234 node clock-names property */
+ /* Test getting 1st element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
- ut_assertok(run_command("fdt get value fone /test-node at 1234 clock-names 1", 0));
+ ut_assertok(run_commandf("fdt get value fone %s clock-names 1", node));
ut_asserteq_str("i2c", env_get("fone"));
ut_assertok(ut_check_console_end(uts));
- /* Test getting 2nd element of /test-node at 1234 node clock-names property */
+ /* Test getting 2nd element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
- ut_assertok(run_command("fdt get value ftwo /test-node at 1234 clock-names 2", 0));
+ ut_assertok(run_commandf("fdt get value ftwo %s clock-names 2", node));
ut_asserteq_str("spi", env_get("ftwo"));
ut_assertok(ut_check_console_end(uts));
- /* Test missing 10th element of /test-node at 1234 node clock-names property */
+ /* Test missing 10th element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
- ut_asserteq(1, run_command("fdt get value ften /test-node at 1234 clock-names 10", 0));
+ ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", node));
ut_assertok(ut_check_console_end(uts));
- /* Test getting default element of /test-node at 1234 node nonexistent property */
+ /* Test getting default element of $node node nonexistent property */
ut_assertok(console_record_reset_enable());
- ut_asserteq(1, run_command("fdt get value fnone /test-node at 1234 nonexistent", 1));
+ ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", node));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
ut_assertok(ut_check_console_end(uts));
+ return 0;
+}
+
+static int fdt_test_get_value(struct unit_test_state *uts)
+{
+ char fdt[4096];
+ ulong addr;
+ int ret;
+
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+ addr = map_to_sysmem(fdt);
+ set_working_fdt_addr(addr);
+
+ ret = fdt_test_get_value_common(uts, "/test-node at 1234");
+ if (!ret)
+ ret = fdt_test_get_value_common(uts, "testnodealias");
+ if (ret)
+ return ret;
+
/* Test getting default element of /nonexistent node */
ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get value fnode /nonexistent nonexistent", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
ut_assertok(ut_check_console_end(uts));
+ /* Test getting default element of bad alias */
+ ut_assertok(console_record_reset_enable());
+ ut_asserteq(1, run_command("fdt get value vbadalias badalias nonexistent", 1));
+ ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
+ ut_assertok(ut_check_console_end(uts));
+
+ /* Test getting default element of nonexistent alias */
+ ut_assertok(console_record_reset_enable());
+ ut_asserteq(1, run_command("fdt get value vnoalias noalias nonexistent", 1));
+ ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
+ ut_assertok(ut_check_console_end(uts));
+
return 0;
}
FDT_TEST(fdt_test_get_value, UT_TESTF_CONSOLE_REC);
--
2.39.2
More information about the U-Boot
mailing list