Rob Herring | c4ffc05 | 2019-06-20 15:19:41 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: LGPL-2.1-or-later |
Minghuan Lian | a31e3ef | 2011-12-05 12:22:07 +1100 | [diff] [blame] | 2 | /* |
| 3 | * libfdt - Flat Device Tree manipulation |
| 4 | * Testcase for fdt_appendprop() |
| 5 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
Minghuan Lian | a31e3ef | 2011-12-05 12:22:07 +1100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <stdlib.h> |
| 9 | #include <stdio.h> |
| 10 | #include <string.h> |
| 11 | #include <ctype.h> |
| 12 | #include <stdint.h> |
| 13 | |
Minghuan Lian | a31e3ef | 2011-12-05 12:22:07 +1100 | [diff] [blame] | 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 | |
| 28 | int 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 Gibson | cbf1410 | 2012-06-01 14:12:37 +1000 | [diff] [blame] | 49 | CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1)); |
Minghuan Lian | a31e3ef | 2011-12-05 12:22:07 +1100 | [diff] [blame] | 50 | 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 | } |