2 * libfdt - Flat Device Tree manipulation
3 * Testcase for string references in dtc
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 void check_ref(const void *fdt, int node, const char *checkpath)
35 p = fdt_getprop(fdt, node, "ref", &len);
37 FAIL("fdt_getprop(%d, \"ref\"): %s", node, fdt_strerror(len));
38 if (!streq(p, checkpath))
39 FAIL("'ref' in node at %d has value \"%s\" instead of \"%s\"",
42 p = fdt_getprop(fdt, node, "lref", &len);
44 FAIL("fdt_getprop(%d, \"lref\"): %s", node, fdt_strerror(len));
45 if (!streq(p, checkpath))
46 FAIL("'lref' in node at %d has value \"%s\" instead of \"%s\"",
50 int main(int argc, char *argv[])
57 test_init(argc, argv);
58 fdt = load_blob_arg(argc, argv);
60 n1 = fdt_path_offset(fdt, "/node1");
62 FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
63 n2 = fdt_path_offset(fdt, "/node2");
65 FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));
67 check_ref(fdt, n1, "/node2");
68 check_ref(fdt, n2, "/node1");
70 /* Check multiple reference */
71 multilen = strlen("/node1") + strlen("/node2") + 2;
72 p = fdt_getprop(fdt, 0, "multiref", &len);
74 FAIL("fdt_getprop(0, \"multiref\"): %s", fdt_strerror(len));
76 FAIL("multiref has wrong length, %d instead of %d",
78 if ((!streq(p, "/node1") || !streq(p + strlen("/node1") + 1, "/node2")))
79 FAIL("multiref has wrong value");