xref: /netbsd-src/external/gpl2/dtc/dist/tests/appendprop2.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: appendprop2.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_appendprop()
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 
34 #define SPACE		65536
35 
36 #define CHECK(code) \
37 	{ \
38 		err = (code); \
39 		if (err) \
40 			FAIL(#code ": %s", fdt_strerror(err)); \
41 	}
42 
43 int main(int argc, char *argv[])
44 {
45 	void *fdt, *buf;
46 	int err;
47 	uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04};
48 
49 	test_init(argc, argv);
50 	fdt = load_blob_arg(argc, argv);
51 
52 	buf = xmalloc(SPACE);
53 	CHECK(fdt_open_into(fdt, buf, SPACE));
54 	fdt = buf;
55 
56 	CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));
57 	CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_2));
58 	CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1));
59 	CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_2));
60 
61 	CHECK(fdt_pack(fdt));
62 
63 	save_blob("appendprop2.test.dtb", fdt);
64 
65 	PASS();
66 }
67