1 /* $NetBSD: addr_size_cells.c,v 1.1.1.3 2019/12/22 12:34:06 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, 2);
50 check_node(fdt, "/identity-bus@0", 2, 1);
51 check_node(fdt, "/simple-bus@1000000", 2, 1);
52 check_node(fdt, "/discrete-bus@2000000", 1, 0);
53 check_node(fdt, "/c0", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
54 check_node(fdt, "/c1", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
55 check_node(fdt, "/c2", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
56 check_node(fdt, "/c3", -FDT_ERR_BADNCELLS, 0);
57 PASS();
58 }
59