• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3  * libfdt - Flat Device Tree manipulation
4  *	Testcase for fdt_nop_node()
5  * Copyright (C) 2006 David Gibson, IBM Corporation.
6  */
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <stdint.h>
13 
14 #include <libfdt.h>
15 
16 #include "tests.h"
17 #include "testdata.h"
18 
19 #define SPACE	65536
20 
21 #define CHECK(code) \
22 	{ \
23 		err = (code); \
24 		if (err) \
25 			FAIL(#code ": %s", fdt_strerror(err)); \
26 	}
27 
28 #define OFF_CHECK(off, code) \
29 	{ \
30 		(off) = (code); \
31 		if (off < 0) \
32 			FAIL(#code ": %s", fdt_strerror(off)); \
33 	}
34 
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37 	void *fdt;
38 	int err;
39 	int offset;
40 
41 	test_init(argc, argv);
42 
43 	fdt = xmalloc(SPACE);
44 
45 	CHECK(fdt_create(fdt, SPACE));
46 
47 	CHECK(fdt_finish_reservemap(fdt));
48 	CHECK(fdt_begin_node(fdt, ""));
49 	CHECK(fdt_property_cell(fdt, "prop1", TEST_VALUE_1));
50 	CHECK(fdt_property_cell(fdt, "prop2", TEST_VALUE_2));
51 	CHECK(fdt_end_node(fdt));
52 	CHECK(fdt_finish(fdt));
53 
54 	verbose_printf("Built empty tree, totalsize = %d\n",
55 		       fdt_totalsize(fdt));
56 
57 	CHECK(fdt_open_into(fdt, fdt, SPACE));
58 
59 	check_getprop_cell(fdt, 0, "prop1", TEST_VALUE_1);
60 	check_getprop_cell(fdt, 0, "prop2", TEST_VALUE_2);
61 
62 	CHECK(fdt_nop_property(fdt, 0, "prop1"));
63 
64 	check_getprop_cell(fdt, 0, "prop2", TEST_VALUE_2);
65 
66 	OFF_CHECK(offset, fdt_add_subnode(fdt, 0, "subnode"));
67 
68 	check_getprop_cell(fdt, 0, "prop2", TEST_VALUE_2);
69 
70 	PASS();
71 }
72