blob: afad5027b79137cff66b7de334dc6e692c3e0e94 [file] [log] [blame]
David Gibson7ba551f2006-12-01 16:59:43 +11001/*
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>
David Gibson857f54e2007-03-23 15:16:54 +110025#include <stdint.h>
David Gibson7ba551f2006-12-01 16:59:43 +110026
27#include <fdt.h>
28#include <libfdt.h>
29
30#include "tests.h"
31#include "testdata.h"
32
33int main(int argc, char *argv[])
34{
David Gibson73d60922006-12-15 15:12:47 +110035 void *fdt;
David Gibson7ba551f2006-12-01 16:59:43 +110036 int subnode1_offset, subnode2_offset, subsubnode2_offset;
37 int err;
38 int oldsize, delsize, newsize;
39
40 test_init(argc, argv);
41 fdt = load_blob_arg(argc, argv);
42
David Gibsona041dcd2007-11-01 11:37:31 +110043 fdt = open_blob_rw(fdt);
44
David Gibson7ba551f2006-12-01 16:59:43 +110045 oldsize = fdt_totalsize(fdt);
46
David Gibsond2a9da02007-09-28 15:51:04 +100047 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
David Gibson9a9fdf52006-12-15 15:12:51 +110048 if (subnode1_offset < 0)
David Gibsond2a9da02007-09-28 15:51:04 +100049 FAIL("Couldn't find \"/subnode@1\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110050 fdt_strerror(subnode1_offset));
David Gibson9521dc52007-11-20 13:35:46 +110051 check_getprop_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
David Gibson7ba551f2006-12-01 16:59:43 +110052
David Gibsond2a9da02007-09-28 15:51:04 +100053 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
David Gibson9a9fdf52006-12-15 15:12:51 +110054 if (subnode2_offset < 0)
David Gibsond2a9da02007-09-28 15:51:04 +100055 FAIL("Couldn't find \"/subnode@2\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110056 fdt_strerror(subnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110057 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson7ba551f2006-12-01 16:59:43 +110058
David Gibsond2a9da02007-09-28 15:51:04 +100059 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110060 if (subsubnode2_offset < 0)
David Gibsond2a9da02007-09-28 15:51:04 +100061 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110062 fdt_strerror(subsubnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110063 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson7ba551f2006-12-01 16:59:43 +110064
65 err = fdt_del_node(fdt, subnode1_offset);
66 if (err)
67 FAIL("fdt_del_node(subnode1): %s", fdt_strerror(err));
68
David Gibsond2a9da02007-09-28 15:51:04 +100069 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
David Gibson9a9fdf52006-12-15 15:12:51 +110070 if (subnode1_offset != -FDT_ERR_NOTFOUND)
David Gibson7ba551f2006-12-01 16:59:43 +110071 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110072 fdt_strerror(subnode1_offset),
73 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson7ba551f2006-12-01 16:59:43 +110074
David Gibsond2a9da02007-09-28 15:51:04 +100075 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
David Gibson9a9fdf52006-12-15 15:12:51 +110076 if (subnode2_offset < 0)
77 FAIL("Couldn't find \"/subnode2\": %s",
78 fdt_strerror(subnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110079 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson7ba551f2006-12-01 16:59:43 +110080
David Gibsond2a9da02007-09-28 15:51:04 +100081 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110082 if (subsubnode2_offset < 0)
David Gibsond2a9da02007-09-28 15:51:04 +100083 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110084 fdt_strerror(subsubnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110085 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson7ba551f2006-12-01 16:59:43 +110086
87 err = fdt_del_node(fdt, subnode2_offset);
88 if (err)
89 FAIL("fdt_del_node(subnode2): %s", fdt_strerror(err));
90
David Gibsond2a9da02007-09-28 15:51:04 +100091 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
David Gibson9a9fdf52006-12-15 15:12:51 +110092 if (subnode1_offset != -FDT_ERR_NOTFOUND)
David Gibson7ba551f2006-12-01 16:59:43 +110093 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110094 fdt_strerror(subnode1_offset),
95 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson7ba551f2006-12-01 16:59:43 +110096
David Gibsond2a9da02007-09-28 15:51:04 +100097 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
David Gibson9a9fdf52006-12-15 15:12:51 +110098 if (subnode2_offset != -FDT_ERR_NOTFOUND)
David Gibson7ba551f2006-12-01 16:59:43 +110099 FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +1100100 fdt_strerror(subnode2_offset),
101 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson7ba551f2006-12-01 16:59:43 +1100102
David Gibsond2a9da02007-09-28 15:51:04 +1000103 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +1100104 if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
David Gibson7ba551f2006-12-01 16:59:43 +1100105 FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +1100106 fdt_strerror(subsubnode2_offset),
107 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson7ba551f2006-12-01 16:59:43 +1100108
109 delsize = fdt_totalsize(fdt);
110
David Gibson73d60922006-12-15 15:12:47 +1100111 err = fdt_pack(fdt);
112 if (err)
David Gibson7ba551f2006-12-01 16:59:43 +1100113 FAIL("fdt_pack(): %s", fdt_strerror(err));
114
115 newsize = fdt_totalsize(fdt);
116
117 verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n",
118 oldsize, delsize, newsize);
119
120 if (newsize >= oldsize)
121 FAIL("Tree failed to shrink after deletions");
122
123 PASS();
124}