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
32
void check_search(void *fdt, const char *compat, ...)
35
int offset = -1, target;
39
target = va_arg(ap, int);
40
verbose_printf("Searching (target = %d): %d ->",
42
offset = fdt_node_offset_by_compatible(fdt, offset, compat);
43
verbose_printf("%d\n", offset);
46
FAIL("fdt_node_offset_by_compatible(%s) returns %d "
47
"instead of %d", compat, offset, target);
48
} while (target >= 0);
53
int main(int argc, char *argv[])
56
int subnode1_offset, subnode2_offset;
57
int subsubnode1_offset, subsubnode2_offset;
59
test_init(argc, argv);
60
fdt = load_blob_arg(argc, argv);
62
subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
63
subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
64
subsubnode1_offset = fdt_path_offset(fdt, "/subnode@1/subsubnode");
65
subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
67
if ((subnode1_offset < 0) || (subnode2_offset < 0)
68
|| (subsubnode1_offset < 0) || (subsubnode2_offset < 0))
69
FAIL("Can't find required nodes");
71
check_search(fdt, "test_tree1", 0, -FDT_ERR_NOTFOUND);
72
check_search(fdt, "subnode1", subnode1_offset, -FDT_ERR_NOTFOUND);
73
check_search(fdt, "subsubnode1", subsubnode1_offset, -FDT_ERR_NOTFOUND);
74
check_search(fdt, "subsubnode2", subsubnode2_offset, -FDT_ERR_NOTFOUND);
75
/* Eek.. HACK to make this work whatever the order in the
77
if (subsubnode1_offset < subsubnode2_offset)
78
check_search(fdt, "subsubnode", subsubnode1_offset,
79
subsubnode2_offset, -FDT_ERR_NOTFOUND);
81
check_search(fdt, "subsubnode", subsubnode2_offset,
82
subsubnode1_offset, -FDT_ERR_NOTFOUND);
83
check_search(fdt, "nothing-like-this", -FDT_ERR_NOTFOUND);