Skip to content

Commit

Permalink
tests: cmake: run zephyr_get() tests in script mode
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pillo79 committed Dec 16, 2024
1 parent 96b1fb9 commit 8a6052c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/cmake/zephyr_get/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(zephyr_get_test)
target_sources(app PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c)
if(CMAKE_SCRIPT_MODE_FILE)
# Script mode initialization (re-run)
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)
get_property(IMAGE_NAME TARGET sysbuild_cache PROPERTY SYSBUILD_NAME)
Expand Down Expand Up @@ -73,6 +81,9 @@ function(assert_equal variable expected_value)
endif()

set(info "${TEST_NAME}: ${variable} == '${actual_value}'")
if(CMAKE_SCRIPT_MODE_FILE)
string(PREPEND info "script mode ")
endif()
if("${actual_value}" STREQUAL "${expected_value}")
message("PASS: ${info}")
else()
Expand Down Expand Up @@ -583,3 +594,8 @@ run_suite(
test_merge_reverse
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()

0 comments on commit 8a6052c

Please sign in to comment.