2
* libfdt - Flat Device Tree manipulation
3
* Testcase for fdt_path_offset()
4
* Copyright (C) 2006 David Gibson, IBM Corporation.
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public License
8
* as published by the Free Software Foundation; either version 2.1 of
9
* the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
int check_subnode(void *fdt, int parent, const char *name)
34
const struct fdt_node_header *nh;
37
verbose_printf("Checking subnode \"%s\" of %d...", name, parent);
38
offset = fdt_subnode_offset(fdt, parent, name);
39
verbose_printf("offset %d...", offset);
41
FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(offset));
42
nh = fdt_offset_ptr(fdt, offset, sizeof(*nh));
43
verbose_printf("pointer %p\n", nh);
45
FAIL("NULL retrieving subnode \"%s\"", name);
47
tag = fdt32_to_cpu(nh->tag);
49
if (tag != FDT_BEGIN_NODE)
50
FAIL("Incorrect tag 0x%08x on property \"%s\"", tag, name);
51
if (!nodename_eq(nh->name, name))
52
FAIL("Subnode name mismatch \"%s\" instead of \"%s\"",
58
int main(int argc, char *argv[])
62
int subnode1_offset, subnode2_offset;
63
int subnode1_offset_p, subnode2_offset_p;
64
int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2;
65
int subsubnode1_offset_p, subsubnode2_offset_p, subsubnode2_offset2_p;
67
test_init(argc, argv);
68
fdt = load_blob_arg(argc, argv);
70
root_offset = fdt_path_offset(fdt, "/");
72
FAIL("fdt_path_offset(\"/\") failed: %s",
73
fdt_strerror(root_offset));
74
else if (root_offset != 0)
75
FAIL("fdt_path_offset(\"/\") returns incorrect offset %d",
77
subnode1_offset = check_subnode(fdt, 0, "subnode@1");
78
subnode2_offset = check_subnode(fdt, 0, "subnode@2");
80
subnode1_offset_p = fdt_path_offset(fdt, "/subnode@1");
81
subnode2_offset_p = fdt_path_offset(fdt, "/subnode@2");
83
if (subnode1_offset != subnode1_offset_p)
84
FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
85
subnode1_offset, subnode1_offset_p);
87
if (subnode2_offset != subnode2_offset_p)
88
FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
89
subnode2_offset, subnode2_offset_p);
91
subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode");
92
subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0");
93
subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode");
95
subsubnode1_offset_p = fdt_path_offset(fdt, "/subnode@1/subsubnode");
96
subsubnode2_offset_p = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
97
subsubnode2_offset2_p = fdt_path_offset(fdt, "/subnode@2/subsubnode");
99
if (subsubnode1_offset != subsubnode1_offset_p)
100
FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
101
subsubnode1_offset, subsubnode1_offset_p);
103
if (subsubnode2_offset != subsubnode2_offset_p)
104
FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
105
subsubnode2_offset, subsubnode2_offset_p);