2 * libfdt - Flat Device Tree manipulation
3 * Tests that fdt_next_subnode() works as expected
5 * Copyright (C) 2013 Google, Inc
7 * Copyright (C) 2007 David Gibson, IBM Corporation.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 static void test_node(void *fdt, int parent_offset)
42 /* This property indicates the number of subnodes to expect */
43 prop = fdt_getprop(fdt, parent_offset, "subnodes", &len);
44 if (!prop || len != sizeof(fdt32_t)) {
45 FAIL("Missing/invalid subnodes property at '%s'",
46 fdt_get_name(fdt, parent_offset, NULL));
48 subnodes = cpu_to_fdt32(*prop);
51 for (offset = fdt_first_subnode(fdt, parent_offset);
53 offset = fdt_next_subnode(fdt, offset))
56 if (count != subnodes) {
57 FAIL("Node '%s': Expected %d subnodes, got %d\n",
58 fdt_get_name(fdt, parent_offset, NULL), subnodes,
63 static void check_fdt_next_subnode(void *fdt)
68 for (offset = fdt_first_subnode(fdt, 0);
70 offset = fdt_next_subnode(fdt, offset)) {
71 test_node(fdt, offset);
76 FAIL("Expected %d tests, got %d\n", 2, count);
79 int main(int argc, char *argv[])
83 test_init(argc, argv);
85 CONFIG("Usage: %s <dtb file>", argv[0]);
87 fdt = load_blob(argv[1]);
89 FAIL("No device tree available");
91 check_fdt_next_subnode(fdt);