xref: /netbsd-src/external/gpl2/dtc/dist/tests/nop_node.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: nop_node.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $	*/
2 
3 /*
4  * libfdt - Flat Device Tree manipulation
5  *	Testcase for fdt_nop_node()
6  * Copyright (C) 2006 David Gibson, IBM Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <stdint.h>
28 
29 #include <libfdt.h>
30 
31 #include "tests.h"
32 #include "testdata.h"
33 
34 int main(int argc, char *argv[])
35 {
36 	void *fdt;
37 	int subnode1_offset, subnode2_offset, subsubnode2_offset;
38 	int err;
39 
40 	test_init(argc, argv);
41 	fdt = load_blob_arg(argc, argv);
42 
43 	subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
44 	if (subnode1_offset < 0)
45 		FAIL("Couldn't find \"/subnode1\": %s",
46 		     fdt_strerror(subnode1_offset));
47 	check_getprop_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
48 
49 	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
50 	if (subnode2_offset < 0)
51 		FAIL("Couldn't find \"/subnode2\": %s",
52 		     fdt_strerror(subnode2_offset));
53 	check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
54 
55 	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
56 	if (subsubnode2_offset < 0)
57 		FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
58 		     fdt_strerror(subsubnode2_offset));
59 	check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
60 
61 	err = fdt_nop_node(fdt, subnode1_offset);
62 	if (err)
63 		FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err));
64 
65 	subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
66 	if (subnode1_offset != -FDT_ERR_NOTFOUND)
67 		FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
68 		     fdt_strerror(subnode1_offset),
69 		     fdt_strerror(-FDT_ERR_NOTFOUND));
70 
71 	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
72 	if (subnode2_offset < 0)
73 		FAIL("Couldn't find \"/subnode2\": %s",
74 		     fdt_strerror(subnode2_offset));
75 	check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
76 
77 	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
78 	if (subsubnode2_offset < 0)
79 		FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
80 		     fdt_strerror(subsubnode2_offset));
81 	check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
82 
83 	err = fdt_nop_node(fdt, subnode2_offset);
84 	if (err)
85 		FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err));
86 
87 	subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
88 	if (subnode1_offset != -FDT_ERR_NOTFOUND)
89 		FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
90 		     fdt_strerror(subnode1_offset),
91 		     fdt_strerror(-FDT_ERR_NOTFOUND));
92 
93 	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
94 	if (subnode2_offset != -FDT_ERR_NOTFOUND)
95 		FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
96 		     fdt_strerror(subnode2_offset),
97 		     fdt_strerror(-FDT_ERR_NOTFOUND));
98 
99 	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
100 	if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
101 		FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
102 		     fdt_strerror(subsubnode2_offset),
103 		     fdt_strerror(-FDT_ERR_NOTFOUND));
104 
105 	PASS();
106 }
107