2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_parent_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
30 static int path_parent_len(const char *path)
32 const char *p = strrchr(path, '/');
42 static void check_path(struct fdt_header *fdt, const char *path)
45 int nodeoffset, parentoffset, parentpathoffset, pathparentlen;
47 pathparentlen = path_parent_len(path);
48 parentpath = alloca(pathparentlen + 1);
49 strncpy(parentpath, path, pathparentlen);
50 parentpath[pathparentlen] = '\0';
52 verbose_printf("Path: \"%s\"\tParent: \"%s\"\n", path, parentpath);
54 nodeoffset = fdt_path_offset(fdt, path);
56 FAIL("fdt_path_offset(%s): %s", path, fdt_strerror(nodeoffset));
58 parentpathoffset = fdt_path_offset(fdt, parentpath);
59 if (parentpathoffset < 0)
60 FAIL("fdt_path_offset(%s): %s", parentpath,
61 fdt_strerror(parentpathoffset));
63 parentoffset = fdt_parent_offset(fdt, nodeoffset);
65 FAIL("fdt_parent_offset(): %s", fdt_strerror(parentoffset));
67 if (parentoffset != parentpathoffset)
68 FAIL("fdt_parent_offset() returns %d instead of %d",
69 parentoffset, parentpathoffset);
72 int main(int argc, char *argv[])
77 test_init(argc, argv);
78 fdt = load_blob_arg(argc, argv);
80 check_path(fdt, "/subnode@1");
81 check_path(fdt, "/subnode@2");
82 check_path(fdt, "/subnode@1/subsubnode");
83 check_path(fdt, "/subnode@2/subsubnode@0");
84 err = fdt_parent_offset(fdt, 0);
85 if (err != -FDT_ERR_NOTFOUND)
86 FAIL("fdt_parent_offset(/) returns %d instead of "
87 "-FDT_ERR_NOTFOUND", err);