Add verilator test compilation
This commit is contained in:
parent
74940e6dda
commit
d6f0499217
3
CMakeLists.txt
Normal file
3
CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
project(rvscc)
|
||||
|
||||
include_directories(test)
|
50
test/CMakeLists.txt
Normal file
50
test/CMakeLists.txt
Normal file
@ -0,0 +1,50 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(rvscc-tests CXX)
|
||||
|
||||
include(CTest)
|
||||
|
||||
find_package(verilator HINTS $ENV{VERILATOR_ROOT})
|
||||
if (NOT verilator_FOUND)
|
||||
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable")
|
||||
endif()
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
find_package(SystemCLanguage QUIET)
|
||||
|
||||
function(custom_add_test)
|
||||
cmake_parse_arguments(TEST
|
||||
""
|
||||
"NAME"
|
||||
"SOURCES"
|
||||
${ARGN}
|
||||
)
|
||||
set(TEST_TARGET_NAME test-${TEST_NAME})
|
||||
add_executable(${TEST_TARGET_NAME} sim_individual_test.cpp)
|
||||
verilate(${TEST_TARGET_NAME}
|
||||
SOURCES ${TEST_SOURCES}
|
||||
SYSTEMC
|
||||
VERILATOR_ARGS --timing
|
||||
)
|
||||
set_property(TARGET ${TEST_TARGET_NAME} PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD})
|
||||
verilator_link_systemc(${TEST_TARGET_NAME})
|
||||
list(GET TEST_SOURCES 0 TEST_TOP_MODULE)
|
||||
get_filename_component(TEST_TOP_MODULE_NAME ${TEST_TOP_MODULE} NAME_WE)
|
||||
target_compile_definitions(${TEST_TARGET_NAME} PRIVATE
|
||||
TEST_HEADER="V${TEST_TOP_MODULE_NAME}.h"
|
||||
TEST_CLASS=V${TEST_TOP_MODULE_NAME}
|
||||
)
|
||||
add_test(NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME})
|
||||
endfunction()
|
||||
|
||||
custom_add_test(NAME alu
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test_ALU.sv
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../rtl/ALU.sv
|
||||
)
|
||||
|
||||
custom_add_test(NAME priority-encoder
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test_PriorityEncoder.sv
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../rtl/PriorityEncoder.sv
|
||||
)
|
24
test/sim_individual_test.cpp
Normal file
24
test/sim_individual_test.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#if defined(TEST_HEADER) && defined(TEST_CLASS)
|
||||
|
||||
#include <systemc.h>
|
||||
#include <verilated.h>
|
||||
|
||||
#include TEST_HEADER
|
||||
|
||||
int sc_main(int argc, char* argv[]) {
|
||||
TEST_CLASS* top = new TEST_CLASS{"top"};
|
||||
Verilated::commandArgs(argc, argv);
|
||||
sc_start(1, SC_NS);
|
||||
while (!Verilated::gotFinish())
|
||||
sc_start(1, SC_NS);
|
||||
top->final();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int sc_main(int argc, char* argv[]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user