blob: 9f363b3af3cb3abcf497e996bc9439f0b189b7e1 [file] [log] [blame]
David Gibsonefbbef82007-12-05 10:43:50 +11001/*
2 * libfdt - Flat Device Tree manipulation
3 * Testcase for string references in dtc
4 * Copyright (C) 2006 David Gibson, IBM Corporation.
5 *
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.
10 *
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.
15 *
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
19 */
20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23#include <stdint.h>
24
25#include <fdt.h>
26#include <libfdt.h>
27
28#include "tests.h"
29#include "testdata.h"
30
David Gibson01a2d8a2008-08-04 15:30:13 +100031static void check_ref(const void *fdt, int node, const char *checkpath)
David Gibsonefbbef82007-12-05 10:43:50 +110032{
33 const char *p;
34 int len;
35
36 p = fdt_getprop(fdt, node, "ref", &len);
37 if (!p)
38 FAIL("fdt_getprop(%d, \"ref\"): %s", node, fdt_strerror(len));
39 if (!streq(p, checkpath))
40 FAIL("'ref' in node at %d has value \"%s\" instead of \"%s\"",
41 node, p, checkpath);
42
43 p = fdt_getprop(fdt, node, "lref", &len);
44 if (!p)
45 FAIL("fdt_getprop(%d, \"lref\"): %s", node, fdt_strerror(len));
46 if (!streq(p, checkpath))
47 FAIL("'lref' in node at %d has value \"%s\" instead of \"%s\"",
48 node, p, checkpath);
49}
50
51int main(int argc, char *argv[])
52{
53 void *fdt;
54 const char *p;
55 int len, multilen;
56 int n1, n2;
57
58 test_init(argc, argv);
59 fdt = load_blob_arg(argc, argv);
60
61 n1 = fdt_path_offset(fdt, "/node1");
62 if (n1 < 0)
63 FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
64 n2 = fdt_path_offset(fdt, "/node2");
65 if (n2 < 0)
66 FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));
67
68 check_ref(fdt, n1, "/node2");
69 check_ref(fdt, n2, "/node1");
70
71 /* Check multiple reference */
72 multilen = strlen("/node1") + strlen("/node2") + 2;
73 p = fdt_getprop(fdt, 0, "multiref", &len);
74 if (!p)
75 FAIL("fdt_getprop(0, \"multiref\"): %s", fdt_strerror(len));
76 if (len != multilen)
77 FAIL("multiref has wrong length, %d instead of %d",
78 len, multilen);
79 if ((!streq(p, "/node1") || !streq(p + strlen("/node1") + 1, "/node2")))
80 FAIL("multiref has wrong value");
81
82 PASS();
83}