del_property.c revision 1.1.1.2
1/*	$NetBSD: del_property.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $	*/
2
3/*
4 * libfdt - Flat Device Tree manipulation
5 *	Testcase for fdt_delprop()
6 * Copyright (C) 2006 David Gibson, IBM Corporation.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26#include <ctype.h>
27#include <stdint.h>
28
29#include <libfdt.h>
30
31#include "tests.h"
32#include "testdata.h"
33
34int main(int argc, char *argv[])
35{
36	void *fdt;
37	const uint32_t *intp;
38	const char *strp;
39	int err, lenerr;
40	int oldsize, delsize, newsize;
41
42	test_init(argc, argv);
43	fdt = load_blob_arg(argc, argv);
44
45	fdt = open_blob_rw(fdt);
46
47	oldsize = fdt_totalsize(fdt);
48
49	intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
50	verbose_printf("int value was 0x%08x\n", *intp);
51
52	err = fdt_delprop(fdt, 0, "prop-int");
53	if (err)
54		FAIL("Failed to delete \"prop-int\": %s", fdt_strerror(err));
55
56	intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
57	if (intp)
58		FAIL("prop-int still present after deletion");
59	if (lenerr != -FDT_ERR_NOTFOUND)
60		FAIL("Unexpected error on second getprop: %s",
61		     fdt_strerror(lenerr));
62
63	strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
64			     TEST_STRING_1);
65	verbose_printf("string value was \"%s\"\n", strp);
66	err = fdt_delprop(fdt, 0, "prop-str");
67	if (err)
68		FAIL("Failed to delete \"prop-str\": %s", fdt_strerror(err));
69
70	strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
71	if (strp)
72		FAIL("prop-str still present after deletion");
73	if (lenerr != -FDT_ERR_NOTFOUND)
74		FAIL("Unexpected error on second getprop: %s",
75		     fdt_strerror(lenerr));
76
77	delsize = fdt_totalsize(fdt);
78
79	err = fdt_pack(fdt);
80	if (err)
81		FAIL("fdt_pack(): %s\n", fdt_strerror(err));
82
83	newsize = fdt_totalsize(fdt);
84
85	verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n",
86		       oldsize, delsize, newsize);
87
88	if (newsize >= oldsize)
89		FAIL("Tree failed to shrink after deletions");
90
91	PASS();
92}
93