Add qemu 2.4.0
[kvmfornfv.git] / qemu / dtc / tests / path-references.c
1 /*
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 <libfdt.h>
26
27 #include "tests.h"
28 #include "testdata.h"
29
30 static void check_ref(const void *fdt, int node, const char *checkpath)
31 {
32         const char *p;
33         int len;
34
35         p = fdt_getprop(fdt, node, "ref", &len);
36         if (!p)
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\"",
40                      node, p, checkpath);
41
42         p = fdt_getprop(fdt, node, "lref", &len);
43         if (!p)
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\"",
47                      node, p, checkpath);
48 }
49
50 int main(int argc, char *argv[])
51 {
52         void *fdt;
53         const char *p;
54         int len, multilen;
55         int n1, n2;
56
57         test_init(argc, argv);
58         fdt = load_blob_arg(argc, argv);
59
60         n1 = fdt_path_offset(fdt, "/node1");
61         if (n1 < 0)
62                 FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
63         n2 = fdt_path_offset(fdt, "/node2");
64         if (n2 < 0)
65                 FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));
66
67         check_ref(fdt, n1, "/node2");
68         check_ref(fdt, n2, "/node1");
69
70         /* Check multiple reference */
71         multilen = strlen("/node1") + strlen("/node2") + 2;
72         p = fdt_getprop(fdt, 0, "multiref", &len);
73         if (!p)
74                 FAIL("fdt_getprop(0, \"multiref\"): %s", fdt_strerror(len));
75         if (len != multilen)
76                 FAIL("multiref has wrong length, %d instead of %d",
77                      len, multilen);
78         if ((!streq(p, "/node1") || !streq(p + strlen("/node1") + 1, "/node2")))
79                 FAIL("multiref has wrong value");
80
81         PASS();
82 }