Skip to content

Commit

Permalink
Adding Simple Framework for Creating Test ELFs (#29)
Browse files Browse the repository at this point in the history
Created a framework for building RISC-V assembly tests for testing
Atlas. The framework uses magic memory to end simulation, which has not
been implemented in Atlas yet, so the `stop_sim_on_wfi` parameter is
required for these tests to end properly.

Created ELFs used in Atlas's regression should be checked in to the
`test/sim/workloads`dir.
  • Loading branch information
kathlenemagnus authored Dec 20, 2024
1 parent 72b5f08 commit 974ebda
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 15 deletions.
33 changes: 18 additions & 15 deletions sim/atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include "sparta/app/CommandLineSimulator.hpp"

const char USAGE[] = "TODO"
const char USAGE[] = "Usage:\n"
"./atlas [-i inst limit] <workload>"
"\n";

int main(int argc, char** argv)
Expand Down Expand Up @@ -49,28 +50,30 @@ int main(int argc, char** argv)
return err_code; // Any errors already printed to cerr
}

if (workload.empty())
{
std::cerr << "ERROR: Missing a workload to run. Provide an ELF or JSON to run"
<< std::endl;
std::cerr << USAGE;
return -1;
}

// Create the simulator
sparta::Scheduler scheduler;
atlas::AtlasSim sim(&scheduler, workload, ilimit);

cls.populateSimulation(&sim);

cls.runSimulator(&sim);
if (workload.empty() == false)
{
cls.runSimulator(&sim);

cls.postProcess(&sim);
cls.postProcess(&sim);

// Get workload exit code
const atlas::AtlasState::SimState* sim_state = sim.getAtlasState()->getSimState();
exit_code = sim_state->workload_exit_code;
std::cout << "Workload exit code: " << std::dec << exit_code << std::endl;
// Get workload exit code
const atlas::AtlasState::SimState* sim_state = sim.getAtlasState()->getSimState();
exit_code = sim_state->workload_exit_code;
std::cout << "Workload exit code: " << std::dec << exit_code << std::endl;
}
else
{
std::cout << "ERROR: Missing a workload to run. Provide an ELF or JSON to run"
<< std::endl;
std::cout << USAGE;
return 0;
}
}
catch (...)
{
Expand Down
45 changes: 45 additions & 0 deletions test/elfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.27.6)

project(riscv_assembly_tests ASM)

# Unset these variables to prevent include of Mac SDK
set(CMAKE_OSX_SYSROOT "/")
set(CMAKE_OSX_DEPLOYMENT_TARGET "")

if(NOT RISCV_TOOLCHAIN)
message(FATAL_ERROR "You must supply a -DRISCV_TOOLCHAIN=/path")
else()
message("-- Using RISCV_TOOLCHAIN: ${RISCV_TOOLCHAIN}")
if(EXISTS ${RISCV_TOOLCHAIN}/bin/riscv64-unknown-elf-as)
set(CMAKE_ASM_COMPILER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-elf-as")
set(CMAKE_C_COMPILER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-elf-gcc")
set(CMAKE_CXX_COMPILER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-elf-g++")
set(CMAKE_LINKER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-elf-ld")
elseif(EXISTS ${RISCV_TOOLCHAIN}//bin/riscv64-unknown-linux-gnu-as)
set(CMAKE_ASM_COMPILER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-as")
set(CMAKE_C_COMPILER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-g++")
set(CMAKE_LINKER "${RISCV_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-ld")
else()
message(FATAL_ERROR "Cannot find tools in the given RISCV_TOOLCHAIN")
endif()
endif()

set(BASE_DIR ${PROJECT_SOURCE_DIR})

# Don't test compilers. The riscv toolchain's linker does not support the option '-search_paths_first'
set(CMAKE_C_COMPILER_WORKS 1)
#set(CMAKE_C_FLAGS "-march=rv64gc")
#set(CMAKE_LINK_C_FLAGS "")
set(CMAKE_CXX_COMPILER_WORKS 1)
#set(CMAKE_CXX_FLAGS "-march=rv64gc")
#set(CMAKE_LINK_CXX_FLAGS "")

# Linker setup
set(LINKER_SCRIPT ${BASE_DIR}/common/main.ld)
set(CMAKE_ASM_LINKER_FLAGS "-T ${LINKER_SCRIPT} -e main")
set(CMAKE_ASM_LINK_EXECUTABLE "${CMAKE_LINKER} ${CMAKE_ASM_LINKER_FLAGS} <OBJECTS> -o <TARGET>")

include_directories(common)

add_subdirectory(src)
7 changes: 7 additions & 0 deletions test/elfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Build directions:
```
mkdir build
cd build
cmake .. -DRISCV_TOOLCHAIN=<path to the install of RISCV toolsuite>
make
```
25 changes: 25 additions & 0 deletions test/elfs/common/TEST_TEMPLATE.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Test: [test name]
* ISA: [isa string required]
* Description: [description of test]
*/

.include "host.s"
.include "macros.s"

.section .text
.global main

// Insert your test in main
main:

// Jump or fall through here if test is successful
pass:
test_pass

// Jump here if test is unsuccessful
fail:
test_fail

.section .data
data:
.fill 64, 4, 0xFFFFFFFF
8 changes: 8 additions & 0 deletions test/elfs/common/host.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.section .tohost,"aw"
.globl tohost
.globl fromhost

tohost:
.dword 0
fromhost:
.dword 0
26 changes: 26 additions & 0 deletions test/elfs/common/macros.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Test: nop.elf
* ISA: rv64i
* Description: Stream of nops.
*/

.macro test_pass
li x1, 1
la x2, tohost
sw x1, 0(x2)
wfi
.endm

.macro test_fail
li x1, 2
la x2, tohost
sw x1, 0(x2)
wfi
.endm

.macro start_tracepoint
xor x0, x0, x0
.endm

.macro stop_tracepoint
xor x0, x1, x1
.endm
13 changes: 13 additions & 0 deletions test/elfs/common/main.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
OUTPUT_ARCH("riscv")

SECTIONS
{
. = 0x80000000;
.text : { *(.text) }
. = ALIGN(0x1000);
.tohost : { *(.tohost) }
. = ALIGN(0x1000);
.data : { *(.data) }
. = ALIGN(0x1000);
.bss : { *(.bss) }
}
Binary file added test/elfs/src/.DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions test/elfs/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project (BASE_TESTS)

set (CMAKE_ASM_FLAGS "-march=rv64i_zicsr_zifencei")

add_subdirectory (nop)
3 changes: 3 additions & 0 deletions test/elfs/src/nop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project(nop_test)

add_executable (nop.elf nop.s)
25 changes: 25 additions & 0 deletions test/elfs/src/nop/nop.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Test: nop.elf
* ISA: rv64i
* Description: Stream of nops.
*/

.include "host.s"
.include "macros.s"

.section .text
.global main

main:
.rept 1000
nop
.endr

pass:
test_pass

fail:
test_fail

.section .data
data:
.fill 64, 4, 0xFFFFFFFF

0 comments on commit 974ebda

Please sign in to comment.