2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_node_offset_by_compatible()
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 check_search(void *fdt, const char *compat, ...)
34 int offset = -1, target;
38 target = va_arg(ap, int);
39 verbose_printf("Searching (target = %d): %d ->",
41 offset = fdt_node_offset_by_compatible(fdt, offset, compat);
42 verbose_printf("%d\n", offset);
45 FAIL("fdt_node_offset_by_compatible(%s) returns %d "
46 "instead of %d", compat, offset, target);
47 } while (target >= 0);
52 int main(int argc, char *argv[])
55 int subnode1_offset, subnode2_offset;
56 int subsubnode1_offset, subsubnode2_offset;
58 test_init(argc, argv);
59 fdt = load_blob_arg(argc, argv);
61 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
62 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
63 subsubnode1_offset = fdt_path_offset(fdt, "/subnode@1/subsubnode");
64 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
66 if ((subnode1_offset < 0) || (subnode2_offset < 0)
67 || (subsubnode1_offset < 0) || (subsubnode2_offset < 0))
68 FAIL("Can't find required nodes");
70 check_search(fdt, "test_tree1", 0, -FDT_ERR_NOTFOUND);
71 check_search(fdt, "subnode1", subnode1_offset, -FDT_ERR_NOTFOUND);
72 check_search(fdt, "subsubnode1", subsubnode1_offset, -FDT_ERR_NOTFOUND);
73 check_search(fdt, "subsubnode2", subsubnode2_offset, -FDT_ERR_NOTFOUND);
74 /* Eek.. HACK to make this work whatever the order in the
76 if (subsubnode1_offset < subsubnode2_offset)
77 check_search(fdt, "subsubnode", subsubnode1_offset,
78 subsubnode2_offset, -FDT_ERR_NOTFOUND);
80 check_search(fdt, "subsubnode", subsubnode2_offset,
81 subsubnode1_offset, -FDT_ERR_NOTFOUND);
82 check_search(fdt, "nothing-like-this", -FDT_ERR_NOTFOUND);