diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b94585e70..1050435c3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -208,6 +208,19 @@ smoke-hwconfig: - source verif/regress/hwconfig_tests.sh - python3 .gitlab-ci/scripts/report_pass.py +hello-pk: + extends: + - .fe_smoke_test + variables: + DASHBOARD_JOB_TITLE: "Hello world with riscv-pk on cv64a6_imafdc_sv39" + DASHBOARD_JOB_DESCRIPTION: "Short tests to challenge target configurations" + DASHBOARD_SORT_INDEX: 1 + DASHBOARD_JOB_CATEGORY: "Basic" + COLLECT_SIMU_LOGS: 1 + script: + - bash verif/regress/hello-veri-testharness-pk-cv64a6_imafdc_sv39.sh + - !reference [.simu_after_script] + .synthesis_test: stage: heavy tests timeout: 2 hours diff --git a/verif/regress/hello-verilator-pk-cv64a6_imafdc_sv39.sh b/verif/regress/hello-verilator-pk-cv64a6_imafdc_sv39.sh new file mode 100644 index 000000000..6301ee27d --- /dev/null +++ b/verif/regress/hello-verilator-pk-cv64a6_imafdc_sv39.sh @@ -0,0 +1,39 @@ +# Make sure to source this script from the root directory +# to correctly set the environment variables related to the tools + +# Set the NUM_JOBS variable to increase the number of parallel make jobs +# export NUM_JOBS= +# where are the tools +if ! [ -n "$RISCV" ]; then + echo "Error: RISCV variable undefined" + return +fi + +TIMEOUT_WALLCLOCK="600" +TIMEOUT_TICKS="2100000" +export DV_SIMULATORS="veri-testharness-pk" +export DV_TARGET="cv64a6_imafdc_sv39" +export PK_ARCH="rv64gc_zba_zbb_zbs_zbc" +export PK_MABI="ilp64d" + +if [[ "$DV_SIMULATORS" == *"veri-testharness"* ]]; then + source ./verif/regress/install-verilator.sh +fi + +if [[ "$DV_SIMULATORS" == *"veri-testharness-pk"* ]]; then + + echo "[ riscv-pk ] veri-testharness-pk simulation detected. Installing RISC-V proxy kernel..." + source ./verif/regress/install-pk.sh ${PK_ARCH} ${PK_MABI} > ./verif/sim/pk-install.log 2>&1 + echo "[ riscv-pk ] RISC-V proxy kernel installation logs at $(pwd)/verif/sim/pk-install.log" + echo "[ riscv-pk ] PK_INSTALL_DIR is ${PK_INSTALL_DIR}" +fi + +source ./verif/sim/setup-env.sh +cd ./verif/sim + +CC_OPTS="" + +python3 cva6.py --target $DV_TARGET --iss=$DV_SIMULATORS --iss_yaml=cva6.yaml --iss_timeout=$TIMEOUT_WALLCLOCK \ +--c_tests ../tests/custom/hello_world/hello_world.c \ +--gcc_opts="$CC_OPTS" \ +--issrun_opts="+time_out=$TIMEOUT_TICKS" diff --git a/verif/regress/install-pk.sh b/verif/regress/install-pk.sh new file mode 100755 index 000000000..9248dfee7 --- /dev/null +++ b/verif/regress/install-pk.sh @@ -0,0 +1,83 @@ +# This script installs RISCV proxy kernel at ${ROOT_PROJECT}/tools/pk, +# where ROOT_PROJECT is base of the CVA6 repository. +#!/bin/bash +PK_ARCH=$1 +PK_MABI=$2 +PK_REPO="https://github.com/riscv-software-src/riscv-pk.git" +PK_BRANCH="master" +PK_COMMIT_HASH="e5563d1044bd6790325c4602c49f89e1182fa91a" + +if ! [ -n "$RISCV" ]; then + echo "Error: RISCV variable undefined" + return +fi +PATH=$RISCV/bin:$PATH +CLEAN_INSTALL="1" +# Customise this to a fast local disk +ROOT_PROJECT=$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../) + +if [ -z "$NUM_JOBS" ]; then + NUM_JOBS=1 +fi + +#PK_PATCH="$ROOT_PROJECT/verif/regress/pk.patch" + +# Unset historical variable PK_ROOT as it collides with the build process. +if [ -n "$PK_ROOT" ]; then + unset PK_ROOT +fi + +echo "[install-pk.sh] Entry values:" +echo " PK_BUILD_DIR='$PK_BUILD_DIR'" +echo " PK_INSTALL_DIR='$PK_INSTALL_DIR'" + +# If not set, define the installation location of pk to the local path +# +# /tools/pk +# +# Continuous Integration may need to override this particular variable +# to use a preinstalled build of Verilator. +if [ -z "$PK_INSTALL_DIR" ]; then + export PK_INSTALL_DIR="$ROOT_PROJECT/tools/pk" + echo "Setting PK_INSTALL_DIR to '$PK_INSTALL_DIR'..." +fi + +# Define the default src+build location of pk in case it needs to be (re)built. +# No need to force this location in Continuous Integration scripts. +if [ -z "$PK_BUILD_DIR" ]; then + export PK_BUILD_DIR="$PK_INSTALL_DIR/build-pk" + echo "Setting PK_BUILD_DIR to '$PK_BUILD_DIR'..." +fi + +echo "Cleaning $PK_INSTALL_DIR" +rm -rf $PK_INSTALL_DIR + +# Build and install pk only if not already installed at the expected +# location $PK_INSTALL_DIR. +if [ ! -f "$PK_INSTALL_DIR/riscv-none-elf/bin/pk" ]; then + echo "Building pk in '$PK_BUILD_DIR'..." + echo "pk will be installed in '$PK_INSTALL_DIR'" + echo "PK_REPO=$PK_REPO" + echo "PK_BRANCH=$PK_BRANCH" + echo "NUM_JOBS=$NUM_JOBS" + mkdir -p $PK_BUILD_DIR + pushd $PK_BUILD_DIR + # Fetch repository only if the ".git" directory does not exist. + # Do not remove the content arbitrarily if ".git" does not exist in order + # to preserve user content - let git fail instead. + [ -d .git ] || git clone --depth=1 --branch ${PK_BRANCH} ${PK_REPO} . && git checkout ${PK_COMMIT_HASH} +# [ -d .git ] || git init && git remote add origin ${PK_REPO} && git fetch --depth=1 origin ${PK_COMMIT_HASH} && git reset --hard FETCH_HEAD + mkdir -p build + pushd build + ../configure --prefix="$PK_INSTALL_DIR" --host=riscv-none-elf --with-arch=$PK_ARCH + make + make install + popd + popd +else + echo "pk already installed in '$PK_INSTALL_DIR'." +fi + +# Add pk bin directory to PATH if not already present. +echo $PATH | grep -q "$PK_INSTALL_DIR/bin:" || \ + export PATH="$PK_INSTALL_DIR/bin:$PATH" diff --git a/verif/sim/Makefile b/verif/sim/Makefile index 1a71754c0..f3a96d41c 100644 --- a/verif/sim/Makefile +++ b/verif/sim/Makefile @@ -411,6 +411,22 @@ vcs-testharness: $(tool_path)/spike-dasm --isa=$(variant) < ./trace_rvfi_hart_00.dasm > $(log) grep $(isspostrun_opts) ./trace_rvfi_hart_00.dasm +veri-testharness-pk: + rm -rf $(path_var)/work-ver + @echo "Trace compact value $(TRACE_COMPACT)" + make -C $(path_var) verilate verilator="verilator --no-timing" target=$(target) defines=$(subst +define+,,$(isscomp_opts)) + $(path_var)/work-ver/Variane_testharness $(if $(TRACE_COMPACT), -f verilator.fst) $(if $(TRACE_FAST), -v verilator.vcd) \ + $(PK_INSTALL_DIR)/riscv-none-elf/bin/pk $(elf) \ + +tohost_addr=$(shell $$RISCV/bin/$(CV_SW_PREFIX)nm -B $(PK_INSTALL_DIR)/riscv-none-elf/bin/pk | grep -w tohost | cut -d' ' -f1) \ + $(issrun_opts) + # If present, move default waveform files to log directory. + # Keep track of target in waveform file name. + [ ! -f verilator.fst ] || mv verilator.fst `dirname $(log)`/`basename $(log) .log`.fst + [ ! -f verilator.vcd ] || mv verilator.vcd `dirname $(log)`/`basename $(log) .log`.vcd + # Generate disassembled log. + $(tool_path)/spike-dasm --isa=$(variant) < ./trace_rvfi_hart_00.dasm > $(log) + grep $(isspostrun_opts) ./trace_rvfi_hart_00.dasm + veri-testharness: make -C $(path_var) verilate verilator="verilator --no-timing" target=$(target) defines=$(subst +define+,,$(isscomp_opts)) $(path_var)/work-ver/Variane_testharness $(if $(TRACE_COMPACT), -f verilator.fst) $(if $(TRACE_FAST), -v verilator.vcd) $(elf) $(issrun_opts) \ diff --git a/verif/sim/cva6.py b/verif/sim/cva6.py index 4c5075ec8..fb456be14 100644 --- a/verif/sim/cva6.py +++ b/verif/sim/cva6.py @@ -508,13 +508,18 @@ def run_test(test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir, if test_type != "o": # gcc compilation logging.info("Compiling test: %s" % test_path) - cmd = ("%s %s \ - -I%s/dv/user_extension \ - -T%s %s -o %s " % \ - (get_env_var("RISCV_CC", debug_cmd = debug_cmd), test_path, cwd, - linker, gcc_opts, elf)) + if "veri-testharness-pk" not in iss_list: + + cmd = ("%s %s \ + -I%s/dv/user_extension \ + -T%s %s -o %s " % \ + (get_env_var("RISCV_CC", debug_cmd = debug_cmd), test_path, cwd, + linker, gcc_opts, elf)) + else: # veri-testharness with proxy kernel enabled. + cmd= ("%s %s %s -o %s " % (get_env_var("RISCV_CC", debug_cmd = debug_cmd), test_path, gcc_opts, elf)) cmd += (" -march=%s" % isa) cmd += (" -mabi=%s" % mabi) + logging.info("Compilation cmd: %s" % cmd) run_cmd(cmd, debug_cmd = debug_cmd) log_list = [] # ISS simulation diff --git a/verif/sim/cva6.yaml b/verif/sim/cva6.yaml index 601129602..5286f2494 100644 --- a/verif/sim/cva6.yaml +++ b/verif/sim/cva6.yaml @@ -30,6 +30,16 @@ cmd: > make veri-testharness target= variant= elf= path_var= tool_path= isscomp_opts= issrun_opts= isspostrun_opts= log= +############################################################################### +# Verilator with RISCV proxy kernel support +############################################################################### +- iss: veri-testharness-pk + path_var: RTL_PATH + tool_path: SPIKE_PATH + tb_path: TB_PATH + cmd: > + make veri-testharness-pk target= variant= elf= path_var= tool_path= isscomp_opts= issrun_opts= isspostrun_opts= log= + ############################################################################### # Synopsys VCS specific commands, variables ###############################################################################