Skip to content

Commit

Permalink
[tests] Improved test infrastructure
Browse files Browse the repository at this point in the history
- Make clear what is host code and what is cluster code
  • Loading branch information
Xeratec committed Nov 29, 2024
1 parent 6488731 commit d4aa93e
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 49 deletions.
18 changes: 5 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
27 changes: 19 additions & 8 deletions tests/generic/host/returnZero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@
# Moritz Scherer <[email protected]>
# Philip Wiese <[email protected]>

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)
File renamed without changes.
43 changes: 36 additions & 7 deletions tests/generic/snitchCluster/simpleOffload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,47 @@
# Moritz Scherer <[email protected]>
# Philip Wiese <[email protected]>

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)
16 changes: 16 additions & 0 deletions tests/generic/snitchCluster/simpleOffload/include/test_cluster.h
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

#ifndef _TEST_CLUSTER_INCLUDE_GUARD_
#define _TEST_CLUSTER_INCLUDE_GUARD_

#include <stdint.h>

void clusterInterruptHandler();

int32_t testReturn(void *args);

#endif //_TEST_CLUSTER_INCLUDE_GUARD_
16 changes: 16 additions & 0 deletions tests/generic/snitchCluster/simpleOffload/include/test_host.h
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

#ifndef _TEST_HOST_INCLUDE_GUARD_
#define _TEST_HOST_INCLUDE_GUARD_

#define TESTVAL 0x050CCE55

typedef struct {
int value;
} offloadArgs_t;

#endif //_TEST_HOST_INCLUDE_GUARD_
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
//
// Moritz Scherer <[email protected]>

#include "soc.h"
#include "driver.h"

#include <stddef.h>
#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
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
23 changes: 23 additions & 0 deletions tests/generic/snitchCluster/simpleOffload/src_host/test_host.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

#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));
}

0 comments on commit d4aa93e

Please sign in to comment.