Skip to content

Commit

Permalink
Setup simulation-based testing flow (#21)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Scheremo and Moritz Scherer authored Jan 9, 2025
1 parent 242aff7 commit 99ff2fe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
44 changes: 43 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 5 additions & 4 deletions cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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=$<TARGET_FILE:${name}> +PRELMODE=${PRELOAD_MODE_INT})
endif()
endmacro()

macro(add_target_source name)
Expand All @@ -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
Expand Down

0 comments on commit 99ff2fe

Please sign in to comment.