From 99ff2fea14ed1b4269b6e4b0495d638b99c3f42d Mon Sep 17 00:00:00 2001 From: MoritzScherer Date: Thu, 9 Jan 2025 09:47:29 +0100 Subject: [PATCH] Setup simulation-based testing flow (#21) * Split away testing, setup simulation variables * Rename Simulation Binary to SoC Model Binary * Add VALID_TEST_MODES list * Fix message * Reenable test building, switch add_test logic * Fix formatting --------- Co-authored-by: Moritz Scherer --- CMakeLists.txt | 44 +++++++++++++++++++++++++++++++++++++++++++- cmake/Utils.cmake | 9 +++++---- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c8404e..efa9936 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,48 @@ add_subdirectory(drivers) ################################################################################ # Testing # ################################################################################ -enable_testing() + +set(VALID_TEST_MODES "simulation" "none") + +# Option for TEST_MODE with default value +option(TEST_MODE "Set what validation target the tests should be run on" "none") + +# Check if TEST_MODE is set to a valid option +if(NOT TEST_MODE IN_LIST VALID_TEST_MODES) + # Collect all error messages into a single string + set(error_messages "") + list(APPEND error_messages "[CHIMERA-SDK] Invalid TEST_MODE: ${TEST_MODE}") + list(APPEND error_messages "[CHIMERA-SDK] Available options for TEST_MODE are:") + foreach(mode IN LISTS VALID_TEST_MODES) + list(APPEND error_messages " - ${mode}") + endforeach() + + # Convert the list of messages into a single multi-line string + list(JOIN error_messages "\n" error_message) + + # Raise fatal error with all messages + message(FATAL_ERROR "${error_message}") +endif() + +set(SOC_MODEL_BINARY "chim.bin" CACHE STRING "Path to the simulation binary") +set(PRELOAD_MODE "0" CACHE STRING "Preload mode for simulation") + +if (TEST_MODE STREQUAL "simulation") + enable_testing() + + if(NOT EXISTS ${SOC_MODEL_BINARY}) + message(FATAL_ERROR "SoC model binary ${SOC_MODEL_BINARY} does not exist.") + endif() + + # Convert PRELOAD_MODE to integer + if ("${PRELOAD_MODE}" MATCHES "^[0-9]+$") + set(PRELOAD_MODE_INT ${PRELOAD_MODE}) + else() + message(FATAL_ERROR "PRELOAD_MODE must be an integer.") + endif() + + message(STATUS "[CHIMERA-SDK] SoC Model Binary : ${SOC_MODEL_BINARY}") + message(STATUS "[CHIMERA-SDK] Preload Mode : ${PRELOAD_MODE}") +endif() add_subdirectory(tests) diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index cbd9d6b..b053e4c 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -15,7 +15,9 @@ endmacro() ## TODO: Add vsim target or some such macro(add_chimera_test name) add_chimera_executable(${ARGV}) - add_test(NAME ${name} COMMAND ${name}) + if(TEST_MODE STREQUAL "simulation") + add_test(NAME ${name} COMMAND ${SIMULATION_BINARY} +BINARY=$ +PRELMODE=${PRELOAD_MODE_INT}) + endif() endmacro() macro(add_target_source name) @@ -36,14 +38,13 @@ endmacro() Add subdirectories based on a mapping of target platforms to folders. The mappings are expected to be in the format ``target_platform:folder1,folder2,...``. - :param target_platform: The target platform to build for. :param category: The category of the subdirectories. :param mappings: A list of mappings from target platforms to folders. Make sure to wrap the list in quotes! - + .. code-block:: cmake :caption: Example Usage - + set(MAPPINGS chimera-convolve:snitch_cluster chimera-open:snitch_cluster