From 749b112fa812599594fce58dcbfeb9e5d8f254cd Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sun, 1 Aug 2021 11:59:27 +1000 Subject: [PATCH] tests: devicetree: test LINKER_DT_NODE_REGION_NAME Add a new application for testing non-core devicetree functionality. Add tests for the default and fallback case of `LINKER_DT_NODE_REGION_NAME`. Signed-off-by: Jordan Yates --- tests/lib/devicetree/api_ext/CMakeLists.txt | 9 +++++++ tests/lib/devicetree/api_ext/README | 1 + tests/lib/devicetree/api_ext/app.overlay | 29 ++++++++++++++++++++ tests/lib/devicetree/api_ext/prj.conf | 1 + tests/lib/devicetree/api_ext/src/main.c | 30 +++++++++++++++++++++ tests/lib/devicetree/api_ext/testcase.yaml | 7 +++++ 6 files changed, 77 insertions(+) create mode 100644 tests/lib/devicetree/api_ext/CMakeLists.txt create mode 100644 tests/lib/devicetree/api_ext/README create mode 100644 tests/lib/devicetree/api_ext/app.overlay create mode 100644 tests/lib/devicetree/api_ext/prj.conf create mode 100644 tests/lib/devicetree/api_ext/src/main.c create mode 100644 tests/lib/devicetree/api_ext/testcase.yaml diff --git a/tests/lib/devicetree/api_ext/CMakeLists.txt b/tests/lib/devicetree/api_ext/CMakeLists.txt new file mode 100644 index 00000000000..4a9425bab7f --- /dev/null +++ b/tests/lib/devicetree/api_ext/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(devicetree_extensions) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/lib/devicetree/api_ext/README b/tests/lib/devicetree/api_ext/README new file mode 100644 index 00000000000..48cd28c25a7 --- /dev/null +++ b/tests/lib/devicetree/api_ext/README @@ -0,0 +1 @@ +Test cases for the devicetree.h extensions (GPIO, SPI, etc). diff --git a/tests/lib/devicetree/api_ext/app.overlay b/tests/lib/devicetree/api_ext/app.overlay new file mode 100644 index 00000000000..e1b19a5e2f7 --- /dev/null +++ b/tests/lib/devicetree/api_ext/app.overlay @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021, Commonwealth Scientific and Industrial Research + * Organisation (CSIRO) ABN 41 687 119 230. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Application overlay for testing the devicetree.h extension API's. + * + * Names in this file should be chosen in a way that won't conflict + * with real-world devicetree nodes, to allow these tests to run on + * (and be extended to test) real hardware. + */ + + / { + test { + #address-cells = < 0x1 >; + #size-cells = < 0x1 >; + + test_sram1: sram@20000000 { + compatible = "mmio-sram"; + reg = < 0x20000000 0x1000 >; + zephyr,memory-region = "SRAM_REGION"; + }; + test_sram2: sram@20001000 { + compatible = "mmio-sram"; + reg = < 0x20001000 0x1000 >; + }; + }; +}; diff --git a/tests/lib/devicetree/api_ext/prj.conf b/tests/lib/devicetree/api_ext/prj.conf new file mode 100644 index 00000000000..9467c292689 --- /dev/null +++ b/tests/lib/devicetree/api_ext/prj.conf @@ -0,0 +1 @@ +CONFIG_ZTEST=y diff --git a/tests/lib/devicetree/api_ext/src/main.c b/tests/lib/devicetree/api_ext/src/main.c new file mode 100644 index 00000000000..501727b5843 --- /dev/null +++ b/tests/lib/devicetree/api_ext/src/main.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021, Commonwealth Scientific and Industrial Research + * Organisation (CSIRO) ABN 41 687 119 230. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include + +#define TEST_SRAM1 DT_NODELABEL(test_sram1) +#define TEST_SRAM2 DT_NODELABEL(test_sram2) + +static void test_linker_regions(void) +{ + zassert_true(!strcmp(LINKER_DT_NODE_REGION_NAME(TEST_SRAM1), "SRAM_REGION"), ""); + zassert_true(!strcmp(LINKER_DT_NODE_REGION_NAME(TEST_SRAM2), "/test/sram@20001000"), ""); +} + +void test_main(void) +{ + ztest_test_suite(devicetree_api_ext, + ztest_unit_test(test_linker_regions) + ); + ztest_run_test_suite(devicetree_api_ext); +} diff --git a/tests/lib/devicetree/api_ext/testcase.yaml b/tests/lib/devicetree/api_ext/testcase.yaml new file mode 100644 index 00000000000..3ac22dea78c --- /dev/null +++ b/tests/lib/devicetree/api_ext/testcase.yaml @@ -0,0 +1,7 @@ +tests: + libraries.devicetree_ext: + tags: devicetree + # We only need this to run on one platform so use native_posix as it + # will mostly likely be the fastest. + integration_platforms: + - native_posix