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 static void vcheck_search(void *fdt, const char *propname, const void *propval,
32 int proplen, va_list ap)
34 int offset = -1, target;
37 target = va_arg(ap, int);
38 verbose_printf("Searching (target = %d): %d ->",
40 offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
42 verbose_printf("%d\n", offset);
45 FAIL("fdt_node_offset_by_prop_value() returns %d "
46 "instead of %d", offset, target);
47 } while (target >= 0);
50 static void check_search(void *fdt, const char *propname, const void *propval,
55 va_start(ap, proplen);
56 vcheck_search(fdt, propname, propval, proplen, ap);
60 static void check_search_str(void *fdt, const char *propname,
61 const char *propval, ...)
65 va_start(ap, propval);
66 vcheck_search(fdt, propname, propval, strlen(propval)+1, ap);
70 #define check_search_cell(fdt, propname, propval, ...) \
72 uint32_t val = cpu_to_fdt32(propval); \
73 check_search((fdt), (propname), &val, sizeof(val), \
77 int main(int argc, char *argv[])
80 int subnode1_offset, subnode2_offset;
81 int subsubnode1_offset, subsubnode2_offset;
83 test_init(argc, argv);
84 fdt = load_blob_arg(argc, argv);
86 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
87 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
88 subsubnode1_offset = fdt_path_offset(fdt, "/subnode@1/subsubnode");
89 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
91 if ((subnode1_offset < 0) || (subnode2_offset < 0)
92 || (subsubnode1_offset < 0) || (subsubnode2_offset < 0))
93 FAIL("Can't find required nodes");
95 check_search_cell(fdt, "prop-int", TEST_VALUE_1, 0, subnode1_offset,
96 subsubnode1_offset, -FDT_ERR_NOTFOUND);
98 check_search_cell(fdt, "prop-int", TEST_VALUE_2, subnode2_offset,
99 subsubnode2_offset, -FDT_ERR_NOTFOUND);
101 check_search_str(fdt, "prop-str", TEST_STRING_1, 0, -FDT_ERR_NOTFOUND);
103 check_search_str(fdt, "prop-str", "no such string", -FDT_ERR_NOTFOUND);
105 check_search_cell(fdt, "prop-int", TEST_VALUE_1+1, -FDT_ERR_NOTFOUND);
107 check_search(fdt, "no-such-prop", NULL, 0, -FDT_ERR_NOTFOUND);