Skip to content

Commit 06fd738

Browse files
nordicjmkartben
authored andcommitted
tests: cmake: Add sysbuild snippets test
Adds a new test that ensures sysbuild snippets work and are applied correctly Signed-off-by: Jamie McCrae <[email protected]>
1 parent 0711f42 commit 06fd738

File tree

12 files changed

+115
-0
lines changed

12 files changed

+115
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(test_snippets)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
menu "Zephyr"
5+
source "Kconfig.zephyr"
6+
endmenu
7+
8+
# Test values set by the snippet config overlays and tested by the test logic
9+
config TEST_FOO_VAL
10+
int "Test value"
11+
default 12
12+
help
13+
This option's value should be overridden by sysbuild.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config TEST_FOO_VAL
5+
int "Test value"
6+
default 0
7+
help
8+
This option's value should be overridden by the 'foo' snippet config overlay.
9+
10+
config EXPECTED_SB_TEST_FOO_VAL
11+
int "Expected sysbuild test value"
12+
default 999999
13+
help
14+
Expected sysbuild value for the test.
15+
16+
config EXPECTED_APP_TEST_FOO_VAL
17+
int "Expected application test value"
18+
default 999999
19+
help
20+
Expected application value for the test.
21+
22+
source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ZTEST=y
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Empty file */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
set(SNIPPET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
6+
set(sysbuild_snippets_SNIPPET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "")
7+
set(EXTRA_ZEPHYR_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/test_module" CACHE INTERNAL "test_module directory")
8+
9+
find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
11+
project(sysbuild LANGUAGES)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_TEST_FOO_VAL=18382
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SB_CONFIG_TEST_FOO_VAL=464372
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: foo
2+
append:
3+
SB_EXTRA_CONF_FILE: sb.conf
4+
EXTRA_CONF_FILE: app.conf
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake)
4+
ExternalProject_Get_Property(${DEFAULT_IMAGE} BINARY_DIR)
5+
import_kconfig(CONFIG_ ${BINARY_DIR}/zephyr/.config)
6+
7+
if("${SB_CONFIG_TEST_FOO_VAL}" STREQUAL "${CONFIG_TEST_FOO_VAL}")
8+
message(FATAL_ERROR "Values match (sysbuild and app): ${SB_CONFIG_TEST_FOO_VAL} and ${CONFIG_TEST_FOO_VAL}")
9+
else()
10+
message(NOTICE "Values diverge (sysbuild and app)")
11+
endif()
12+
13+
if("${SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL}" STREQUAL "${SB_CONFIG_TEST_FOO_VAL}")
14+
message(NOTICE "Values match (sysbuild and snippet): ${SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL} and ${SB_CONFIG_TEST_FOO_VAL}")
15+
else()
16+
message(FATAL_ERROR "Values diverge (sysbuild and snippet): ${SB_CONFIG_EXPECTED_SB_TEST_FOO_VAL} and ${SB_CONFIG_TEST_FOO_VAL}")
17+
endif()
18+
19+
if("${SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL}" STREQUAL "${CONFIG_TEST_FOO_VAL}")
20+
message(NOTICE "Values match (app and snippet): ${SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL} and ${CONFIG_TEST_FOO_VAL}")
21+
else()
22+
message(FATAL_ERROR "Values diverge (app and snippet): ${SB_CONFIG_EXPECTED_APP_TEST_FOO_VAL} and ${CONFIG_TEST_FOO_VAL}")
23+
endif()
24+
endfunction()

0 commit comments

Comments
 (0)