Add a wrapper script for running tests in ISS

This commit is contained in:
Rupert Swarbrick 2022-04-13 16:12:06 +01:00 committed by Rupert Swarbrick
parent 6dc5c0ed84
commit 9e0e0cd014
2 changed files with 87 additions and 32 deletions

View file

@ -53,8 +53,6 @@ COV := 0
SIMULATOR := vcs
# ISS (spike, ovpsim)
ISS := spike
# ISS runtime options
ISS_OPTS :=
# ISA
ISA := rv32imcb
ISA_ISS := rv32imc_Zba_Zbb_Zbc_Zbs_Xbitmanip
@ -82,12 +80,6 @@ PMP_GRANULARITY := 0
IBEX_CONFIG := opentitan
# TODO(udinator) - might need options for SAIL/Whisper/Spike
ifeq (${ISS},ovpsim)
ISS_OPTS += --override riscvOVPsim/cpu/PMP_registers=${PMP_REGIONS}
ISS_OPTS += --override riscvOVPsim/cpu/PMP_grain=${PMP_GRANULARITY}
endif
# A version of $(OUT) with a trailing '/'. The point is that this will
# never match the name of a phony targets like "sim" (which causes
# strange rebuilds otherwise). The call to $(dir ) avoids adding
@ -132,9 +124,6 @@ CSR_OPTS=--csr_yaml=${CSR_FILE} \
--isa="${ISA}" \
--end_signature_addr=${SIGNATURE_ADDR}
_RISCV_DV_OPTS=--custom_target=$(realpath riscv_dv_extension)\
--mabi=ilp32 \
# To avoid cluttering the output directory with stamp files, we place them in
# $(metadata).
metadata := $(OUT-SEED)/.metadata
@ -356,32 +345,27 @@ instr_gen_compile: $(metadata)/.instr_gen.compile_tests.stamp
#
# This (obviously) depends on having compiled the generated programs, so we
# don't have to worry about variables that affect the 'gen' stage. However, the
# ISS and ISS_OPTS variables do affect the output, so we need to dump them. See
# the 'gen' stage for more verbose explanations of how this works.
iss-var-deps := ISS ISS_OPTS
# ISS variable does affect the output, so we need to dump it. See the 'gen'
# stage for more verbose explanations of how this works.
iss-var-deps := ISS
-include $(metadata)/.iss.vars.mk
iss-vars-prereq = $(call vars-prereq,iss,running ISS,$(iss-var-deps))
ISS_COMMANDS := $(shell mktemp)
$(metadata)/.iss.run.stamp: \
$(metadata)/.instr_gen.compile_tests.stamp $(iss-vars-prereq) $(TESTLIST)
@ # Generate the commands to be run into $(ISS_COMMANDS)
$(verb)python3 ${GEN_DIR}/run.py \
--o=$(OUT-SEED)/instr_gen \
--steps=iss_sim \
${TEST_OPTS} \
--iss="${ISS}" \
--iss_opts="${ISS_OPTS}" \
--isa="${ISA_ISS}" \
${_RISCV_DV_OPTS} \
--debug $(ISS_COMMANDS) # Write all the commands to execute into here...
@ # Construct the sub-makefile from the commands, then call it
$(verb)./scripts/construct_makefile.py \
--output=$(OUT-SEED)/instr_gen/iss.mk \
--test_cmds=$(ISS_COMMANDS)
@$(MAKE) -s -f $(OUT-SEED)/instr_gen/iss.mk all
@ # Bookkeeping
$(call dump-vars,$(metadata)/.iss.vars.mk,iss,$(iss-var-deps))
$(metadata)/.instr_gen.compile_tests.stamp $(iss-vars-prereq) \
$(TESTLIST) \
scripts/construct_makefile.py scripts/run-iss.py | $(metadata)
+$(verb)scripts/run-iss.py \
$(verb-arg) \
--iss=$(ISS) \
--output=$(OUT-SEED)/instr_gen \
--isa=$(ISA_ISS) \
--test $(TEST) \
--start-seed $(SEED) \
--iterations $(ITERATIONS) \
--pmp-num-regions $(PMP_REGIONS) \
--pmp-granularity $(PMP_GRANULARITY)
@touch $@
.PHONY: iss_run

View file

@ -0,0 +1,71 @@
#!/usr/bin/env python3
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
import sys
import tempfile
import construct_makefile
from scripts_lib import start_riscv_dv_run_cmd, run_one
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--iss', required=True)
parser.add_argument('--output', required=True)
parser.add_argument('--isa', required=True)
parser.add_argument('--test', required=True)
parser.add_argument('--start-seed', type=int, required=True)
parser.add_argument('--iterations', type=int, required=True)
parser.add_argument('--pmp-num-regions', type=int, required=True)
parser.add_argument('--pmp-granularity', type=int, required=True)
args = parser.parse_args()
iss_opts = []
if args.iss == 'ovpsim':
iss_opts += ['--override',
f'riscvOVPsim/cpu/PMP_registers={args.pmp_num_regions}',
'--override',
f'riscvOVPsim/cpu/PMP_grain={args.pmp_granularity}']
output_makefile = os.path.join(args.output, 'iss.mk')
with tempfile.NamedTemporaryFile() as tf:
cmd = (start_riscv_dv_run_cmd(args.verbose) +
['--steps=iss_sim',
'--output', args.output,
'--isa', args.isa,
'--iss', args.iss,
'--test', args.test,
'--start_seed', str(args.start_seed),
'--iterations', str(args.iterations),
'--debug', tf.name])
if iss_opts:
cmd += ['--iss_opts', ' '.join(iss_opts)]
# Run riscv-dv to generate a bunch of commands
gen_retcode = run_one(args.verbose, cmd)
if gen_retcode:
return gen_retcode
# Now convert that command list to a Makefile
construct_makefile.transform(False, tf.name, output_makefile)
# Finally, run Make to run those commands
cmd = ['make', '-f', output_makefile, 'all']
if not args.verbose:
cmd.append('-s')
return run_one(args.verbose, cmd)
if __name__ == '__main__':
sys.exit(main())