symbian-qemu-0.9.1-12/dtc-trunk/tests/references.c
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 /*
       
     2  * libfdt - Flat Device Tree manipulation
       
     3  *	Testcase for phandle 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 
       
    31 void check_ref(const void *fdt, int node, uint32_t checkref)
       
    32 {
       
    33 	const uint32_t *p;
       
    34 	uint32_t ref;
       
    35 	int len;
       
    36 
       
    37 	p = fdt_getprop(fdt, node, "ref", &len);
       
    38 	if (!p)
       
    39 		FAIL("fdt_getprop(%d, \"ref\"): %s", node, fdt_strerror(len));
       
    40 	if (len != sizeof(*p))
       
    41 		FAIL("'ref' in node at %d has wrong size (%d instead of %zd)",
       
    42 		     node, len, sizeof(*p));
       
    43 	ref = fdt32_to_cpu(*p);
       
    44 	if (ref != checkref)
       
    45 		FAIL("'ref' in node at %d has value 0x%x instead of 0x%x",
       
    46 		     node, ref, checkref);
       
    47 
       
    48 	p = fdt_getprop(fdt, node, "lref", &len);
       
    49 	if (!p)
       
    50 		FAIL("fdt_getprop(%d, \"lref\"): %s", node, fdt_strerror(len));
       
    51 	if (len != sizeof(*p))
       
    52 		FAIL("'lref' in node at %d has wrong size (%d instead of %zd)",
       
    53 		     node, len, sizeof(*p));
       
    54 	ref = fdt32_to_cpu(*p);
       
    55 	if (ref != checkref)
       
    56 		FAIL("'lref' in node at %d has value 0x%x instead of 0x%x",
       
    57 		     node, ref, checkref);
       
    58 }
       
    59 
       
    60 int main(int argc, char *argv[])
       
    61 {
       
    62 	void *fdt;
       
    63 	int n1, n2, n3, n4;
       
    64 	uint32_t h1, h2, h4;
       
    65 
       
    66 	test_init(argc, argv);
       
    67 	fdt = load_blob_arg(argc, argv);
       
    68 
       
    69 	n1 = fdt_path_offset(fdt, "/node1");
       
    70 	if (n1 < 0)
       
    71 		FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
       
    72 	n2 = fdt_path_offset(fdt, "/node2");
       
    73 	if (n2 < 0)
       
    74 		FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));
       
    75 	n3 = fdt_path_offset(fdt, "/node3");
       
    76 	if (n3 < 0)
       
    77 		FAIL("fdt_path_offset(/node3): %s", fdt_strerror(n3));
       
    78 	n4 = fdt_path_offset(fdt, "/node4");
       
    79 	if (n4 < 0)
       
    80 		FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4));
       
    81 
       
    82 	h1 = fdt_get_phandle(fdt, n1);
       
    83 	h2 = fdt_get_phandle(fdt, n2);
       
    84 	h4 = fdt_get_phandle(fdt, n4);
       
    85 
       
    86 	if (h1 != 0x2000)
       
    87 		FAIL("/node1 has wrong phandle, 0x%x instead of 0x%x",
       
    88 		     h1, 0x2000);
       
    89 	if (h2 != 0x1)
       
    90 		FAIL("/node2 has wrong phandle, 0x%x instead of 0x%x",
       
    91 		     h2, 0x1);
       
    92 	if ((h4 == 0x2000) || (h4 == 0x1) || (h4 == 0))
       
    93 		FAIL("/node4 has bad phandle, 0x%x", h4);
       
    94 
       
    95 	check_ref(fdt, n1, h2);
       
    96 	check_ref(fdt, n2, h1);
       
    97 	check_ref(fdt, n3, h4);
       
    98 
       
    99 	PASS();
       
   100 }