libtests/ofw01: Added a test for RTEMS OFW

This commit adds a basic test that tests all the implemented
RTEMS OFW functions.
This commit is contained in:
G S Niteesh Babu
2020-12-04 13:40:47 +05:30
committed by Christian Mauderer
parent 9d2ed41fcb
commit f867e7b6f4
8 changed files with 418 additions and 0 deletions

View File

@@ -316,6 +316,8 @@ links:
uid: write
- role: build-dependency
uid: writev
- role: build-dependency
uid: ofw01
type: build
use-after:
- rtemstest

View File

@@ -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: []

View File

@@ -0,0 +1,201 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (C) <2020> Niteesh G S <niteesh.gs@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 <bsp/fdt.h>
#include <ofw/ofw.h>
#include <ofw/ofw_test.h>
#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, &reg, 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, &regs[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, &reg, 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 <rtems/confdefs.h>

View File

@@ -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.

View File

@@ -0,0 +1,2 @@
*** BEGIN OF TEST OFW 1 ***
*** END OF TEST OFW 1 ***

View File

@@ -0,0 +1,72 @@
/*
* 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, 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);

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2020 Niteesh G S <niteesh.gs@gmail.com>. All rights reserved.
* Copyright (c) 2015 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@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>;
};
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";
};
};
};

View File

@@ -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