Add qemu 2.4.0
[kvmfornfv.git] / qemu / dtc / tests / phandle_format.c
1 /*
2  * libfdt - Flat Device Tree manipulation
3  *      Testcase for phandle format options
4  * Copyright (C) 2009 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 #define PHANDLE_LEGACY  0x1
31 #define PHANDLE_EPAPR   0x2
32 #define PHANDLE_BOTH    0x3
33
34 int main(int argc, char *argv[])
35 {
36         void *fdt;
37         int phandle_format;
38         int n4;
39         uint32_t h4;
40
41         if (argc != 3)
42                 CONFIG("Usage: %s <dtb file> <legacy|epapr|both>\n", argv[0]);
43
44         test_init(argc, argv);
45         fdt = load_blob(argv[1]);
46
47         if (streq(argv[2], "legacy"))
48                 phandle_format = PHANDLE_LEGACY;
49         else if (streq(argv[2], "epapr"))
50                 phandle_format = PHANDLE_EPAPR;
51         else if (streq(argv[2], "both"))
52                 phandle_format = PHANDLE_BOTH;
53         else
54                 CONFIG("Usage: %s <dtb file> <legacy|epapr|both>\n", argv[0]);
55
56         n4 = fdt_path_offset(fdt, "/node4");
57         if (n4 < 0)
58                 FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4));
59
60         h4 = fdt_get_phandle(fdt, n4);
61         if ((h4 == 0) || (h4 == -1))
62                 FAIL("/node4 has bad phandle 0x%x\n", h4);
63
64         if (phandle_format & PHANDLE_LEGACY)
65                 check_getprop_cell(fdt, n4, "linux,phandle", h4);
66         else
67                 if (fdt_getprop(fdt, n4, "linux,phandle", NULL))
68                         FAIL("linux,phandle property present in non-legacy mode");
69
70         if (phandle_format & PHANDLE_EPAPR)
71                 check_getprop_cell(fdt, n4, "phandle", h4);
72         else
73                 if (fdt_getprop(fdt, n4, "phandle", NULL))
74                         FAIL("phandle property present in legacy-only mode");
75
76         PASS();
77 }