From 06fd7389bd6ad8e53e404b2c47c6b75476b0e86b Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 4 Jun 2024 08:52:55 +0100 Subject: [PATCH] tests: cmake: Add sysbuild snippets test Adds a new test that ensures sysbuild snippets work and are applied correctly Signed-off-by: Jamie McCrae --- tests/cmake/sysbuild_snippets/CMakeLists.txt | 9 +++++++ tests/cmake/sysbuild_snippets/Kconfig | 13 ++++++++++ .../cmake/sysbuild_snippets/Kconfig.sysbuild | 22 +++++++++++++++++ tests/cmake/sysbuild_snippets/prj.conf | 1 + tests/cmake/sysbuild_snippets/src/main.c | 7 ++++++ .../sysbuild_snippets/sysbuild/CMakeLists.txt | 11 +++++++++ .../sysbuild/snippets/foo/app.conf | 1 + .../sysbuild/snippets/foo/sb.conf | 1 + .../sysbuild/snippets/foo/snippet.yml | 4 ++++ .../sysbuild/test_module/CMakeLists.txt | 24 +++++++++++++++++++ .../sysbuild/test_module/zephyr/module.yml | 2 ++ tests/cmake/sysbuild_snippets/testcase.yaml | 20 ++++++++++++++++ 12 files changed, 115 insertions(+) create mode 100644 tests/cmake/sysbuild_snippets/CMakeLists.txt create mode 100644 tests/cmake/sysbuild_snippets/Kconfig create mode 100644 tests/cmake/sysbuild_snippets/Kconfig.sysbuild create mode 100644 tests/cmake/sysbuild_snippets/prj.conf create mode 100644 tests/cmake/sysbuild_snippets/src/main.c create mode 100644 tests/cmake/sysbuild_snippets/sysbuild/CMakeLists.txt create mode 100644 tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/app.conf create mode 100644 tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/sb.conf create mode 100644 tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/snippet.yml create mode 100644 tests/cmake/sysbuild_snippets/sysbuild/test_module/CMakeLists.txt create mode 100644 tests/cmake/sysbuild_snippets/sysbuild/test_module/zephyr/module.yml create mode 100644 tests/cmake/sysbuild_snippets/testcase.yaml diff --git a/tests/cmake/sysbuild_snippets/CMakeLists.txt b/tests/cmake/sysbuild_snippets/CMakeLists.txt new file mode 100644 index 00000000000..119768d9537 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_snippets) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/cmake/sysbuild_snippets/Kconfig b/tests/cmake/sysbuild_snippets/Kconfig new file mode 100644 index 00000000000..d8e1822ed3e --- /dev/null +++ b/tests/cmake/sysbuild_snippets/Kconfig @@ -0,0 +1,13 @@ +# Copyright 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +menu "Zephyr" +source "Kconfig.zephyr" +endmenu + +# Test values set by the snippet config overlays and tested by the test logic +config TEST_FOO_VAL + int "Test value" + default 12 + help + This option's value should be overridden by sysbuild. diff --git a/tests/cmake/sysbuild_snippets/Kconfig.sysbuild b/tests/cmake/sysbuild_snippets/Kconfig.sysbuild new file mode 100644 index 00000000000..e3691432511 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/Kconfig.sysbuild @@ -0,0 +1,22 @@ +# Copyright 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config TEST_FOO_VAL + int "Test value" + default 0 + help + This option's value should be overridden by the 'foo' snippet config overlay. + +config EXPECTED_SB_TEST_FOO_VAL + int "Expected sysbuild test value" + default 999999 + help + Expected sysbuild value for the test. + +config EXPECTED_APP_TEST_FOO_VAL + int "Expected application test value" + default 999999 + help + Expected application value for the test. + +source "${ZEPHYR_BASE}/share/sysbuild/Kconfig" diff --git a/tests/cmake/sysbuild_snippets/prj.conf b/tests/cmake/sysbuild_snippets/prj.conf new file mode 100644 index 00000000000..9467c292689 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/prj.conf @@ -0,0 +1 @@ +CONFIG_ZTEST=y diff --git a/tests/cmake/sysbuild_snippets/src/main.c b/tests/cmake/sysbuild_snippets/src/main.c new file mode 100644 index 00000000000..eed3a0cb003 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/src/main.c @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Empty file */ diff --git a/tests/cmake/sysbuild_snippets/sysbuild/CMakeLists.txt b/tests/cmake/sysbuild_snippets/sysbuild/CMakeLists.txt new file mode 100644 index 00000000000..5cac9b45dbf --- /dev/null +++ b/tests/cmake/sysbuild_snippets/sysbuild/CMakeLists.txt @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SNIPPET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") +set(sysbuild_snippets_SNIPPET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "") +set(EXTRA_ZEPHYR_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/test_module" CACHE INTERNAL "test_module directory") + +find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(sysbuild LANGUAGES) diff --git a/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/app.conf b/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/app.conf new file mode 100644 index 00000000000..4d2cb023f49 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/app.conf @@ -0,0 +1 @@ +CONFIG_TEST_FOO_VAL=18382 diff --git a/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/sb.conf b/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/sb.conf new file mode 100644 index 00000000000..8b7106584df --- /dev/null +++ b/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/sb.conf @@ -0,0 +1 @@ +SB_CONFIG_TEST_FOO_VAL=464372 diff --git a/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/snippet.yml b/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/snippet.yml new file mode 100644 index 00000000000..327ed603052 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/sysbuild/snippets/foo/snippet.yml @@ -0,0 +1,4 @@ +name: foo +append: + SB_EXTRA_CONF_FILE: sb.conf + EXTRA_CONF_FILE: app.conf diff --git a/tests/cmake/sysbuild_snippets/sysbuild/test_module/CMakeLists.txt b/tests/cmake/sysbuild_snippets/sysbuild/test_module/CMakeLists.txt new file mode 100644 index 00000000000..152ea609fc9 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/sysbuild/test_module/CMakeLists.txt @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: Apache-2.0 + +function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake) + ExternalProject_Get_Property(${DEFAULT_IMAGE} BINARY_DIR) + import_kconfig(CONFIG_ ${BINARY_DIR}/zephyr/.config) + + if("${SB_CONFIG_TEST_FOO_VAL}" STREQUAL "${CONFIG_TEST_FOO_VAL}") + message(FATAL_ERROR "Values match (sysbuild and app): ${SB_CONFIG_TEST_FOO_VAL} and ${CONFIG_TEST_FOO_VAL}") + else() + message(NOTICE "Values diverge (sysbuild and app)") + endif() + + if("${SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL}" STREQUAL "${SB_CONFIG_TEST_FOO_VAL}") + message(NOTICE "Values match (sysbuild and snippet): ${SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL} and ${SB_CONFIG_TEST_FOO_VAL}") + else() + message(FATAL_ERROR "Values diverge (sysbuild and snippet): ${SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL} and ${SB_CONFIG_TEST_FOO_VAL}") + endif() + + if("${SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL}" STREQUAL "${CONFIG_TEST_FOO_VAL}") + message(NOTICE "Values match (app and snippet): ${SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL} and ${CONFIG_TEST_FOO_VAL}") + else() + message(FATAL_ERROR "Values diverge (app and snippet): ${SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL} and ${CONFIG_TEST_FOO_VAL}") + endif() +endfunction() diff --git a/tests/cmake/sysbuild_snippets/sysbuild/test_module/zephyr/module.yml b/tests/cmake/sysbuild_snippets/sysbuild/test_module/zephyr/module.yml new file mode 100644 index 00000000000..ba6d2fc1696 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/sysbuild/test_module/zephyr/module.yml @@ -0,0 +1,2 @@ +build: + sysbuild-cmake: . diff --git a/tests/cmake/sysbuild_snippets/testcase.yaml b/tests/cmake/sysbuild_snippets/testcase.yaml new file mode 100644 index 00000000000..0c1dd5c70e6 --- /dev/null +++ b/tests/cmake/sysbuild_snippets/testcase.yaml @@ -0,0 +1,20 @@ +common: + sysbuild: true + tags: sysbuild_snippets sysbuild + platform_allow: + - native_sim + integration_platforms: + - native_sim + +tests: + # Test the initial state with no snippets applied + buildsystem.sysbuild.snippets.none: + extra_args: + - SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL=0 + - SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL=12 + # Test the `foo` snippet in sysbuild + buildsystem.sysbuild.snippets.applied: + extra_args: + - SNIPPET=foo + - SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL=464372 + - SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL=18382