source: rtems/testsuites/libtests/libfdt01/init.c @ 175263e

5
Last change on this file since 175263e was 175263e, checked in by Sebastian Huber <sebastian.huber@…>, on 10/15/15 at 09:38:03

libfdt: Initial import

Import from:

git://git.kernel.org/pub/scm/utils/dtc/dtc.git

Commit:

604e61e081e3c6c8fa1a8189c71cb3908a5bbc1e

Date:

2015-09-29T09:09:08Z

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <libfdt.h>
22#include <string.h>
23
24#include "some.h"
25
26/*
27 * To generate the FDT blob use:
28 *
29 * dtc some.dts -O asm > some.s
30 * as some.s -o some.o
31 * objcopy -O binary some.o some.bin
32 * rtems-bin2c some.bin some.c
33 */
34
35const char rtems_test_name[] = "LIBFDT 1";
36
37static void test(void)
38{
39  const void *fdt = some_bin;
40  int status;
41  uint32_t size;
42  const char *alias;
43  int root;
44  int cells;
45  const char *prop;
46  fdt32_t *prop_32;
47  int len;
48  int d;
49  int m;
50  int t;
51  int node;
52  uint32_t phandle;
53  uint32_t cell;
54
55  status = fdt_check_header(fdt);
56  rtems_test_assert(status == 0);
57
58  size = fdt_totalsize(fdt);
59  rtems_test_assert(size == some_bin_size);
60
61  alias = fdt_get_alias(fdt, "nix");
62  rtems_test_assert(alias == NULL);
63
64  alias = fdt_get_alias(fdt, "k");
65  rtems_test_assert(strcmp(alias, "/m@1248") == 0);
66
67  root = fdt_path_offset(fdt, "nix");
68  rtems_test_assert(root == -FDT_ERR_BADPATH);
69
70  root = fdt_path_offset(fdt, "/");
71  rtems_test_assert(root >= 0);
72
73  cells = fdt_address_cells(fdt, root);
74  rtems_test_assert(cells == 1);
75
76  cells = fdt_size_cells(fdt, root);
77  rtems_test_assert(cells == 2);
78
79  status = fdt_node_check_compatible(fdt, root, "a,b");
80  rtems_test_assert(status == 0);
81
82  status = fdt_node_check_compatible(fdt, root, "blub");
83  rtems_test_assert(status == 1);
84
85  prop = fdt_getprop(fdt, root, "model", &len);
86  rtems_test_assert(len == 2);
87  rtems_test_assert(memcmp(prop, "c", 2) == 0);
88
89  d = fdt_subnode_offset(fdt, root, "slurf");
90  rtems_test_assert(d == -FDT_ERR_NOTFOUND);
91
92  d = fdt_subnode_offset(fdt, root, "d");
93  rtems_test_assert(d >= 0);
94
95  prop = fdt_getprop(fdt, d, "e", &len);
96  rtems_test_assert(len == 2);
97  rtems_test_assert(memcmp(prop, "f", 2) == 0);
98
99  prop = fdt_getprop(fdt, d, "g", &len);
100  rtems_test_assert(len == 0);
101  rtems_test_assert(prop != NULL);
102
103  m = fdt_subnode_offset(fdt, root, "m@1248");
104  rtems_test_assert(m >= 0);
105
106  t = fdt_subnode_offset(fdt, root, "t");
107  rtems_test_assert(t >= 0);
108
109  prop_32 = (fdt32_t *) fdt_getprop(fdt, t, "u", &len);
110  rtems_test_assert(len == 4);
111  phandle = fdt32_to_cpu(*prop_32);
112
113  node = fdt_node_offset_by_phandle(fdt, phandle);
114  rtems_test_assert(node == m);
115
116  prop_32 = (fdt32_t *) fdt_getprop(fdt, m, "n", &len);
117  rtems_test_assert(len == 8);
118  cell = fdt32_to_cpu(prop_32[0]);
119  rtems_test_assert(cell == 0xdeadbeef);
120  cell = fdt32_to_cpu(prop_32[1]);
121  rtems_test_assert(cell == 0x12345678);
122}
123
124static void Init(rtems_task_argument arg)
125{
126  TEST_BEGIN();
127
128  test();
129
130  TEST_END();
131  rtems_test_exit(0);
132}
133
134#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
135#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
136
137#define CONFIGURE_MAXIMUM_TASKS 1
138
139#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
140
141#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
142
143#define CONFIGURE_INIT
144
145#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.