From 175263ec91f00f6668ae7f28f385850a1c77bf6b Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 15 Oct 2015 11:38:03 +0200 Subject: libfdt: Initial import Import from: git://git.kernel.org/pub/scm/utils/dtc/dtc.git Commit: 604e61e081e3c6c8fa1a8189c71cb3908a5bbc1e Date: 2015-09-29T09:09:08Z --- testsuites/libtests/Makefile.am | 1 + testsuites/libtests/configure.ac | 1 + testsuites/libtests/libfdt01/Makefile.am | 20 +++++ testsuites/libtests/libfdt01/init.c | 145 ++++++++++++++++++++++++++++++ testsuites/libtests/libfdt01/libfdt01.doc | 20 +++++ testsuites/libtests/libfdt01/libfdt01.scn | 2 + testsuites/libtests/libfdt01/some.c | 52 +++++++++++ testsuites/libtests/libfdt01/some.dts | 54 +++++++++++ testsuites/libtests/libfdt01/some.h | 15 ++++ 9 files changed, 310 insertions(+) create mode 100644 testsuites/libtests/libfdt01/Makefile.am create mode 100644 testsuites/libtests/libfdt01/init.c create mode 100644 testsuites/libtests/libfdt01/libfdt01.doc create mode 100644 testsuites/libtests/libfdt01/libfdt01.scn create mode 100644 testsuites/libtests/libfdt01/some.c create mode 100644 testsuites/libtests/libfdt01/some.dts create mode 100644 testsuites/libtests/libfdt01/some.h (limited to 'testsuites') diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am index ed773c4e06..d775c77c76 100644 --- a/testsuites/libtests/Makefile.am +++ b/testsuites/libtests/Makefile.am @@ -1,6 +1,7 @@ ACLOCAL_AMFLAGS = -I ../aclocal _SUBDIRS = POSIX +_SUBDIRS += libfdt01 _SUBDIRS += defaultconfig01 _SUBDIRS += pwdgrp02 _SUBDIRS += shell01 diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac index 4924e0f2a2..89ca57fa16 100644 --- a/testsuites/libtests/configure.ac +++ b/testsuites/libtests/configure.ac @@ -79,6 +79,7 @@ AM_CONDITIONAL(DLTESTS,[test x"$TEST_LIBDL" = x"yes"]) # Explicitly list all Makefiles here AC_CONFIG_FILES([Makefile +libfdt01/Makefile defaultconfig01/Makefile pwdgrp02/Makefile shell01/Makefile diff --git a/testsuites/libtests/libfdt01/Makefile.am b/testsuites/libtests/libfdt01/Makefile.am new file mode 100644 index 0000000000..880d22191e --- /dev/null +++ b/testsuites/libtests/libfdt01/Makefile.am @@ -0,0 +1,20 @@ +rtems_tests_PROGRAMS = libfdt01 +libfdt01_SOURCES = init.c some.c +libfdt01_LDADD = -lfdt + +dist_rtems_tests_DATA = libfdt01.scn libfdt01.doc + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(libfdt01_OBJECTS) $(libfdt01_LDADD) +LINK_LIBS = $(libfdt01_LDLIBS) + +libfdt01$(EXEEXT): $(libfdt01_OBJECTS) $(libfdt01_DEPENDENCIES) + @rm -f libfdt01$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/libtests/libfdt01/init.c b/testsuites/libtests/libfdt01/init.c new file mode 100644 index 0000000000..a13fc82021 --- /dev/null +++ b/testsuites/libtests/libfdt01/init.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include "tmacros.h" + +#include +#include + +#include "some.h" + +/* + * To generate the FDT blob use: + * + * dtc some.dts -O asm > some.s + * as some.s -o some.o + * objcopy -O binary some.o some.bin + * rtems-bin2c some.bin some.c + */ + +const char rtems_test_name[] = "LIBFDT 1"; + +static void test(void) +{ + const void *fdt = some_bin; + int status; + uint32_t size; + const char *alias; + int root; + int cells; + const char *prop; + fdt32_t *prop_32; + int len; + int d; + int m; + int t; + int node; + uint32_t phandle; + uint32_t cell; + + status = fdt_check_header(fdt); + rtems_test_assert(status == 0); + + size = fdt_totalsize(fdt); + rtems_test_assert(size == some_bin_size); + + alias = fdt_get_alias(fdt, "nix"); + rtems_test_assert(alias == NULL); + + alias = fdt_get_alias(fdt, "k"); + rtems_test_assert(strcmp(alias, "/m@1248") == 0); + + root = fdt_path_offset(fdt, "nix"); + rtems_test_assert(root == -FDT_ERR_BADPATH); + + root = fdt_path_offset(fdt, "/"); + rtems_test_assert(root >= 0); + + cells = fdt_address_cells(fdt, root); + rtems_test_assert(cells == 1); + + cells = fdt_size_cells(fdt, root); + rtems_test_assert(cells == 2); + + status = fdt_node_check_compatible(fdt, root, "a,b"); + rtems_test_assert(status == 0); + + status = fdt_node_check_compatible(fdt, root, "blub"); + rtems_test_assert(status == 1); + + prop = fdt_getprop(fdt, root, "model", &len); + rtems_test_assert(len == 2); + rtems_test_assert(memcmp(prop, "c", 2) == 0); + + d = fdt_subnode_offset(fdt, root, "slurf"); + rtems_test_assert(d == -FDT_ERR_NOTFOUND); + + d = fdt_subnode_offset(fdt, root, "d"); + rtems_test_assert(d >= 0); + + prop = fdt_getprop(fdt, d, "e", &len); + rtems_test_assert(len == 2); + rtems_test_assert(memcmp(prop, "f", 2) == 0); + + prop = fdt_getprop(fdt, d, "g", &len); + rtems_test_assert(len == 0); + rtems_test_assert(prop != NULL); + + m = fdt_subnode_offset(fdt, root, "m@1248"); + rtems_test_assert(m >= 0); + + t = fdt_subnode_offset(fdt, root, "t"); + rtems_test_assert(t >= 0); + + prop_32 = (fdt32_t *) fdt_getprop(fdt, t, "u", &len); + rtems_test_assert(len == 4); + phandle = fdt32_to_cpu(*prop_32); + + node = fdt_node_offset_by_phandle(fdt, phandle); + rtems_test_assert(node == m); + + prop_32 = (fdt32_t *) fdt_getprop(fdt, m, "n", &len); + rtems_test_assert(len == 8); + cell = fdt32_to_cpu(prop_32[0]); + rtems_test_assert(cell == 0xdeadbeef); + cell = fdt32_to_cpu(prop_32[1]); + rtems_test_assert(cell == 0x12345678); +} + +static void Init(rtems_task_argument arg) +{ + TEST_BEGIN(); + + test(); + + TEST_END(); + rtems_test_exit(0); +} + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_MAXIMUM_TASKS 1 + +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT + +#include diff --git a/testsuites/libtests/libfdt01/libfdt01.doc b/testsuites/libtests/libfdt01/libfdt01.doc new file mode 100644 index 0000000000..1e9ab970be --- /dev/null +++ b/testsuites/libtests/libfdt01/libfdt01.doc @@ -0,0 +1,20 @@ +This file describes the directives and concepts tested by this test set. + +test set name: libfdt01 + +directives: + + - fdt_address_cells() + - fdt_check_header() + - fdt_get_alias() + - fdt_getprop() + - fdt_node_check_compatible() + - fdt_node_offset_by_phandle() + - fdt_path_offset() + - fdt_size_cells() + - fdt_subnode_offset() + - fdt_totalsize() + +concepts: + + - Ensure that some libfdt functions work as expected. diff --git a/testsuites/libtests/libfdt01/libfdt01.scn b/testsuites/libtests/libfdt01/libfdt01.scn new file mode 100644 index 0000000000..7ea69716fe --- /dev/null +++ b/testsuites/libtests/libfdt01/libfdt01.scn @@ -0,0 +1,2 @@ +*** BEGIN OF TEST LIBFDT 1 *** +*** END OF TEST LIBFDT 1 *** diff --git a/testsuites/libtests/libfdt01/some.c b/testsuites/libtests/libfdt01/some.c new file mode 100644 index 0000000000..5eed911204 --- /dev/null +++ b/testsuites/libtests/libfdt01/some.c @@ -0,0 +1,52 @@ +/* + * Declarations for C structure representing binary file some.bin + * + * WARNING: Automatically generated -- do not edit! + */ + +#include + +const unsigned char some_bin[] = { + 0xd0, 0x0d, 0xfe, 0xed, 0x00, 0x00, 0x01, 0xd8, 0x00, 0x00, 0x00, 0x38, + 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, + 0x00, 0x00, 0x01, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x61, 0x2c, 0x62, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1a, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x26, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x09, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x01, + 0x68, 0x40, 0x30, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, + 0x68, 0x40, 0x31, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x61, 0x6c, 0x69, 0x61, + 0x73, 0x65, 0x73, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x30, 0x2f, 0x6d, 0x40, 0x31, 0x32, 0x34, 0x38, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x6d, 0x40, 0x31, 0x32, + 0x34, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x32, 0xde, 0xad, 0xbe, 0xef, 0x12, 0x34, 0x56, 0x78, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x34, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, + 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x44, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x74, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, + 0x6c, 0x65, 0x00, 0x23, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2d, + 0x63, 0x65, 0x6c, 0x6c, 0x73, 0x00, 0x23, 0x73, 0x69, 0x7a, 0x65, 0x2d, + 0x63, 0x65, 0x6c, 0x6c, 0x73, 0x00, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x00, + 0x67, 0x00, 0x77, 0x00, 0x6b, 0x00, 0x6e, 0x00, 0x6c, 0x69, 0x6e, 0x75, + 0x78, 0x2c, 0x70, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x00, 0x70, 0x00, + 0x72, 0x00, 0x75, 0x00, +}; + +const size_t some_bin_size = sizeof(some_bin); diff --git a/testsuites/libtests/libfdt01/some.dts b/testsuites/libtests/libfdt01/some.dts new file mode 100644 index 0000000000..ac15825b17 --- /dev/null +++ b/testsuites/libtests/libfdt01/some.dts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +/dts-v1/; + +/ { + compatible = "a,b"; + #address-cells = <1>; + #size-cells = <2>; + model = "c"; + + d { + e = "f"; + g; + + h@0 { + }; + + h@1 { + w = <123>; + }; + }; + + aliases { + k = "/m@1248"; + }; + + l: m@1248 { + n = <0xdeadbeef 0x12345678>; + + o { + p; + }; + + q { + r = "s"; + }; + }; + + t { + u = <&l>; + }; +}; diff --git a/testsuites/libtests/libfdt01/some.h b/testsuites/libtests/libfdt01/some.h new file mode 100644 index 0000000000..e2e0135e68 --- /dev/null +++ b/testsuites/libtests/libfdt01/some.h @@ -0,0 +1,15 @@ +/* + * Extern declarations for C structure representing binary file some.bin + * + * WARNING: Automatically generated -- do not edit! + */ + +#ifndef __some_h +#define __some_h + +#include + +extern const unsigned char some_bin[]; +extern const size_t some_bin_size; + +#endif -- cgit v1.2.3