blob: a7b502aacd1c4b8519d24c2abc257a62a8440a81 [file] [log] [blame]
Rob Herringc4ffc052019-06-20 15:19:41 -06001// SPDX-License-Identifier: LGPL-2.1-or-later
Minghuan Liana31e3ef2011-12-05 12:22:07 +11002/*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for fdt_appendprop()
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
Minghuan Liana31e3ef2011-12-05 12:22:07 +11006 */
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include <ctype.h>
12#include <stdint.h>
13
Minghuan Liana31e3ef2011-12-05 12:22:07 +110014#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
28int main(int argc, char *argv[])
29{
30 void *fdt;
31 int err;
32 uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04};
33
34 test_init(argc, argv);
35
36 /* Create an empty tree first */
37 fdt = xmalloc(SPACE);
38 CHECK(fdt_create(fdt, SPACE));
39 CHECK(fdt_finish_reservemap(fdt));
40 CHECK(fdt_begin_node(fdt, ""));
41 CHECK(fdt_end_node(fdt));
42 CHECK(fdt_finish(fdt));
43
44 /* Now use appendprop to add properties */
45 CHECK(fdt_open_into(fdt, fdt, SPACE));
46
47 CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));
48 CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_1));
David Gibsoncbf14102012-06-01 14:12:37 +100049 CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1));
Minghuan Liana31e3ef2011-12-05 12:22:07 +110050 CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_1));
51
52 CHECK(fdt_pack(fdt));
53
54 save_blob("appendprop1.test.dtb", fdt);
55
56 PASS();
57}