-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework golden tests and replace bash with CMake scripts
- Loading branch information
Showing
8 changed files
with
59 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
include(${CMAKE_SOURCE_DIR}/cmake/golden-tests.cmake) | ||
include("${CMAKE_SOURCE_DIR}/cmake/add-golden-test.cmake") | ||
|
||
# Initialize "global" variables used by macros | ||
set(output_files "") | ||
add_golden_test(HelloWorld.test.cpp) | ||
target_link_libraries(Sts1CobcSwTests_HelloWorld PRIVATE rodos::rodos) | ||
|
||
set(Sts1CobcSw "${CMAKE_SOURCE_DIR}/Sts1CobcSw") | ||
add_golden_test(HelloDummy.test.cpp) | ||
target_link_libraries(Sts1CobcSwTests_HelloDummy PRIVATE rodos::rodos etl::etl Sts1CobcSw_Dummy) | ||
|
||
add_golden_test(TESTFILE "HelloWorld.test.cpp" LIB rodos::rodos) | ||
# --- All golden tests --- | ||
|
||
add_golden_test(TESTFILE "HelloDummy.test.cpp" LIB rodos::rodos etl::etl Sts1CobcSw_Dummy) | ||
|
||
add_custom_target(AllGoldenTests DEPENDS ${output_files}) | ||
get_property( | ||
all_golden_test_targets DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS | ||
) | ||
add_custom_target(AllGoldenTests) # Must be defined after getting all hardware test targets | ||
add_dependencies(AllGoldenTests ${all_golden_test_targets}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function(add_golden_test test_file) | ||
if(NOT ("${test_file}" MATCHES "\.test\.cpp$")) | ||
message(FATAL_ERROR "Name of test file `${test_file}` does not end with .test.cpp") | ||
endif() | ||
|
||
get_filename_component(test_file_name ${test_file} NAME_WE) | ||
set(target ${PROJECT_NAME}_${test_file_name}) | ||
|
||
add_executable(${target} EXCLUDE_FROM_ALL) | ||
target_sources(${target} PRIVATE "${test_file}") | ||
target_include_directories(${target} ${warning_guard} PUBLIC "${CMAKE_SOURCE_DIR}") | ||
set_target_properties(${target} PROPERTIES OUTPUT_NAME ${test_file_name}) | ||
|
||
add_test( | ||
NAME ${test_file_name} | ||
COMMAND | ||
"${CMAKE_COMMAND}" -D "TEST_EXECUTABLE=$<TARGET_FILE:${target}>" -D | ||
"EXPECTED_OUTPUT_FILE=${CMAKE_SOURCE_DIR}/Tests/GoldenTests/ExpectedOutputs/${test_file_name}.txt" | ||
-P "${CMAKE_SOURCE_DIR}/cmake/run-golden-test.cmake" | ||
) | ||
# Set a timeout in case we have deadlocks, infinite loops, etc. | ||
set_tests_properties(${test_file_name} PROPERTIES TIMEOUT 8) | ||
endfunction() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
|
||
if(NOT DEFINED TEST_EXECUTABLE) | ||
message(FATAL_ERROR "TEST_EXECUTABLE is not defined") | ||
endif() | ||
if(NOT DEFINED EXPECTED_OUTPUT_FILE) | ||
message(FATAL_ERROR "EXPECTED_OUTPUT_FILE is not defined") | ||
endif() | ||
|
||
message("Running golden test with") | ||
message(" test executable: ${TEST_EXECUTABLE}") | ||
message(" expected output file: ${EXPECTED_OUTPUT_FILE}") | ||
execute_process(COMMAND "${TEST_EXECUTABLE}" OUTPUT_VARIABLE output) | ||
|
||
set(rodos_header_regex ".*--------------- Application running ------------\n") | ||
string(REGEX REPLACE "${rodos_header_regex}" "" output_without_rodos_header ${output}) | ||
|
||
file(READ "${EXPECTED_OUTPUT_FILE}" expected_output) | ||
|
||
if(output_without_rodos_header STREQUAL expected_output) | ||
message("Test passed ✔️") | ||
else() | ||
# TODO: Upgrade CMake to version 3.29 for cmake_language(EXIT 1) | ||
message(FATAL_ERROR "Test failed ❌") | ||
endif() |