From e17e463cf3f3724076a6997c3894a6c158fcf8bd Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Wed, 20 Sep 2023 09:36:32 +0200 Subject: [PATCH] adds script to run UCB riscv tests --- CMakeLists.txt | 8 ++++- dbt-rise-core | 2 +- dbt-rise-tgc | 2 +- run_riscv_tests.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100755 run_riscv_tests.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d08810..e23e903 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ if(CMAKE_PROJECT_NAME STREQUAL "TGFS-ISS") ########################################################################### set(CORE_NAME TGC5C CACHE STRING "The core to build the ISS for" ) option(FW_BUILD "Enable the automatic download and build of some firmware to run on the ISS" OFF) + option(ENABLE_SANITIZER "Enable address sanitizer" OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -34,7 +35,12 @@ if(CMAKE_PROJECT_NAME STREQUAL "TGFS-ISS") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(warnings "/W4 /WX /EHsc") endif() - + if(ENABLE_SANITIZER) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") + endif() include(GNUInstallDirs) include(ConanInline) if(BUILD_SHARED_LIBS) diff --git a/dbt-rise-core b/dbt-rise-core index 22a0503..d18b6a6 160000 --- a/dbt-rise-core +++ b/dbt-rise-core @@ -1 +1 @@ -Subproject commit 22a0503f2ebe36fa44a5ef1c86950e2dc621848c +Subproject commit d18b6a6fd4f7ef0304378cbefb2ab1dd11689e6a diff --git a/dbt-rise-tgc b/dbt-rise-tgc index 8ee3ac9..de45d06 160000 --- a/dbt-rise-tgc +++ b/dbt-rise-tgc @@ -1 +1 @@ -Subproject commit 8ee3ac90f72176d0bbdfe10e43ab251f629c7d37 +Subproject commit de45d068782e0bd7960dedced11c7ea041a13639 diff --git a/run_riscv_tests.sh b/run_riscv_tests.sh new file mode 100755 index 0000000..e1b2ee4 --- /dev/null +++ b/run_riscv_tests.sh @@ -0,0 +1,89 @@ +#!/bin/bash +## + +# Absolute path to this script, e.g. /home/user/bin/foo.sh +SCRIPT=`readlink -f "$0"` +# Absolute path this script is in, thus /home/user/bin +SCRIPTDIR=`dirname "$SCRIPT"` +SCRIPTNAME=`basename "$SCRIPT"` +function print_help { + echo "Usage: $SCRIPTNAME [-b ] [-s ]}" + echo "Run UCB risc-v compliance test suite on backends" + echo "Optional cli arguments:" + echo " -b backend type, default all" + echo " -s simulator arguments" + echo " -h print help" + echo " -v increase verbosity" +} +SIM_ARGS="-v1" +BACKENDS=("interp" "tcc" "llvm") +DEBUG=0 +BUILD_TYPE=Debug +while getopts 'b:s:hv' c +do + case $c in + b) BACKENDS=($OPTARG);; + s) SIM_ARGS=$OPTARG ;; + h) print_help; exit 0 ;; + v) DEBUG=1 ;; + ?) + print_help >&2 + exit 1 + ;; + esac +done + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +ROOT_DIR=$DIR + +RISCV_TEST=$ROOT_DIR/build/riscv-tests +# prepare riscv-test binaries +if [ ! -d $RISCV_TEST ]; then + mkdir -p $ROOT_DIR/build; cd $ROOT_DIR/build + git clone --recursive https://github.com/riscv/riscv-tests.git + cd $RISCV_TEST + autoconf + ./configure --with-xlen=32 + cd $ROOT_DIR + make -C $RISCV_TEST -j -k +fi +# check that we have an executable +RISCV_EXE=$ROOT_DIR/build/${BUILD_TYPE}/dbt-rise-tgc/tgc-sim +if [ ! -x $RISCV_EXE ]; then + mkdir -p build/${BUILD_TYPE} + echo "running cmake -B build/${BUILD_TYPE} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DWITH_TCC=ON -DWITH_LLVM=ON " + cmake -S . -B build/${BUILD_TYPE} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DWITH_TCC=ON -DWITH_LLVM=ON ../.. || exit 1 + cmake --build build/${BUILD_TYPE} -j 20 || exit 1 +fi + +test_ui_list=`find ${RISCV_TEST}/isa -type f -name rv32ui-p-\* -executable | grep -v fence | grep -v ma_data |sort` +test_uc_list=`find ${RISCV_TEST}/isa -type f -name rv32uc-p-\* -executable | grep -v fence | sort` +test_um_list=`find ${RISCV_TEST}/isa -type f -name rv32um-p-\* -executable | grep -v fence | sort` +test_list="$test_ui_list $test_uc_list $test_um_list $test_mmode_list" + +for backend in "${BACKENDS[@]}"; do + failed_list=() + for elf in $test_list; do + [ $DEBUG -eq 0 ] || echo Running "${RISCV_EXE} $SIM_ARGS -f $elf --backend $backend" + ${RISCV_EXE} $SIM_ARGS -f $elf --backend $backend + if [ $? != 0 ]; then + failed_list+="$backend:$elf " + fi + done + tcount=`echo $test_list | wc -w` + if [ ! -z "$failed_list" ]; then + fcount=`echo $failed_list | wc -w` + echo "($backend) $fcount of $tcount test(s) failed:" + echo $failed_list | tr ' ' '\n' + else + echo + echo "($backend) $tcount tests passed." + if [ $DEBUG -eq 1 ];then + echo "List of executed tests:" + for t in $test_list; do + name=`basename $t` + echo " $name" + done + fi + fi +done