1 // SPDX-License-Identifier: GPL-2.0+
6 #include <dm/of_extra.h>
10 static int dm_test_ofnode_compatible(struct unit_test_state *uts)
12 ofnode root_node = ofnode_path("/");
14 ut_assert(ofnode_valid(root_node));
15 ut_assert(ofnode_device_is_compatible(root_node, "sandbox"));
19 DM_TEST(dm_test_ofnode_compatible, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
21 static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts)
23 const char propname[] = "compatible";
24 const char propval[] = "denx,u-boot-fdt-test";
26 ofnode node = ofnode_null();
28 /* Find first matching node, there should be at least one */
29 node = ofnode_by_prop_value(node, propname, propval, sizeof(propval));
30 ut_assert(ofnode_valid(node));
31 str = ofnode_read_string(node, propname);
32 ut_assert(str && !strcmp(str, propval));
34 /* Find the rest of the matching nodes */
36 node = ofnode_by_prop_value(node, propname, propval,
38 if (!ofnode_valid(node))
40 str = ofnode_read_string(node, propname);
41 ut_assert(str && !strcmp(str, propval));
46 DM_TEST(dm_test_ofnode_by_prop_value, DM_TESTF_SCAN_FDT);
48 static int dm_test_ofnode_fmap(struct unit_test_state *uts)
50 struct fmap_entry entry;
53 node = ofnode_path("/cros-ec/flash");
54 ut_assert(ofnode_valid(node));
55 ut_assertok(ofnode_read_fmap_entry(node, &entry));
56 ut_asserteq(0x08000000, entry.offset);
57 ut_asserteq(0x20000, entry.length);
61 DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
63 static int dm_test_ofnode_read(struct unit_test_state *uts)
69 node = ofnode_path("/a-test");
70 ut_assert(ofnode_valid(node));
72 val = ofnode_read_prop(node, "int-value", &size);
73 ut_assertnonnull(val);
75 ut_asserteq(1234, fdt32_to_cpu(val[0]));
77 val = ofnode_read_prop(node, "missing", &size);
79 ut_asserteq(-FDT_ERR_NOTFOUND, size);
81 /* Check it works without a size parameter */
82 val = ofnode_read_prop(node, "missing", NULL);
87 DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
89 static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
96 str = ofnode_read_chosen_string("setting");
97 ut_assertnonnull(str);
98 ut_asserteq_str("sunrise ohoka", str);
99 ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting"));
101 node = ofnode_get_chosen_node("other-node");
102 ut_assert(ofnode_valid(node));
103 ut_asserteq_str("c-test@5", ofnode_get_name(node));
105 node = ofnode_get_chosen_node("setting");
106 ut_assert(!ofnode_valid(node));
108 val = ofnode_read_chosen_prop("int-values", &size);
109 ut_assertnonnull(val);
110 ut_asserteq(8, size);
111 ut_asserteq(0x1937, fdt32_to_cpu(val[0]));
112 ut_asserteq(72993, fdt32_to_cpu(val[1]));
116 DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
118 static int dm_test_ofnode_get_child_count(struct unit_test_state *uts)
120 ofnode node, child_node;
123 node = ofnode_path("/i-test");
124 ut_assert(ofnode_valid(node));
126 val = ofnode_get_child_count(node);
129 child_node = ofnode_first_subnode(node);
130 ut_assert(ofnode_valid(child_node));
131 val = ofnode_get_child_count(child_node);
136 DM_TEST(dm_test_ofnode_get_child_count,
137 DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);