From d4aa93e3896ef03730ca02eebab7cff24bcd16bf Mon Sep 17 00:00:00 2001 From: Philip Wiese Date: Fri, 29 Nov 2024 16:43:09 +0100 Subject: [PATCH] [tests] Improved test infrastructure - Make clear what is host code and what is cluster code --- CMakeLists.txt | 18 +++----- tests/generic/host/returnZero/CMakeLists.txt | 27 ++++++++---- .../{src/test.c => src_host/test_host.c} | 0 .../simpleOffload/CMakeLists.txt | 43 ++++++++++++++++--- .../simpleOffload/include/test_cluster.h | 16 +++++++ .../simpleOffload/include/test_host.h | 16 +++++++ .../test.c => src_cluster/test_cluster.c} | 34 ++++++--------- .../simpleOffload/src_host/test_host.c | 23 ++++++++++ 8 files changed, 128 insertions(+), 49 deletions(-) rename tests/generic/host/returnZero/{src/test.c => src_host/test_host.c} (100%) create mode 100644 tests/generic/snitchCluster/simpleOffload/include/test_cluster.h create mode 100644 tests/generic/snitchCluster/simpleOffload/include/test_host.h rename tests/generic/snitchCluster/simpleOffload/{src/test.c => src_cluster/test_cluster.c} (71%) create mode 100644 tests/generic/snitchCluster/simpleOffload/src_host/test_host.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d3e99fc..8f51b25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,14 +34,12 @@ set(ABI_HOST ilp32) set(ISA_CLUSTER_SNITCH rv32im) set(ABI_CLUSTER_SNITCH ilp32) -include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils.cmake) +message(STATUS "[CHIMERA-SDK] ISA_HOST : ${ISA_HOST}") +message(STATUS "[CHIMERA-SDK] ABI_HOST : ${ABI_HOST}") +message(STATUS "[CHIMERA-SDK] ISA_CLUSTER_SNITCH : ${ISA_CLUSTER_SNITCH}") +message(STATUS "[CHIMERA-SDK] ABI_CLUSTER_SNITCH : ${ABI_CLUSTER_SNITCH}") -# WIESEP: With the current flow the cluster ISA has to be part of the host ISA -# use isa_includes to check this -set(ISA_IS_SUBSET isa_includes(${ISA_HOST} ${ISA_CLUSTER_SNITCH})) -if(NOT ISA_IS_SUBSET) - message(FATAL_ERROR "Cluster ISA ${ISA_CLUSTER_SNITCH} is not included in host ISA ${ISA_HOST}") -endif() +include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils.cmake) # WIESEP: Add a object library to collect all runtime sources add_library(runtime STATIC) @@ -75,12 +73,6 @@ add_library(chimera-sdk INTERFACE) target_link_libraries(chimera-sdk INTERFACE hal) target_link_libraries(chimera-sdk INTERFACE runtime) -# WIESEP: Expose cluster ISA and ABI to avoid offloading issues -target_compile_options(chimera-sdk INTERFACE - -march=${ISA_CLUSTER_SNITCH} - -mabi=${ABI_CLUSTER_SNITCH} -) - enable_testing() add_subdirectory(tests) diff --git a/tests/generic/host/returnZero/CMakeLists.txt b/tests/generic/host/returnZero/CMakeLists.txt index 55ba665..6bb87aa 100644 --- a/tests/generic/host/returnZero/CMakeLists.txt +++ b/tests/generic/host/returnZero/CMakeLists.txt @@ -5,19 +5,30 @@ # Moritz Scherer # Philip Wiese -file(GLOB_RECURSE TEST_SRCS - "src/test.c" -) +set(TEST_NAME test_host_returnZero) -add_chimera_test( - test_host_returnZero - ${TEST_SRCS} +######## HOST Code ############################################################# +file(GLOB_RECURSE TEST_HOST_SRCS + "src_host/*.c" ) -target_compile_options(test_host_returnZero +add_library(${TEST_NAME}_host OBJECT ${TEST_HOST_SRCS}) +# target_include_directories(${TEST_NAME}_host PUBLIC include) + +# WIESEP: Set the correct ISA and ABI for the host +target_compile_options(${TEST_NAME}_host PRIVATE -O2 + -march=${ISA_HOST} + -mabi=${ABI_HOST} ) +target_link_libraries(${TEST_NAME}_host PUBLIC chimera-sdk) -target_link_libraries(test_host_returnZero PUBLIC chimera-sdk) +######## TEST Executable ####################################################### +add_chimera_test( + ${TEST_NAME} +) + +# WIESEP: Link the host to the test executable (chimera-sdk is already linked) +target_link_libraries(${TEST_NAME} PUBLIC ${TEST_NAME}_host) diff --git a/tests/generic/host/returnZero/src/test.c b/tests/generic/host/returnZero/src_host/test_host.c similarity index 100% rename from tests/generic/host/returnZero/src/test.c rename to tests/generic/host/returnZero/src_host/test_host.c diff --git a/tests/generic/snitchCluster/simpleOffload/CMakeLists.txt b/tests/generic/snitchCluster/simpleOffload/CMakeLists.txt index f77c56b..60f9b4c 100644 --- a/tests/generic/snitchCluster/simpleOffload/CMakeLists.txt +++ b/tests/generic/snitchCluster/simpleOffload/CMakeLists.txt @@ -5,18 +5,47 @@ # Moritz Scherer # Philip Wiese -file(GLOB_RECURSE TEST_SRCS - "src/test.c" +set(TEST_NAME test_snitchCluster_simpleOffload) + +######## HOST Code ############################################################# +file(GLOB_RECURSE TEST_HOST_SRCS + "src_host/*.c" ) -add_chimera_test( - test_snitchCluster_simpleOffload - ${TEST_SRCS} +add_library(${TEST_NAME}_host OBJECT ${TEST_HOST_SRCS}) +target_include_directories(${TEST_NAME}_host PUBLIC include) + +# WIESEP: Set the correct ISA and ABI for the host +target_compile_options(${TEST_NAME}_host + PRIVATE + -O2 + -march=${ISA_HOST} + -mabi=${ABI_HOST} ) +target_link_libraries(${TEST_NAME}_host PUBLIC chimera-sdk) -target_compile_options(test_snitchCluster_simpleOffload +######## CLUSTER Code ########################################################## +file(GLOB_RECURSE TEST_SNITCH_SRCS + "src_cluster/*.c" +) + +add_library(${TEST_NAME}_cluster OBJECT ${TEST_SNITCH_SRCS}) +target_include_directories(${TEST_NAME}_cluster PUBLIC include) + +# WIESEP: Set the correct ISA and ABI for the cluster +target_compile_options(${TEST_NAME}_cluster PRIVATE -O2 + -march=${ISA_CLUSTER_SNITCH} + -mabi=${ABI_CLUSTER_SNITCH} +) +target_link_libraries(${TEST_NAME}_cluster PUBLIC chimera-sdk) + +######## TEST Executable ####################################################### +add_chimera_test( + ${TEST_NAME} ) -target_link_libraries(test_snitchCluster_simpleOffload PUBLIC chimera-sdk) +# WIESEP: Link the host and cluster code to the test executable (chimera-sdk is already linked) +target_link_libraries(${TEST_NAME} PUBLIC ${TEST_NAME}_host) +target_link_libraries(${TEST_NAME} PUBLIC ${TEST_NAME}_cluster) diff --git a/tests/generic/snitchCluster/simpleOffload/include/test_cluster.h b/tests/generic/snitchCluster/simpleOffload/include/test_cluster.h new file mode 100644 index 0000000..c92c3cf --- /dev/null +++ b/tests/generic/snitchCluster/simpleOffload/include/test_cluster.h @@ -0,0 +1,16 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Philip Wiese + +#ifndef _TEST_CLUSTER_INCLUDE_GUARD_ +#define _TEST_CLUSTER_INCLUDE_GUARD_ + +#include + +void clusterInterruptHandler(); + +int32_t testReturn(void *args); + +#endif //_TEST_CLUSTER_INCLUDE_GUARD_ diff --git a/tests/generic/snitchCluster/simpleOffload/include/test_host.h b/tests/generic/snitchCluster/simpleOffload/include/test_host.h new file mode 100644 index 0000000..ac214ef --- /dev/null +++ b/tests/generic/snitchCluster/simpleOffload/include/test_host.h @@ -0,0 +1,16 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Philip Wiese + +#ifndef _TEST_HOST_INCLUDE_GUARD_ +#define _TEST_HOST_INCLUDE_GUARD_ + +#define TESTVAL 0x050CCE55 + +typedef struct { + int value; +} offloadArgs_t; + +#endif //_TEST_HOST_INCLUDE_GUARD_ diff --git a/tests/generic/snitchCluster/simpleOffload/src/test.c b/tests/generic/snitchCluster/simpleOffload/src_cluster/test_cluster.c similarity index 71% rename from tests/generic/snitchCluster/simpleOffload/src/test.c rename to tests/generic/snitchCluster/simpleOffload/src_cluster/test_cluster.c index e3de20a..ffaff19 100644 --- a/tests/generic/snitchCluster/simpleOffload/src/test.c +++ b/tests/generic/snitchCluster/simpleOffload/src_cluster/test_cluster.c @@ -4,17 +4,18 @@ // // Moritz Scherer -#include "soc.h" -#include "driver.h" - -#include +#include "test_cluster.h" +#include "test_host.h" -#define TESTVAL 0x050CCE55 -#define STACK_ADDRESS (CLUSTER_4_BASE + 0x20000 - 8) +#include "soc.h" static uint32_t *clintPointer = (uint32_t *)CLINT_CTRL_BASE; -// WIESEP: Stack, thread and global pointer might not yet be set up! +/** + * @brief Interrupt handler for the cluster, which clears the interrupt flag for the current hart. + * + * @warning Stack, thread and global pointer might not yet be set up! + */ __attribute__((naked)) void clusterInterruptHandler() { asm volatile( // Load global pointer @@ -42,12 +43,11 @@ __attribute__((naked)) void clusterInterruptHandler() { ); } -typedef struct { - int value; -} offloadArgs_t; - -static offloadArgs_t offloadArgs = {.value = 0xdeadbeef}; - +/** + * @brief Main function of the cluster test. + * + * @return int Return 0 if the test was successful, -1 otherwise. + */ int32_t testReturn(void *args) { // Cast to the correct struct offloadArgs_t *argsStruct = (offloadArgs_t *)args; @@ -58,12 +58,4 @@ int32_t testReturn(void *args) { } return TESTVAL; -} - -int main() { - setup_snitchCluster_interruptHandler(clusterInterruptHandler); - offload_snitchCluster_core(testReturn, &offloadArgs, (void *)(STACK_ADDRESS), 4, 0); - uint32_t retVal = wait_snitchCluster_return(4); - - return (retVal != (TESTVAL | 0x000000001)); } \ No newline at end of file diff --git a/tests/generic/snitchCluster/simpleOffload/src_host/test_host.c b/tests/generic/snitchCluster/simpleOffload/src_host/test_host.c new file mode 100644 index 0000000..f0d38de --- /dev/null +++ b/tests/generic/snitchCluster/simpleOffload/src_host/test_host.c @@ -0,0 +1,23 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Moritz Scherer + +#include "test_cluster.h" +#include "test_host.h" + +#include "soc.h" +#include "driver.h" + +#define STACK_ADDRESS (CLUSTER_4_BASE + 0x20000 - 8) + +static offloadArgs_t offloadArgs = {.value = 0xdeadbeef}; + +int main() { + setup_snitchCluster_interruptHandler(clusterInterruptHandler); + offload_snitchCluster_core(testReturn, &offloadArgs, (void *)(STACK_ADDRESS), 4, 0); + uint32_t retVal = wait_snitchCluster_return(4); + + return (retVal != (TESTVAL | 0x000000001)); +} \ No newline at end of file