Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup simulation-based testing flow #21

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Xeratec marked this conversation as resolved.
Show resolved Hide resolved
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)
36 changes: 19 additions & 17 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 @@ -34,22 +36,22 @@ endmacro()
#[=======================================================================[.rst:
.. cmake:command:: add_chimera_subdirectories(target_platform, category, mappings)

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
chimera-host:
)
add_chimera_subdirectories(${TARGET_PLATFORM} "Device" "${MAPPINGS}")
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
chimera-host:
)
add_chimera_subdirectories(${TARGET_PLATFORM} "Device" "${MAPPINGS}")
Xeratec marked this conversation as resolved.
Show resolved Hide resolved

#]=======================================================================]
function(add_chimera_subdirectories target_platform category mappings)
Expand Down
Loading