1 /*
2  * libfdt - Flat Device Tree manipulation
3  *	Testcase for #address-cells and #size-cells handling
4  * Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au>
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 
check_node(const void * fdt,const char * path,int ac,int sc)30 static void check_node(const void *fdt, const char *path, int ac, int sc)
31 {
32 	int offset;
33 	int xac, xsc;
34 
35 	offset = fdt_path_offset(fdt, path);
36 	if (offset < 0)
37 		FAIL("Couldn't find path %s", path);
38 
39 	xac = fdt_address_cells(fdt, offset);
40 	xsc = fdt_size_cells(fdt, offset);
41 
42 	if (xac != ac)
43 		FAIL("Address cells for %s is %d instead of %d\n",
44 		     path, xac, ac);
45 	if (xsc != sc)
46 		FAIL("Size cells for %s is %d instead of %d\n",
47 		     path, xsc, sc);
48 }
49 
main(int argc,char * argv[])50 int main(int argc, char *argv[])
51 {
52 	void *fdt;
53 
54 	if (argc != 2)
55 		CONFIG("Usage: %s <dtb file>\n", argv[0]);
56 
57 	test_init(argc, argv);
58 	fdt = load_blob(argv[1]);
59 
60 	check_node(fdt, "/", 2, 2);
61 	PASS();
62 }
63