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
33 int main(int argc, char *argv[])
36 int subnode1_offset, subnode2_offset, subsubnode2_offset;
38 int oldsize, delsize, newsize;
40 test_init(argc, argv);
41 fdt = load_blob_arg(argc, argv);
43 fdt = open_blob_rw(fdt);
45 oldsize = fdt_totalsize(fdt);
47 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
48 if (subnode1_offset < 0)
49 FAIL("Couldn't find \"/subnode@1\": %s",
50 fdt_strerror(subnode1_offset));
51 check_getprop_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
53 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
54 if (subnode2_offset < 0)
55 FAIL("Couldn't find \"/subnode@2\": %s",
56 fdt_strerror(subnode2_offset));
57 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
59 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
60 if (subsubnode2_offset < 0)
61 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
62 fdt_strerror(subsubnode2_offset));
63 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
65 err = fdt_del_node(fdt, subnode1_offset);
67 FAIL("fdt_del_node(subnode1): %s", fdt_strerror(err));
69 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
70 if (subnode1_offset != -FDT_ERR_NOTFOUND)
71 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
72 fdt_strerror(subnode1_offset),
73 fdt_strerror(-FDT_ERR_NOTFOUND));
75 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
76 if (subnode2_offset < 0)
77 FAIL("Couldn't find \"/subnode2\": %s",
78 fdt_strerror(subnode2_offset));
79 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
81 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
82 if (subsubnode2_offset < 0)
83 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
84 fdt_strerror(subsubnode2_offset));
85 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
87 err = fdt_del_node(fdt, subnode2_offset);
89 FAIL("fdt_del_node(subnode2): %s", fdt_strerror(err));
91 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
92 if (subnode1_offset != -FDT_ERR_NOTFOUND)
93 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
94 fdt_strerror(subnode1_offset),
95 fdt_strerror(-FDT_ERR_NOTFOUND));
97 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
98 if (subnode2_offset != -FDT_ERR_NOTFOUND)
99 FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
100 fdt_strerror(subnode2_offset),
101 fdt_strerror(-FDT_ERR_NOTFOUND));
103 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
104 if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
105 FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
106 fdt_strerror(subsubnode2_offset),
107 fdt_strerror(-FDT_ERR_NOTFOUND));
109 delsize = fdt_totalsize(fdt);
113 FAIL("fdt_pack(): %s", fdt_strerror(err));
115 newsize = fdt_totalsize(fdt);
117 verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n",
118 oldsize, delsize, newsize);
120 if (newsize >= oldsize)
121 FAIL("Tree failed to shrink after deletions");