• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libfdt - Flat Device Tree manipulation
3  *	Testcase for fdt_nop_property()
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 <libfdt.h>
28 
29 #include "tests.h"
30 #include "testdata.h"
31 
main(int argc,char * argv[])32 int main(int argc, char *argv[])
33 {
34 	void *fdt;
35 	const uint32_t *intp;
36 	const char *strp;
37 	int err;
38 	int lenerr;
39 
40 	test_init(argc, argv);
41 	fdt = load_blob_arg(argc, argv);
42 
43 	intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
44 	verbose_printf("int value was 0x%08x\n", *intp);
45 
46 	err = fdt_nop_property(fdt, 0, "prop-int");
47 	if (err)
48 		FAIL("Failed to nop \"prop-int\": %s", fdt_strerror(err));
49 
50 	intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
51 	if (intp)
52 		FAIL("prop-int still present after nopping");
53 	if (lenerr != -FDT_ERR_NOTFOUND)
54 		FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
55 
56 	strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
57 			     TEST_STRING_1);
58 	verbose_printf("string value was \"%s\"\n", strp);
59 	err = fdt_nop_property(fdt, 0, "prop-str");
60 	if (err)
61 		FAIL("Failed to nop \"prop-str\": %s", fdt_strerror(err));
62 
63 	strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
64 	if (strp)
65 		FAIL("prop-str still present after nopping");
66 	if (lenerr != -FDT_ERR_NOTFOUND)
67 		FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
68 
69 	PASS();
70 }
71