2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_get_path()
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 #define POISON ('\xff')
32 static void check_path_buf(void *fdt, const char *path, int pathlen, int buflen)
38 offset = fdt_path_offset(fdt, path);
40 FAIL("Couldn't find path \"%s\": %s", path, fdt_strerror(offset));
42 memset(buf, POISON, sizeof(buf)); /* poison the buffer */
44 len = fdt_get_path(fdt, offset, buf, buflen);
45 verbose_printf("get_path() %s -> %d -> %s\n", path, offset, buf);
47 if (buflen <= pathlen) {
48 if (len != -FDT_ERR_NOSPACE)
49 FAIL("fdt_get_path([%d bytes]) returns %d with "
50 "insufficient buffer space", buflen, len);
53 FAIL("fdt_get_path([%d bytes]): %s", buflen,
56 FAIL("fdt_get_path([%d bytes]) returns %d "
57 "instead of 0", buflen, len);
58 if (strcmp(buf, path) != 0)
59 FAIL("fdt_get_path([%d bytes]) returns \"%s\" "
60 "instead of \"%s\"", buflen, buf, path);
63 if (buf[buflen] != POISON)
64 FAIL("fdt_get_path([%d bytes]) overran buffer", buflen);
67 static void check_path(void *fdt, const char *path)
69 int pathlen = strlen(path);
71 check_path_buf(fdt, path, pathlen, 1024);
72 check_path_buf(fdt, path, pathlen, pathlen+1);
73 check_path_buf(fdt, path, pathlen, pathlen);
74 check_path_buf(fdt, path, pathlen, 0);
75 check_path_buf(fdt, path, pathlen, 2);
78 int main(int argc, char *argv[])
82 test_init(argc, argv);
83 fdt = load_blob_arg(argc, argv);
86 check_path(fdt, "/subnode@1");
87 check_path(fdt, "/subnode@2");
88 check_path(fdt, "/subnode@1/subsubnode");
89 check_path(fdt, "/subnode@2/subsubnode@0");