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
30 static int check_subnode(void *fdt, int parent, const char *name)
33 const struct fdt_node_header *nh;
36 verbose_printf("Checking subnode \"%s\" of %d...", name, parent);
37 offset = fdt_subnode_offset(fdt, parent, name);
38 verbose_printf("offset %d...", offset);
40 FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(offset));
41 nh = fdt_offset_ptr(fdt, offset, sizeof(*nh));
42 verbose_printf("pointer %p\n", nh);
44 FAIL("NULL retrieving subnode \"%s\"", name);
46 tag = fdt32_to_cpu(nh->tag);
48 if (tag != FDT_BEGIN_NODE)
49 FAIL("Incorrect tag 0x%08x on property \"%s\"", tag, name);
50 if (!nodename_eq(nh->name, name))
51 FAIL("Subnode name mismatch \"%s\" instead of \"%s\"",
57 int main(int argc, char *argv[])
61 int subnode1_offset, subnode2_offset;
62 int subnode1_offset_p, subnode2_offset_p;
63 int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2;
64 int subsubnode1_offset_p, subsubnode2_offset_p, subsubnode2_offset2_p;
66 test_init(argc, argv);
67 fdt = load_blob_arg(argc, argv);
69 root_offset = fdt_path_offset(fdt, "/");
71 FAIL("fdt_path_offset(\"/\") failed: %s",
72 fdt_strerror(root_offset));
73 else if (root_offset != 0)
74 FAIL("fdt_path_offset(\"/\") returns incorrect offset %d",
76 subnode1_offset = check_subnode(fdt, 0, "subnode@1");
77 subnode2_offset = check_subnode(fdt, 0, "subnode@2");
79 subnode1_offset_p = fdt_path_offset(fdt, "/subnode@1");
80 subnode2_offset_p = fdt_path_offset(fdt, "/subnode@2");
82 if (subnode1_offset != subnode1_offset_p)
83 FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
84 subnode1_offset, subnode1_offset_p);
86 if (subnode2_offset != subnode2_offset_p)
87 FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
88 subnode2_offset, subnode2_offset_p);
90 subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode");
91 subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0");
92 subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode");
94 subsubnode1_offset_p = fdt_path_offset(fdt, "/subnode@1/subsubnode");
95 subsubnode2_offset_p = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
96 subsubnode2_offset2_p = fdt_path_offset(fdt, "/subnode@2/subsubnode");
98 if (subsubnode1_offset != subsubnode1_offset_p)
99 FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
100 subsubnode1_offset, subsubnode1_offset_p);
102 if (subsubnode2_offset != subsubnode2_offset_p)
103 FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
104 subsubnode2_offset, subsubnode2_offset_p);
106 if (subsubnode2_offset2 != subsubnode2_offset2_p)
107 FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
108 subsubnode2_offset2, subsubnode2_offset2_p);