summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-03-02 04:08:28 +0100
committerSimon Glass <sjg@chromium.org>2023-03-08 11:40:57 -0800
commit39e072701ce1a989afe84a170a868c0bcc977efe (patch)
treec572e550b5aaddaf78e942e2acbc7fed75d3e8e5
parentd6729765ffd2c82bb030bb231c7756dbfc8cf3aa (diff)
downloadu-boot-39e072701ce1a989afe84a170a868c0bcc977efe.tar.gz
u-boot-39e072701ce1a989afe84a170a868c0bcc977efe.tar.bz2
u-boot-39e072701ce1a989afe84a170a868c0bcc977efe.zip
test: cmd: fdt: Test alias resolution in 'fdt get value'
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@mailbox.org> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--test/cmd/fdt.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 21553a2f3d..e04ba37f19 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@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@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@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@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@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@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@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@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@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@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@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@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@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);