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)
43 * This property indicates the number of properties in our
46 prop = fdt_getprop(fdt, parent_offset, "test-properties", &len);
47 if (!prop || len != sizeof(fdt32_t)) {
48 FAIL("Missing/invalid test-properties property at '%s'",
49 fdt_get_name(fdt, parent_offset, NULL));
51 properties = cpu_to_fdt32(*prop);
54 offset = fdt_first_subnode(fdt, parent_offset);
56 FAIL("Missing test node\n");
58 fdt_for_each_property_offset(property, fdt, offset)
61 if (count != properties) {
62 FAIL("Node '%s': Expected %d properties, got %d\n",
63 fdt_get_name(fdt, parent_offset, NULL), properties,
68 static void check_fdt_next_subnode(void *fdt)
73 fdt_for_each_subnode(offset, fdt, 0) {
74 test_node(fdt, offset);
79 FAIL("Expected %d tests, got %d\n", 2, count);
82 int main(int argc, char *argv[])
86 test_init(argc, argv);
88 CONFIG("Usage: %s <dtb file>", argv[0]);
90 fdt = load_blob(argv[1]);
92 FAIL("No device tree available");
94 check_fdt_next_subnode(fdt);