blob: 745de50c7bae19b91ee5b8563001170d72f827f7 [file] [log] [blame]
Masahiro Yamadab4f2dda2018-04-27 01:02:02 +09001// SPDX-License-Identifier: GPL-2.0+
2
3#include <common.h>
4#include <dm.h>
Simon Glass699c9ca2018-10-01 12:22:08 -06005#include <dm/of_extra.h>
Masahiro Yamadab4f2dda2018-04-27 01:02:02 +09006#include <dm/test.h>
7#include <test/ut.h>
8
9static int dm_test_ofnode_compatible(struct unit_test_state *uts)
10{
11 ofnode root_node = ofnode_path("/");
12
13 ut_assert(ofnode_valid(root_node));
14 ut_assert(ofnode_device_is_compatible(root_node, "sandbox"));
15
16 return 0;
17}
18DM_TEST(dm_test_ofnode_compatible, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Jens Wiklanderd9fd0ac2018-08-20 11:10:00 +020019
20static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts)
21{
22 const char propname[] = "compatible";
23 const char propval[] = "denx,u-boot-fdt-test";
24 const char *str;
25 ofnode node = ofnode_null();
26
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));
32
33 /* Find the rest of the matching nodes */
34 while (true) {
35 node = ofnode_by_prop_value(node, propname, propval,
36 sizeof(propval));
37 if (!ofnode_valid(node))
38 break;
39 str = ofnode_read_string(node, propname);
40 ut_assert(str && !strcmp(str, propval));
41 }
42
43 return 0;
44}
45DM_TEST(dm_test_ofnode_by_prop_value, DM_TESTF_SCAN_FDT);
Simon Glass699c9ca2018-10-01 12:22:08 -060046
47static int dm_test_ofnode_fmap(struct unit_test_state *uts)
48{
49 struct fmap_entry entry;
50 ofnode node;
51
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);
57
58 return 0;
59}
60DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);