xref: /netbsd-src/external/gpl2/dtc/dist/tests/addr_size_cells2.c (revision cc7d2833ecf67da5a5ddc470841931eb9f6723e4)
1 /*	$NetBSD: addr_size_cells2.c,v 1.1.1.1 2019/12/22 12:34:07 skrll Exp $	*/
2 
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 /*
5  * libfdt - Flat Device Tree manipulation
6  *	Testcase for #address-cells and #size-cells handling
7  * Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au>
8  */
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdint.h>
13 
14 #include <libfdt.h>
15 
16 #include "tests.h"
17 #include "testdata.h"
18 
check_node(const void * fdt,const char * path,int ac,int sc)19 static void check_node(const void *fdt, const char *path, int ac, int sc)
20 {
21 	int offset;
22 	int xac, xsc;
23 
24 	offset = fdt_path_offset(fdt, path);
25 	if (offset < 0)
26 		FAIL("Couldn't find path %s", path);
27 
28 	xac = fdt_address_cells(fdt, offset);
29 	xsc = fdt_size_cells(fdt, offset);
30 
31 	if (xac != ac)
32 		FAIL("Address cells for %s is %d instead of %d\n",
33 		     path, xac, ac);
34 	if (xsc != sc)
35 		FAIL("Size cells for %s is %d instead of %d\n",
36 		     path, xsc, sc);
37 }
38 
main(int argc,char * argv[])39 int main(int argc, char *argv[])
40 {
41 	void *fdt;
42 
43 	if (argc != 2)
44 		CONFIG("Usage: %s <dtb file>\n", argv[0]);
45 
46 	test_init(argc, argv);
47 	fdt = load_blob(argv[1]);
48 
49 	check_node(fdt, "/", 2, 1);
50 	PASS();
51 }
52