2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_nop_node()
4 * Copyright (C) 2006 David Gibson, IBM Corporation.
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.
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.
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
32 int main(int argc, char *argv[])
35 int subnode1_offset, subnode2_offset, subsubnode2_offset;
37 int oldsize, delsize, newsize;
39 test_init(argc, argv);
40 fdt = load_blob_arg(argc, argv);
42 fdt = open_blob_rw(fdt);
44 oldsize = fdt_totalsize(fdt);
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);
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);
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);
64 err = fdt_del_node(fdt, subnode1_offset);
66 FAIL("fdt_del_node(subnode1): %s", fdt_strerror(err));
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));
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);
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);
86 err = fdt_del_node(fdt, subnode2_offset);
88 FAIL("fdt_del_node(subnode2): %s", fdt_strerror(err));
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));
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));
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));
108 delsize = fdt_totalsize(fdt);
112 FAIL("fdt_pack(): %s", fdt_strerror(err));
114 newsize = fdt_totalsize(fdt);
116 verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n",
117 oldsize, delsize, newsize);
119 if (newsize >= oldsize)
120 FAIL("Tree failed to shrink after deletions");