xref: /netbsd-src/external/gpl2/dtc/dist/tests/appendprop1.c (revision cc7d2833ecf67da5a5ddc470841931eb9f6723e4)
1 /*	$NetBSD: appendprop1.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $	*/
2 
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 /*
5  * libfdt - Flat Device Tree manipulation
6  *	Testcase for fdt_appendprop()
7  * Copyright (C) 2006 David Gibson, IBM Corporation.
8  */
9 
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <stdint.h>
15 
16 #include <libfdt.h>
17 
18 #include "tests.h"
19 #include "testdata.h"
20 
21 #define SPACE		65536
22 
23 #define CHECK(code) \
24 	{ \
25 		err = (code); \
26 		if (err) \
27 			FAIL(#code ": %s", fdt_strerror(err)); \
28 	}
29 
main(int argc,char * argv[])30 int main(int argc, char *argv[])
31 {
32 	void *fdt;
33 	int err;
34 	uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04};
35 
36 	test_init(argc, argv);
37 
38 	/* Create an empty tree first */
39 	fdt = xmalloc(SPACE);
40 	CHECK(fdt_create(fdt, SPACE));
41 	CHECK(fdt_finish_reservemap(fdt));
42 	CHECK(fdt_begin_node(fdt, ""));
43 	CHECK(fdt_end_node(fdt));
44 	CHECK(fdt_finish(fdt));
45 
46 	/* Now use appendprop to add properties */
47 	CHECK(fdt_open_into(fdt, fdt, SPACE));
48 
49 	CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));
50 	CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_1));
51 	CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1));
52 	CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_1));
53 
54 	CHECK(fdt_pack(fdt));
55 
56 	save_blob("appendprop1.test.dtb", fdt);
57 
58 	PASS();
59 }
60