On 29/07/2020 18:07, Gedare Bloom wrote: > On Wed, Jul 15, 2020 at 12:32 AM G S Niteesh Babu <niteesh...@gmail.com> > wrote: >> >> --- >> spec/build/testsuites/libtests/grp.yml | 3 + >> .../testsuites/libtests/openfirmware01.yml | 20 +++ >> testsuites/libtests/openfirmware01/init.c | 147 ++++++++++++++++++ >> .../openfirmware01/openfirmware01.doc | 29 ++++ >> .../openfirmware01/openfirmware01.scn | 2 + >> testsuites/libtests/openfirmware01/some.c | 52 +++++++ >> testsuites/libtests/openfirmware01/some.dts | 54 +++++++ >> testsuites/libtests/openfirmware01/some.h | 15 ++ >> 8 files changed, 322 insertions(+) >> create mode 100644 spec/build/testsuites/libtests/openfirmware01.yml >> create mode 100644 testsuites/libtests/openfirmware01/init.c >> create mode 100644 testsuites/libtests/openfirmware01/openfirmware01.doc >> create mode 100644 testsuites/libtests/openfirmware01/openfirmware01.scn >> create mode 100644 testsuites/libtests/openfirmware01/some.c >> create mode 100644 testsuites/libtests/openfirmware01/some.dts >> create mode 100644 testsuites/libtests/openfirmware01/some.h >> >> diff --git a/spec/build/testsuites/libtests/grp.yml >> b/spec/build/testsuites/libtests/grp.yml >> index f1de6cd75f..56e84d2c89 100644 >> --- a/spec/build/testsuites/libtests/grp.yml >> +++ b/spec/build/testsuites/libtests/grp.yml >> @@ -11,6 +11,7 @@ install: [] >> ldflags: >> - -Wl,--wrap=printf >> - -Wl,--wrap=puts >> +- -Wl,--wrap=bsp_fdt_get >> links: >> - role: build-dependency >> uid: optbin2c >> @@ -312,6 +313,8 @@ links: >> uid: write >> - role: build-dependency >> uid: writev >> +- role: build-dependency >> + uid: openfirmware01 >> type: build >> use-after: >> - rtemstest >> diff --git a/spec/build/testsuites/libtests/openfirmware01.yml >> b/spec/build/testsuites/libtests/openfirmware01.yml >> new file mode 100644 >> index 0000000000..8feb69eb1e >> --- /dev/null >> +++ b/spec/build/testsuites/libtests/openfirmware01.yml >> @@ -0,0 +1,20 @@ >> +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause >> +build-type: test-program >> +cflags: [] >> +copyrights: >> +- Copyright (C) 2020 Niteesh G S >> +cppflags: [] >> +cxxflags: [] >> +enabled-by: true >> +features: c cprogram >> +includes: [] >> +ldflags: [] >> +links: [] >> +source: >> +- testsuites/libtests/openfirmware01/init.c >> +- testsuites/libtests/openfirmware01/some.c >> +stlib: [] >> +target: testsuites/libtests/openfirmware01.exe >> +type: build >> +use-after: [] >> +use-before: [] >> diff --git a/testsuites/libtests/openfirmware01/init.c >> b/testsuites/libtests/openfirmware01/init.c >> new file mode 100644 >> index 0000000000..fc38e6c513 >> --- /dev/null >> +++ b/testsuites/libtests/openfirmware01/init.c >> @@ -0,0 +1,147 @@ >> +/* SPDX-License-Identifier: BSD-2-Clause */ >> + >> +/* >> + * Copyright (C) <2020> Niteesh G S <niteesh...@gmail.com> >> + * >> + * Redistribution and use in source and binary forms, with or without >> + * modification, are permitted provided that the following conditions >> + * are met: >> + * 1. Redistributions of source code must retain the above copyright >> + * notice, this list of conditions and the following disclaimer. >> + * 2. Redistributions in binary form must reproduce the above copyright >> + * notice, this list of conditions and the following disclaimer in the >> + * documentation and/or other materials provided with the distribution. >> + * >> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS >> IS" >> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >> PURPOSE >> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >> THE >> + * POSSIBILITY OF SUCH DAMAGE. >> + */ >> + >> +#ifdef HAVE_CONFIG_H >> +#include "config.h" >> +#endif >> + >> +#include <tmacros.h> >> +#include <stdio.h> >> +#include <stdlib.h> >> +#include <libfdt.h> >> +#include <sys/endian.h> >> +#include <dev/ofw/openfirm.h> >> + >> +#include "some.h" >> + >> +#define BUF_SIZE 100 >> + >> +const char rtems_test_name[] = "OpenFirmWare 01"; >> + >> +const void *__wrap_bsp_fdt_get(void); >> +const void *__real_bsp_fdt_get(void); >> + >> +const void *__wrap_bsp_fdt_get(void) >> +{ >> + if (some_bin != NULL) { >> + return &some_bin[0]; >> + } >> + return __real_bsp_fdt_get(); >> +} >> + >> +static void Init(rtems_task_argument arg) >> +{ >> + int rv; >> + phandle_t d; >> + phandle_t l; >> + phandle_t t; >> + phandle_t root; >> + phandle_t temp; >> + uint32_t *arr; >> + char buf[BUF_SIZE]; >> + char *bufp; >> + ssize_t buf_len; >> + >> + TEST_BEGIN(); >> + buf_len = sizeof(buf); >> + >> + /* >> + * Cannot use fdt_path_offset to compare because >> + * the OF interface uses the offset from the ftdp >> + * to the node as phandle. >> + */ >> + root = OF_finddevice("/"); >> + rtems_test_assert(root == 56); >> + >> + root = OF_peer(0); >> + rtems_test_assert(root == 56); >> + >> + d = OF_child(root); >> + temp = OF_finddevice("/d"); >> + rtems_test_assert(d == temp); >> + >> + temp = OF_parent(d); >> + rtems_test_assert(root == temp); >> + >> + rv = OF_getprop(d, "e", buf, buf_len); >> + rtems_test_assert(rv != -1); >> + rtems_test_assert(strcmp(buf, "f") == 0); >> + >> + rv = OF_hasprop(d, "g"); >> + rtems_test_assert(rv == 1); >> + >> + rv = OF_getproplen(root, "model"); >> + rtems_test_assert(rv == 2); >> + >> + rv = OF_nextprop(d, "e", buf, buf_len); >> + rtems_test_assert(rv == 1); >> + rtems_test_assert(strcmp(buf, "g") == 0); >> + >> + l = OF_finddevice("/m@1248"); >> + rv = OF_searchprop(l, "model", buf, buf_len); >> + rtems_test_assert(rv != -1); >> + rtems_test_assert(strcmp(buf, "c") == 0); >> + >> + rv = OF_getprop_alloc(root, "compatible", (void **)&bufp); >> + rtems_test_assert(rv != -1); >> + rtems_test_assert(strcmp(bufp, "a,b") == 0); >> + OF_prop_free(bufp); >> + >> + rv = OF_getprop_alloc_multi(l, "n", sizeof(*arr), (void **)&arr); >> + rtems_test_assert(rv == 2); >> + rtems_test_assert(arr[0] == htobe32(0xdeadbeef)); >> + rtems_test_assert(arr[1] == htobe32(0x12345678)); >> + >> + rv = OF_getencprop_alloc_multi(l, "n", sizeof(*arr), (void **)&arr); >> + rtems_test_assert(rv == 2); >> + rtems_test_assert(arr[0] == 0xdeadbeef); >> + rtems_test_assert(arr[1] == 0x12345678); >> + >> + t = OF_finddevice("/t"); >> + rv = OF_nextprop(t, "u", buf, buf_len); >> + rtems_test_assert(rv == 0); >> + >> + rv = OF_nextprop(d, "e", buf, buf_len); >> + rtems_test_assert(rv == 1); >> + > > ok, so these are intended to be application-visible. The interface is > not standard though, as far as I know. So, I think we need to ensure > we provide an RTEMS-friendly namespace for this OF API, and make sure > the header files are properly arranged for visibility/layering. > > Everything else seems fine to me in a quick glance.
Hello Gedare, the interface is ported from FreeBSD. It's an internal one in FreeBSD but I think it is useful for application drivers too. What would you suggest regarding the namespace. I'm not a big fan of changing imported FreeBSD code. Best regards Christian > >> + TEST_END(); >> + >> + rtems_test_exit(0); >> +} >> + >> +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER >> +#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_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 <rtems/confdefs.h> >> \ No newline at end of file >> diff --git a/testsuites/libtests/openfirmware01/openfirmware01.doc >> b/testsuites/libtests/openfirmware01/openfirmware01.doc >> new file mode 100644 >> index 0000000000..a9d2085798 >> --- /dev/null >> +++ b/testsuites/libtests/openfirmware01/openfirmware01.doc >> @@ -0,0 +1,29 @@ >> +This file describes the directives and concepts tested by this test set. >> + >> +test set name: openfirmware01 >> + >> +directives: >> + >> + - OF_peer >> + - OF_child >> + - OF_parent >> + - OF_getproplen >> + - OF_getprop >> + - OF_getencprop >> + - OF_hasprop >> + - OF_searchprop >> + - OF_searchencprop >> + - OF_getprop_alloc >> + - OF_getprop_alloc_multi >> + - OF_getencprop_alloc >> + - OF_getencprop_alloc_multi >> + - OF_prop_free >> + - OF_nextprop >> + - OF_setprop >> + - OF_canon >> + - OF_finddevice >> + - OF_package_to_path >> + >> +concepts: >> + >> + - Ensure that some openfimware functions work as expected. >> diff --git a/testsuites/libtests/openfirmware01/openfirmware01.scn >> b/testsuites/libtests/openfirmware01/openfirmware01.scn >> new file mode 100644 >> index 0000000000..38abbdfc45 >> --- /dev/null >> +++ b/testsuites/libtests/openfirmware01/openfirmware01.scn >> @@ -0,0 +1,2 @@ >> +*** BEGIN OF TEST OPENFIRMWARE 1 *** >> +*** END OF TEST OPENFIRMWARE 1 *** >> diff --git a/testsuites/libtests/openfirmware01/some.c >> b/testsuites/libtests/openfirmware01/some.c >> new file mode 100644 >> index 0000000000..5eed911204 >> --- /dev/null >> +++ b/testsuites/libtests/openfirmware01/some.c >> @@ -0,0 +1,52 @@ >> +/* >> + * Declarations for C structure representing binary file some.bin >> + * >> + * WARNING: Automatically generated -- do not edit! >> + */ >> + >> +#include <sys/types.h> >> + >> +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/openfirmware01/some.dts >> b/testsuites/libtests/openfirmware01/some.dts >> new file mode 100644 >> index 0000000000..ac15825b17 >> --- /dev/null >> +++ b/testsuites/libtests/openfirmware01/some.dts >> @@ -0,0 +1,54 @@ >> +/* >> + * Copyright (c) 2015 embedded brains GmbH. All rights reserved. >> + * >> + * embedded brains GmbH >> + * Dornierstr. 4 >> + * 82178 Puchheim >> + * Germany >> + * <rt...@embedded-brains.de> >> + * >> + * 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/openfirmware01/some.h >> b/testsuites/libtests/openfirmware01/some.h >> new file mode 100644 >> index 0000000000..e2e0135e68 >> --- /dev/null >> +++ b/testsuites/libtests/openfirmware01/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 <sys/types.h> >> + >> +extern const unsigned char some_bin[]; >> +extern const size_t some_bin_size; >> + >> +#endif >> -- >> 2.17.1 >> > _______________________________________________ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel > _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel