1 /* $NetBSD: appendprop2.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, *buf;
33 int err;
34 uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04};
35
36 test_init(argc, argv);
37 fdt = load_blob_arg(argc, argv);
38
39 buf = xmalloc(SPACE);
40 CHECK(fdt_open_into(fdt, buf, SPACE));
41 fdt = buf;
42
43 CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));
44 CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_2));
45 CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1));
46 CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_2));
47
48 CHECK(fdt_pack(fdt));
49
50 save_blob("appendprop2.test.dtb", fdt);
51
52 PASS();
53 }
54