|
1 /* |
|
2 * libfdt - Flat Device Tree manipulation |
|
3 * Testcase for fdt_delprop() |
|
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 <fdt.h> |
|
28 #include <libfdt.h> |
|
29 |
|
30 #include "tests.h" |
|
31 #include "testdata.h" |
|
32 |
|
33 int main(int argc, char *argv[]) |
|
34 { |
|
35 void *fdt; |
|
36 const uint32_t *intp; |
|
37 const char *strp; |
|
38 int err, lenerr; |
|
39 int oldsize, delsize, newsize; |
|
40 |
|
41 test_init(argc, argv); |
|
42 fdt = load_blob_arg(argc, argv); |
|
43 |
|
44 fdt = open_blob_rw(fdt); |
|
45 |
|
46 oldsize = fdt_totalsize(fdt); |
|
47 |
|
48 intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); |
|
49 verbose_printf("int value was 0x%08x\n", *intp); |
|
50 |
|
51 err = fdt_delprop(fdt, 0, "prop-int"); |
|
52 if (err) |
|
53 FAIL("Failed to delete \"prop-int\": %s", fdt_strerror(err)); |
|
54 |
|
55 intp = fdt_getprop(fdt, 0, "prop-int", &lenerr); |
|
56 if (intp) |
|
57 FAIL("prop-int still present after deletion"); |
|
58 if (lenerr != -FDT_ERR_NOTFOUND) |
|
59 FAIL("Unexpected error on second getprop: %s", |
|
60 fdt_strerror(lenerr)); |
|
61 |
|
62 strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, |
|
63 TEST_STRING_1); |
|
64 verbose_printf("string value was \"%s\"\n", strp); |
|
65 err = fdt_delprop(fdt, 0, "prop-str"); |
|
66 if (err) |
|
67 FAIL("Failed to delete \"prop-str\": %s", fdt_strerror(err)); |
|
68 |
|
69 strp = fdt_getprop(fdt, 0, "prop-str", &lenerr); |
|
70 if (strp) |
|
71 FAIL("prop-str still present after deletion"); |
|
72 if (lenerr != -FDT_ERR_NOTFOUND) |
|
73 FAIL("Unexpected error on second getprop: %s", |
|
74 fdt_strerror(lenerr)); |
|
75 |
|
76 delsize = fdt_totalsize(fdt); |
|
77 |
|
78 err = fdt_pack(fdt); |
|
79 if (err) |
|
80 FAIL("fdt_pack(): %s\n", fdt_strerror(err)); |
|
81 |
|
82 newsize = fdt_totalsize(fdt); |
|
83 |
|
84 verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n", |
|
85 oldsize, delsize, newsize); |
|
86 |
|
87 if (newsize >= oldsize) |
|
88 FAIL("Tree failed to shrink after deletions"); |
|
89 |
|
90 PASS(); |
|
91 } |