tests: cmake: run zephyr_get() tests in script mode

Re-run the zephyr_get() testsuite in script mode after the project
mode testsuite has been executed. This is to ensure that the
zephyr_get() function works correctly in script mode as well.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit is contained in:
Luca Burelli 2024-12-16 16:47:22 +01:00 committed by Benjamin Cabé
parent 4e29a35b22
commit d492c849a3

View file

@ -2,9 +2,17 @@
cmake_minimum_required(VERSION 3.20.0) cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) if(CMAKE_SCRIPT_MODE_FILE)
project(zephyr_get_test) # Script mode initialization (re-run)
target_sources(app PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c) set(ZEPHYR_BASE ${CMAKE_CURRENT_LIST_DIR}/../../../)
list(APPEND CMAKE_MODULE_PATH "${ZEPHYR_BASE}/cmake/modules")
include(extensions)
else()
# Project mode initialization (main CMake invocation)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(zephyr_get_test)
target_sources(app PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c)
endif()
if(SYSBUILD) if(SYSBUILD)
get_property(IMAGE_NAME TARGET sysbuild_cache PROPERTY SYSBUILD_NAME) get_property(IMAGE_NAME TARGET sysbuild_cache PROPERTY SYSBUILD_NAME)
@ -73,6 +81,9 @@ function(assert_equal variable expected_value)
endif() endif()
set(info "${TEST_NAME}: ${variable} == '${actual_value}'") set(info "${TEST_NAME}: ${variable} == '${actual_value}'")
if(CMAKE_SCRIPT_MODE_FILE)
string(PREPEND info "script mode ")
endif()
if("${actual_value}" STREQUAL "${expected_value}") if("${actual_value}" STREQUAL "${expected_value}")
message("PASS: ${info}") message("PASS: ${info}")
else() else()
@ -584,3 +595,8 @@ run_suite(
test_merge_reverse test_merge_reverse
test_snippets_scope test_snippets_scope
) )
if (NOT CMAKE_SCRIPT_MODE_FILE AND NOT SYSBUILD)
# Re-run this testsuite in plain script mode
execute_process(COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_FILE})
endif()