1 // SPDX-License-Identifier: GPL-2.0+
5 #include <dm/of_extra.h>
9 static int dm_test_ofnode_compatible(struct unit_test_state *uts)
11 ofnode root_node = ofnode_path("/");
13 ut_assert(ofnode_valid(root_node));
14 ut_assert(ofnode_device_is_compatible(root_node, "sandbox"));
18 DM_TEST(dm_test_ofnode_compatible, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
20 static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts)
22 const char propname[] = "compatible";
23 const char propval[] = "denx,u-boot-fdt-test";
25 ofnode node = ofnode_null();
27 /* Find first matching node, there should be at least one */
28 node = ofnode_by_prop_value(node, propname, propval, sizeof(propval));
29 ut_assert(ofnode_valid(node));
30 str = ofnode_read_string(node, propname);
31 ut_assert(str && !strcmp(str, propval));
33 /* Find the rest of the matching nodes */
35 node = ofnode_by_prop_value(node, propname, propval,
37 if (!ofnode_valid(node))
39 str = ofnode_read_string(node, propname);
40 ut_assert(str && !strcmp(str, propval));
45 DM_TEST(dm_test_ofnode_by_prop_value, DM_TESTF_SCAN_FDT);
47 static int dm_test_ofnode_fmap(struct unit_test_state *uts)
49 struct fmap_entry entry;
52 node = ofnode_path("/cros-ec/flash");
53 ut_assert(ofnode_valid(node));
54 ut_assertok(ofnode_read_fmap_entry(node, &entry));
55 ut_asserteq(0x08000000, entry.offset);
56 ut_asserteq(0x20000, entry.length);
60 DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
62 static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
67 str = ofnode_read_chosen_string("setting");
68 ut_assertnonnull(str);
69 ut_asserteq_str("sunrise ohoka", str);
70 ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting"));
72 node = ofnode_get_chosen_node("other-node");
73 ut_assert(ofnode_valid(node));
74 ut_asserteq_str("c-test@5", ofnode_get_name(node));
76 node = ofnode_get_chosen_node("setting");
77 ut_assert(!ofnode_valid(node));
81 DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);