From f867e7b6f42e17f30e23678bd59fd1869b1fb829 Mon Sep 17 00:00:00 2001 From: G S Niteesh Babu Date: Fri, 4 Dec 2020 13:40:47 +0530 Subject: libtests/ofw01: Added a test for RTEMS OFW This commit adds a basic test that tests all the implemented RTEMS OFW functions. --- spec/build/testsuites/libtests/grp.yml | 2 + spec/build/testsuites/libtests/ofw01.yml | 21 ++++ testsuites/libtests/ofw01/init.c | 201 +++++++++++++++++++++++++++++++ testsuites/libtests/ofw01/ofw01.doc | 29 +++++ testsuites/libtests/ofw01/ofw01.scn | 2 + testsuites/libtests/ofw01/some.c | 72 +++++++++++ testsuites/libtests/ofw01/some.dts | 76 ++++++++++++ testsuites/libtests/ofw01/some.h | 15 +++ 8 files changed, 418 insertions(+) create mode 100644 spec/build/testsuites/libtests/ofw01.yml create mode 100644 testsuites/libtests/ofw01/init.c create mode 100644 testsuites/libtests/ofw01/ofw01.doc create mode 100644 testsuites/libtests/ofw01/ofw01.scn create mode 100644 testsuites/libtests/ofw01/some.c create mode 100644 testsuites/libtests/ofw01/some.dts create mode 100644 testsuites/libtests/ofw01/some.h diff --git a/spec/build/testsuites/libtests/grp.yml b/spec/build/testsuites/libtests/grp.yml index b9ca014b0d..1aa136854a 100644 --- a/spec/build/testsuites/libtests/grp.yml +++ b/spec/build/testsuites/libtests/grp.yml @@ -316,6 +316,8 @@ links: uid: write - role: build-dependency uid: writev +- role: build-dependency + uid: ofw01 type: build use-after: - rtemstest diff --git a/spec/build/testsuites/libtests/ofw01.yml b/spec/build/testsuites/libtests/ofw01.yml new file mode 100644 index 0000000000..8517c58bad --- /dev/null +++ b/spec/build/testsuites/libtests/ofw01.yml @@ -0,0 +1,21 @@ +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: +- -Wl,--wrap=bsp_fdt_get +links: [] +source: +- testsuites/libtests/ofw01/init.c +- testsuites/libtests/ofw01/some.c +stlib: [] +target: testsuites/libtests/ofw01.exe +type: build +use-after: [] +use-before: [] diff --git a/testsuites/libtests/ofw01/init.c b/testsuites/libtests/ofw01/init.c new file mode 100644 index 0000000000..39bc30774a --- /dev/null +++ b/testsuites/libtests/ofw01/init.c @@ -0,0 +1,201 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (C) <2020> Niteesh G S + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "some.h" + +#define BUF_SIZE 100 + +const char rtems_test_name[] = "OFW 01"; +static const void *test_bin = NULL; + +const void *__wrap_bsp_fdt_get(void); +const void *__real_bsp_fdt_get(void); + +const void *__wrap_bsp_fdt_get(void) +{ + if (test_bin != NULL) { + return test_bin; + } + +#ifdef BSP_FDT_IS_SUPPORTED + return __real_bsp_fdt_get(); +#else + return some_bin; +#endif +} + +static void Init(rtems_task_argument arg) +{ + int rv; + phandle_t d; + phandle_t l; + phandle_t t; + phandle_t c; + phandle_t a; + phandle_t b; + phandle_t q; + phandle_t root; + phandle_t temp; + uint32_t *arr; + char buf[BUF_SIZE]; + char *bufp; + ssize_t buf_len; + rtems_ofw_memory_area reg; + rtems_ofw_memory_area regs[2]; + rtems_vector_number intr; + rtems_vector_number intrs[2]; + TEST_BEGIN(); + buf_len = sizeof(buf); + + /* + * Reinitializing the OFW API to use the test + * FDT instead of the original FDT. + */ + test_bin = some_bin; + rtems_ofw_init(); + + /* + * Cannot use fdt_path_offset to compare because + * the OF interface uses the offset from the ftdp + * to the node as phandle. + */ + root = rtems_ofw_find_device("/"); + rtems_test_assert(root == 56); + + root = rtems_ofw_peer(0); + rtems_test_assert(root == 56); + + d = rtems_ofw_child(root); + temp = rtems_ofw_find_device("/d"); + rtems_test_assert(d == temp); + + temp = rtems_ofw_parent(d); + rtems_test_assert(root == temp); + + rv = rtems_ofw_get_prop(d, "e", buf, buf_len); + rtems_test_assert(rv != -1); + rtems_test_assert(strcmp(buf, "f") == 0); + + rv = rtems_ofw_has_prop(d, "g"); + rtems_test_assert(rv == 1); + + rv = rtems_ofw_get_prop_len(root, "model"); + rtems_test_assert(rv == 2); + + rv = rtems_ofw_next_prop(d, "e", buf, buf_len); + rtems_test_assert(rv == 1); + rtems_test_assert(strcmp(buf, "g") == 0); + + l = rtems_ofw_find_device("/m@1248"); + rv = rtems_ofw_search_prop(l, "model", buf, buf_len); + rtems_test_assert(rv != -1); + rtems_test_assert(strcmp(buf, "c") == 0); + + rv = rtems_ofw_get_prop_alloc(root, "compatible", (void **)&bufp); + rtems_test_assert(rv != -1); + rtems_test_assert(strcmp(bufp, "a,b") == 0); + + rtems_ofw_free(bufp); + rv = rtems_ofw_get_prop_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 = rtems_ofw_get_enc_prop_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 = rtems_ofw_find_device("/t"); + rv = rtems_ofw_next_prop(t, "u", buf, buf_len); + rtems_test_assert(rv == 0); + + rv = rtems_ofw_next_prop(d, "e", buf, buf_len); + rtems_test_assert(rv == 1); + + a = rtems_ofw_find_device("/a"); + rv = rtems_ofw_get_reg(a, ®, sizeof(reg)); + rtems_test_assert(rv == 1); + rtems_test_assert(reg.start == 0x1234); + rtems_test_assert(reg.size == 0x10); + + b = rtems_ofw_find_device("/a/b"); + rv = rtems_ofw_get_reg(b, ®s[0], sizeof(regs)); + rtems_test_assert(rv == 2); + rtems_test_assert(regs[0].start == 0x8234); + rtems_test_assert(regs[0].size == 0x10); + rtems_test_assert(regs[1].start == 0xf468); + rtems_test_assert(regs[1].size == 0x10); + + c = rtems_ofw_find_device("/c"); + rv = rtems_ofw_get_reg(c, ®, sizeof(reg)); + rtems_test_assert(rv == -1); + + a = rtems_ofw_find_device("/a"); + rv = rtems_ofw_get_interrupts(a, &intr, sizeof(intr)); + rtems_test_assert(rv == 1); + rtems_test_assert(intr == 0x1); + + c = rtems_ofw_find_device("/c"); + rv = rtems_ofw_get_interrupts(c, &intrs[0], sizeof(intrs)); + rtems_test_assert(rv == 2); + rtems_test_assert(intrs[0] == 0x1); + rtems_test_assert(intrs[1] == 0x2); + + q = rtems_ofw_find_device("/c/q"); + rv = rtems_ofw_node_status(q); + rtems_test_assert(rv == true); + + 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 diff --git a/testsuites/libtests/ofw01/ofw01.doc b/testsuites/libtests/ofw01/ofw01.doc new file mode 100644 index 0000000000..6a28c847d8 --- /dev/null +++ b/testsuites/libtests/ofw01/ofw01.doc @@ -0,0 +1,29 @@ +This file describes the directives and concepts tested by this test set. + +test set name: openfirmware01 + +directives: + + - rtems_ofw_peer + - rtems_ofw_child + - rtems_ofw_parent + - rtems_ofw_get_prop_len + - rtems_ofw_get_prop + - rtems_ofw_get_enc_prop + - rtems_ofw_has_prop + - rtems_ofw_search_prop + - rtems_ofw_search_enc_prop + - rtems_ofw_get_prop_alloc + - rtems_ofw_get_prop_alloc_multi + - rtems_ofw_get_enc_prop_alloc + - rtems_ofw_get_enc_prop_alloc_multi + - rtems_ofw_free + - rtems_ofw_next_prop + - rtems_ofw_set_prop + - rtems_ofw_canon + - rtems_ofw_find_device + - rtems_ofw_package_to_path + +concepts: + + - Ensure that some openfimware functions work as expected. diff --git a/testsuites/libtests/ofw01/ofw01.scn b/testsuites/libtests/ofw01/ofw01.scn new file mode 100644 index 0000000000..007675e374 --- /dev/null +++ b/testsuites/libtests/ofw01/ofw01.scn @@ -0,0 +1,2 @@ +*** BEGIN OF TEST OFW 1 *** +*** END OF TEST OFW 1 *** \ No newline at end of file diff --git a/testsuites/libtests/ofw01/some.c b/testsuites/libtests/ofw01/some.c new file mode 100644 index 0000000000..91251e71b0 --- /dev/null +++ b/testsuites/libtests/ofw01/some.c @@ -0,0 +1,72 @@ +/* + * 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, 0x02, 0xcf, 0x00, 0x00, 0x00, 0x38, + 0x00, 0x00, 0x02, 0x70, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, + 0x00, 0x00, 0x02, 0x38, 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, 0x01, 0x6f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x71, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3e, + 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, 0x40, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x61, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x46, + 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x4d, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x62, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x42, + 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x24, 0x68, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x01, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, + 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x58, + 0x6f, 0x6b, 0x61, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 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, 0x70, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x00, + 0x70, 0x00, 0x72, 0x00, 0x75, 0x00, 0x72, 0x65, 0x67, 0x00, 0x72, 0x61, + 0x6e, 0x67, 0x65, 0x73, 0x00, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, + 0x70, 0x74, 0x73, 0x00, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00, +}; + +const size_t some_bin_size = sizeof(some_bin); diff --git a/testsuites/libtests/ofw01/some.dts b/testsuites/libtests/ofw01/some.dts new file mode 100644 index 0000000000..6ed8aeb069 --- /dev/null +++ b/testsuites/libtests/ofw01/some.dts @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2020 Niteesh G S . All rights reserved. + * 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>; + }; + + a { + compatible = "a"; + reg = <0x1234 0x10>; + ranges = <0x1000 0x8000 0x400 0x2000 0xF000 0x1000>; + interrupts = <0x1>; + + b { + reg = <0x1234 0x10 0x2468 0x10>; + }; + }; + + c { + ranges; + interrupts = <0x1 0x2 0x3>; + + q { + reg = <0x4800 0x200>; + status = "okay"; + }; + }; +}; diff --git a/testsuites/libtests/ofw01/some.h b/testsuites/libtests/ofw01/some.h new file mode 100644 index 0000000000..e2e0135e68 --- /dev/null +++ b/testsuites/libtests/ofw01/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