blob: 5c71414692a5e990c5a64d03e8aa3cd0bc5872f2 [file] [log] [blame]
David Gibson063693a2006-11-29 16:45:46 +11001/*
2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_nop_node()
4 * Copyright (C) 2006 David Gibson, IBM Corporation.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <ctype.h>
David Gibson857f54e2007-03-23 15:16:54 +110025#include <stdint.h>
David Gibson063693a2006-11-29 16:45:46 +110026
27#include <fdt.h>
28#include <libfdt.h>
29
30#include "tests.h"
31#include "testdata.h"
32
33#define SPACE 65536
34
35#define CHECK(code) \
36 { \
37 err = (code); \
38 if (err) \
39 FAIL(#code ": %s", fdt_strerror(err)); \
40 }
41
42int main(int argc, char *argv[])
43{
David Gibson73d60922006-12-15 15:12:47 +110044 void *fdt;
David Gibson063693a2006-11-29 16:45:46 +110045 int err;
46
47 test_init(argc, argv);
48
David Gibson73d60922006-12-15 15:12:47 +110049 fdt = xmalloc(SPACE);
50 CHECK(fdt_create(fdt, SPACE));
David Gibson063693a2006-11-29 16:45:46 +110051
David Gibsonfd1bf3a2007-10-10 17:12:12 +100052 CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_1, TEST_SIZE_1));
53 CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_2, TEST_SIZE_2));
David Gibson063693a2006-11-29 16:45:46 +110054 CHECK(fdt_finish_reservemap(fdt));
David Gibsonfd1bf3a2007-10-10 17:12:12 +100055
David Gibson063693a2006-11-29 16:45:46 +110056 CHECK(fdt_begin_node(fdt, ""));
David Gibson333542f2007-10-16 13:58:25 +100057 CHECK(fdt_property_string(fdt, "compatible", "test_tree1"));
David Gibsoncbf14102012-06-01 14:12:37 +100058 CHECK(fdt_property_u32(fdt, "prop-int", TEST_VALUE_1));
59 CHECK(fdt_property_u64(fdt, "prop-int64", TEST_VALUE64_1));
David Gibson063693a2006-11-29 16:45:46 +110060 CHECK(fdt_property_string(fdt, "prop-str", TEST_STRING_1));
61
David Gibsond2a9da02007-09-28 15:51:04 +100062 CHECK(fdt_begin_node(fdt, "subnode@1"));
David Gibson333542f2007-10-16 13:58:25 +100063 CHECK(fdt_property_string(fdt, "compatible", "subnode1"));
David Gibson9521dc52007-11-20 13:35:46 +110064 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_1));
David Gibson063693a2006-11-29 16:45:46 +110065 CHECK(fdt_begin_node(fdt, "subsubnode"));
David Gibson333542f2007-10-16 13:58:25 +100066 CHECK(fdt_property(fdt, "compatible", "subsubnode1\0subsubnode",
67 23));
David Gibson9521dc52007-11-20 13:35:46 +110068 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_1));
David Gibson063693a2006-11-29 16:45:46 +110069 CHECK(fdt_end_node(fdt));
David Gibsonf99cd152008-10-30 13:41:08 +110070 CHECK(fdt_begin_node(fdt, "ss1"));
71 CHECK(fdt_end_node(fdt));
David Gibson063693a2006-11-29 16:45:46 +110072 CHECK(fdt_end_node(fdt));
73
David Gibsond2a9da02007-09-28 15:51:04 +100074 CHECK(fdt_begin_node(fdt, "subnode@2"));
David Gibson9521dc52007-11-20 13:35:46 +110075 CHECK(fdt_property_cell(fdt, "linux,phandle", PHANDLE_1));
76 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_2));
David Gibsond2a9da02007-09-28 15:51:04 +100077 CHECK(fdt_begin_node(fdt, "subsubnode@0"));
David Gibsond75b33a2009-11-26 15:37:13 +110078 CHECK(fdt_property_cell(fdt, "phandle", PHANDLE_2));
David Gibson333542f2007-10-16 13:58:25 +100079 CHECK(fdt_property(fdt, "compatible", "subsubnode2\0subsubnode",
80 23));
David Gibson9521dc52007-11-20 13:35:46 +110081 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_2));
David Gibson063693a2006-11-29 16:45:46 +110082 CHECK(fdt_end_node(fdt));
David Gibsonf99cd152008-10-30 13:41:08 +110083 CHECK(fdt_begin_node(fdt, "ss2"));
84 CHECK(fdt_end_node(fdt));
85
David Gibson063693a2006-11-29 16:45:46 +110086 CHECK(fdt_end_node(fdt));
87
88 CHECK(fdt_end_node(fdt));
89
90 save_blob("unfinished_tree1.test.dtb", fdt);
91
92 CHECK(fdt_finish(fdt));
93
94 verbose_printf("Completed tree, totalsize = %d\n",
David Gibson73d60922006-12-15 15:12:47 +110095 fdt_totalsize(fdt));
David Gibson063693a2006-11-29 16:45:46 +110096
97 save_blob("sw_tree1.test.dtb", fdt);
98
99 PASS();
100}