• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libfdt - Flat Device Tree manipulation
3  *	Testcase for fdt_nop_node()
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 
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <stdint.h>
26 
27 #include <libfdt.h>
28 
29 #include "tests.h"
30 #include "testdata.h"
31 
main(int argc,char * argv[])32 int main(int argc, char *argv[])
33 {
34 	void *fdt;
35 	int subnode1_offset, subnode2_offset, subsubnode2_offset;
36 	int err;
37 	int oldsize, delsize, newsize;
38 
39 	test_init(argc, argv);
40 	fdt = load_blob_arg(argc, argv);
41 
42 	fdt = open_blob_rw(fdt);
43 
44 	oldsize = fdt_totalsize(fdt);
45 
46 	subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
47 	if (subnode1_offset < 0)
48 		FAIL("Couldn't find \"/subnode@1\": %s",
49 		     fdt_strerror(subnode1_offset));
50 	check_getprop_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
51 
52 	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
53 	if (subnode2_offset < 0)
54 		FAIL("Couldn't find \"/subnode@2\": %s",
55 		     fdt_strerror(subnode2_offset));
56 	check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
57 
58 	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
59 	if (subsubnode2_offset < 0)
60 		FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
61 		     fdt_strerror(subsubnode2_offset));
62 	check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
63 
64 	err = fdt_del_node(fdt, subnode1_offset);
65 	if (err)
66 		FAIL("fdt_del_node(subnode1): %s", fdt_strerror(err));
67 
68 	subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
69 	if (subnode1_offset != -FDT_ERR_NOTFOUND)
70 		FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
71 		     fdt_strerror(subnode1_offset),
72 		     fdt_strerror(-FDT_ERR_NOTFOUND));
73 
74 	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
75 	if (subnode2_offset < 0)
76 		FAIL("Couldn't find \"/subnode2\": %s",
77 		     fdt_strerror(subnode2_offset));
78 	check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
79 
80 	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
81 	if (subsubnode2_offset < 0)
82 		FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
83 		     fdt_strerror(subsubnode2_offset));
84 	check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
85 
86 	err = fdt_del_node(fdt, subnode2_offset);
87 	if (err)
88 		FAIL("fdt_del_node(subnode2): %s", fdt_strerror(err));
89 
90 	subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
91 	if (subnode1_offset != -FDT_ERR_NOTFOUND)
92 		FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
93 		     fdt_strerror(subnode1_offset),
94 		     fdt_strerror(-FDT_ERR_NOTFOUND));
95 
96 	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
97 	if (subnode2_offset != -FDT_ERR_NOTFOUND)
98 		FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
99 		     fdt_strerror(subnode2_offset),
100 		     fdt_strerror(-FDT_ERR_NOTFOUND));
101 
102 	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
103 	if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
104 		FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
105 		     fdt_strerror(subsubnode2_offset),
106 		     fdt_strerror(-FDT_ERR_NOTFOUND));
107 
108 	delsize = fdt_totalsize(fdt);
109 
110 	err = fdt_pack(fdt);
111 	if (err)
112 		FAIL("fdt_pack(): %s", fdt_strerror(err));
113 
114 	newsize = fdt_totalsize(fdt);
115 
116 	verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n",
117 		       oldsize, delsize, newsize);
118 
119 	if (newsize >= oldsize)
120 		FAIL("Tree failed to shrink after deletions");
121 
122 	PASS();
123 }
124