aboutsummaryrefslogtreecommitdiff
path: root/test/dm/ofnode.c
diff options
context:
space:
mode:
authorSimon Glass2020-01-27 08:49:44 -0700
committerSimon Glass2020-02-05 19:33:45 -0700
commita8167d8ee2305f688d970f7ea4c38d7ca9b205ca (patch)
tree758aba45e1a725e5933aa5f9684413bf70f57e40 /test/dm/ofnode.c
parent14ca9f7f5abf7b94d71cfd466fb339bf64f58bda (diff)
dm: core: Add ofnode_read_prop()
Add a new function to read a property that supports reading the length as well. Reimplement ofnode_read_string() using it and fix its comment. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/dm/ofnode.c')
-rw-r--r--test/dm/ofnode.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 633a3a9e9ad..f1e4ed75db0 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -59,6 +59,32 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts)
}
DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+static int dm_test_ofnode_read(struct unit_test_state *uts)
+{
+ const u32 *val;
+ ofnode node;
+ int size;
+
+ node = ofnode_path("/a-test");
+ ut_assert(ofnode_valid(node));
+
+ val = ofnode_read_prop(node, "int-value", &size);
+ ut_assertnonnull(val);
+ ut_asserteq(4, size);
+ ut_asserteq(1234, fdt32_to_cpu(val[0]));
+
+ val = ofnode_read_prop(node, "missing", &size);
+ ut_assertnull(val);
+ ut_asserteq(-FDT_ERR_NOTFOUND, size);
+
+ /* Check it works without a size parameter */
+ val = ofnode_read_prop(node, "missing", NULL);
+ ut_assertnull(val);
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
{
const char *str;