1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3  * libfdt - Flat Device Tree manipulation
4  *	Testcase for fdt_appendprop()
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 
main(int argc,char * argv[])28 int main(int argc, char *argv[])
29 {
30 	void *fdt, *buf;
31 	int err;
32 	uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04};
33 
34 	test_init(argc, argv);
35 	fdt = load_blob_arg(argc, argv);
36 
37 	buf = xmalloc(SPACE);
38 	CHECK(fdt_open_into(fdt, buf, SPACE));
39 	fdt = buf;
40 
41 	CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));
42 	CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_2));
43 	CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1));
44 	CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_2));
45 
46 	CHECK(fdt_pack(fdt));
47 
48 	save_blob("appendprop2.test.dtb", fdt);
49 
50 	PASS();
51 }
52