summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-03-02 04:08:29 +0100
committerSimon Glass <sjg@chromium.org>2023-03-09 08:50:48 -0800
commite2d7daa6c932646c25fadbf52ac68462de60e2f9 (patch)
tree654dd284f790a042eb7bbd3e9a29940be4e56c4c /test
parented14576b59c4e2e2d608ffddd30e272872adcd74 (diff)
test: cmd: fdt: Test both string and integer arrays in 'fdt get value'
The 'fdt get value' subcommand now supports extraction of integer value from integer arrays, add test for it, including a test for special case unindexed integer array read, which is handled as hash and treated as a long string instead of integer. 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.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index e04ba37f19..69a69c5c75 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -239,38 +239,64 @@ 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_string(struct unit_test_state *uts,
+ const char *node, const char *prop,
+ const char *idx, const char *strres,
+ const int intres)
+{
+ ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("fdt get value var %s %s %s",
+ node, prop, idx ? : ""));
+ if (strres) {
+ ut_asserteq_str(strres, env_get("var"));
+ } else {
+ ut_asserteq(intres, env_get_hex("var", 0x1234));
+ }
+ ut_assertok(ut_check_console_end(uts));
+
+ return 0;
+}
+
static int fdt_test_get_value_common(struct unit_test_state *uts,
const char *node)
{
/* Test getting default element of $node node clock-names property */
- ut_assertok(console_record_reset_enable());
- 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));
+ fdt_test_get_value_string(uts, node, "clock-names", NULL, "fixed", 0);
/* Test getting 0th element of $node node clock-names property */
- ut_assertok(console_record_reset_enable());
- 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));
+ fdt_test_get_value_string(uts, node, "clock-names", "0", "fixed", 0);
/* Test getting 1st element of $node node clock-names property */
- ut_assertok(console_record_reset_enable());
- 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));
+ fdt_test_get_value_string(uts, node, "clock-names", "1", "i2c", 0);
/* Test getting 2nd element of $node node clock-names property */
- ut_assertok(console_record_reset_enable());
- 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));
+ fdt_test_get_value_string(uts, node, "clock-names", "2", "spi", 0);
+
+ /*
+ * Test getting default element of $node node regs property.
+ * The result here is highly unusual, the non-index value read from
+ * integer array is a string of concatenated values from the array,
+ * but only if the array is shorter than 40 characters. Anything
+ * longer is an error. This is a special case for handling hashes.
+ */
+ fdt_test_get_value_string(uts, node, "regs", NULL, "3412000000100000", 0);
+
+ /* Test getting 0th element of $node node regs property */
+ fdt_test_get_value_string(uts, node, "regs", "0", NULL, 0x1234);
+
+ /* Test getting 1st element of $node node regs property */
+ fdt_test_get_value_string(uts, node, "regs", "1", NULL, 0x1000);
/* Test missing 10th element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", node));
ut_assertok(ut_check_console_end(uts));
+ /* Test missing 10th element of $node node regs property */
+ ut_assertok(console_record_reset_enable());
+ ut_asserteq(1, run_commandf("fdt get value ften %s regs 10", node));
+ ut_assertok(ut_check_console_end(uts));
+
/* Test getting default element of $node node nonexistent property */
ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", node));