Skip to content

Commit 8f7a323

Browse files
Merge pull request #1256 from jordancarlin/fcov_lockstep
Refactor functional coverage
2 parents 76b22e9 + 79ec595 commit 8f7a323

File tree

9 files changed

+150
-126
lines changed

9 files changed

+150
-126
lines changed

bin/regression-wally

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,14 @@ def addTestsByDir(testDir, config, sim, coverStr, configs, lockstepMode=0, breke
318318
sim_logdir = f"{regressionDir}/{sim}/logs/"
319319
cmdPrefix = f"wsim --sim {sim} {coverStr} {'--lockstep' if lockstepMode else ''} {config}"
320320
# fcov/ccov only runs on WALLY-COV-ALL.elf files; other lockstep runs on all files
321-
fileStart = "WALLY-COV-ALL" if "cvw-arch-verif/tests" in testDir and "priv" not in testDir and (coverStr == "--fcov" or coverStr == "--ccov") else ""
321+
fileStart = "WALLY-COV-ALL" if "cvw-arch-verif/tests" in testDir and "priv" not in testDir else ""
322322
fileEnd = ".elf"
323-
if lockstepMode or coverStr == "--fcov":
323+
if lockstepMode:
324324
gs = "Mismatches : 0"
325325
elif brekerMode:
326326
gs="# trek: info: summary: Test PASSED"
327+
elif coverStr == "--fcov":
328+
gs = "Functional coverage test complete."
327329
else:
328330
gs = "Single Elf file tests are not signatured verified."
329331
for dirpath, _, filenames in os.walk(os.path.abspath(testDir)):

bin/wsim

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def parseArgs():
2727
parser.add_argument("--tb", "-t", help="Testbench", choices=["testbench", "testbench_fp"], default="testbench")
2828
parser.add_argument("--gui", "-g", help="Simulate with GUI", action="store_true")
2929
parser.add_argument("--ccov", "-c", help="Code Coverage", action="store_true")
30-
parser.add_argument("--fcov", "-f", help="Functional Coverage with cvw-arch-verif, implies lockstep", action="store_true")
30+
parser.add_argument("--fcov", "-f", help="Functional Coverage with cvw-arch-verif", action="store_true")
3131
parser.add_argument("--args", "-a", help="Optional arguments passed to simulator via $value$plusargs", default="")
3232
parser.add_argument("--params", "-p", help="Optional top-level parameter overrides of the form param=value", default="")
3333
parser.add_argument("--define", "-d", help="Optional define macros passed to simulator", default="")
@@ -41,8 +41,8 @@ def validateArgs(args):
4141
if not args.testsuite and not args.elf:
4242
print("Error: Missing test suite or ELF file")
4343
sys.exit(1)
44-
if any([args.lockstep, args.lockstepverbose, args.fcov]) and not (args.testsuite.endswith(".elf") or args.elf) and args.testsuite != "buildroot":
45-
print(f"Invalid Options. Cannot run a testsuite, {args.testsuite} with lockstep or fcov. Must run a single elf or buildroot.")
44+
if (args.lockstep or args.lockstepverbose) and not (args.testsuite.endswith(".elf") or args.elf) and args.testsuite != "buildroot":
45+
print(f"Invalid Options. Cannot run a testsuite, {args.testsuite} with lockstep. Must run a single elf or buildroot.")
4646
sys.exit(1)
4747
elif any([args.gui, args.ccov, args.fcov, args.lockstep, args.lockstepverbose]) and args.sim not in ["questa", "vcs"]:
4848
print("Option only supported for Questa and VCS")
@@ -101,13 +101,11 @@ def prepSim(args, ElfFile):
101101
flagsList.append("--ccov")
102102
if args.fcov:
103103
flagsList.append("--fcov")
104-
defineList.extend(["+define+INCLUDE_TRACE2COV", "+define+IDV_INCLUDE_TRACE2COV", "+define+COVER_BASE_RV32I"]) # COVER_BASE_RV32I is just needed to keep riscvISACOV happy, but does not affect tests
105-
argsList.extend(["+TRACE2COV_ENABLE=1", "+IDV_TRACE2COV=1"])
104+
defineList.append("+define+FCOV")
106105
if args.gui:
107106
flagsList.append("--gui")
108107
if args.lockstep or args.lockstepverbose:
109108
flagsList.append("--lockstep")
110-
if args.lockstep or args.lockstepverbose or args.fcov:
111109
prefix = lockstepSetup(args)
112110
defineList.append("+define+USE_IMPERAS_DV")
113111
if args.config == "breker": # Requires a license for the breker tool. See tests/breker/README.md for details
@@ -154,7 +152,6 @@ def runQuesta(args, flags, prefix):
154152
args.params = fr'--params \"{args.params}\"'
155153
if args.define:
156154
args.define = fr'--define \"{args.define}\"'
157-
# fcov implies lockstep
158155
cmd = f"do wally.do {args.config} {args.testsuite} {args.tb} {args.args} {args.params} {args.define} {flags}"
159156
cmd = f'cd $WALLY/sim/questa; {prefix} vsim {"-c" if not args.gui else ""} -do "{cmd}"'
160157
print(f"Running Questa with command: {cmd}")

config/rv32gc/coverage.svh

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,60 @@
66
// It defines which extensions are enabled for that config.
77

88
// Define XLEN, used in covergroups
9-
`define XLEN32 1
9+
`define XLEN32
1010

1111
// Define relevant addresses
1212
`define ACCESS_FAULT_ADDRESS 32'h0000
1313
`define CLINT_BASE 64'h02000000
1414

1515
// Unprivileged extensions
16-
`include "I_coverage.svh"
17-
`include "M_coverage.svh"
18-
`include "F_coverage.svh"
19-
`include "D_coverage.svh"
20-
`include "Zba_coverage.svh"
21-
`include "Zbb_coverage.svh"
22-
`include "Zbc_coverage.svh"
23-
`include "Zbs_coverage.svh"
24-
`include "ZfaF_coverage.svh"
25-
`include "ZfaD_coverage.svh"
26-
`include "ZfaZfh_coverage.svh"
27-
`include "Zfh_coverage.svh"
28-
`include "ZfhD_coverage.svh"
16+
`define I_COVERAGE
17+
`define M_COVERAGE
18+
`define F_COVERAGE
19+
`define D_COVERAGE
20+
`define ZBA_COVERAGE
21+
`define ZBB_COVERAGE
22+
`define ZBC_COVERAGE
23+
`define ZBS_COVERAGE
24+
`define ZFA_F_COVERAGE
25+
`define ZFA_D_COVERAGE
26+
`define ZFA_ZFH_COVERAGE
27+
`define ZFA_ZFH_D_COVERAGE
28+
`define ZFH_COVERAGE
29+
`define ZFH_D_COVERAGE
2930
// Note: Zfhmin is a subset of Zfh, so usually only one or the other would be used. When Zfhmin and D are supported, ZfhD should also be enabled
30-
`include "Zfhmin_coverage.svh"
31+
`define ZFHMIN_COVERAGE
32+
`define ZFHMIN_D_COVERAGE
3133
// Note: Zmmul is a subset of M, so usually only one or the other would be used.
32-
`include "Zmmul_coverage.svh"
33-
`include "Zicond_coverage.svh"
34-
`include "Zca_coverage.svh"
35-
`include "Zcb_coverage.svh"
36-
`include "ZcbM_coverage.svh"
37-
`include "ZcbZbb_coverage.svh"
38-
`include "Zcf_coverage.svh"
39-
`include "Zcd_coverage.svh"
40-
`include "Zicsr_coverage.svh"
41-
`include "Zbkb_coverage.svh"
42-
`include "Zbkc_coverage.svh"
43-
`include "Zbkx_coverage.svh"
44-
`include "Zknd_coverage.svh"
45-
`include "Zkne_coverage.svh"
46-
`include "Zknh_coverage.svh"
47-
`include "Zaamo_coverage.svh"
48-
`include "Zalrsc_coverage.svh"
34+
`define ZMMUL_COVERAGE
35+
`define ZICOND_COVERAGE
36+
`define ZCA_COVERAGE
37+
`define ZCB_COVERAGE
38+
`define ZCB_M_COVERAGE
39+
`define ZCB_ZBB_COVERAGE
40+
`define ZCF_COVERAGE
41+
`define ZCD_COVERAGE
42+
`define ZICSR_COVERAGE
43+
`define ZBKB_COVERAGE
44+
`define ZBKC_COVERAGE
45+
`define ZBKX_COVERAGE
46+
`define ZKND_COVERAGE
47+
`define ZKNE_COVERAGE
48+
`define ZKNH_COVERAGE
49+
`define ZAAMO_COVERAGE
50+
`define ZALRSC_COVERAGE
4951

5052
// Privileged extensions
51-
`include "ZicsrM_coverage.svh"
52-
`include "ZicsrF_coverage.svh"
53-
`include "ZicsrU_coverage.svh"
54-
`include "RV32VM_coverage.svh"
55-
`include "RV32VM_PMP_coverage.svh"
56-
`include "EndianU_coverage.svh"
57-
`include "EndianM_coverage.svh"
58-
`include "EndianS_coverage.svh"
59-
`include "ExceptionsM_coverage.svh"
60-
`include "ExceptionsZc_coverage.svh"
61-
`include "ZicntrU_coverage.svh"
62-
`include "ZicntrS_coverage.svh"
63-
`include "ZicntrM_coverage.svh"
64-
`include "ZfaZfhD_coverage.svh"
65-
`include "ZfhminD_coverage.svh"
53+
`define RV32VM_COVERAGE
54+
`define RV32VM_PMP_COVERAGE
55+
`define ZICSRM_COVERAGE
56+
`define ZICSRF_COVERAGE
57+
`define ZICSRU_COVERAGE
58+
`define ENDIANU_COVERAGE
59+
`define ENDIANS_COVERAGE
60+
`define ENDIANM_COVERAGE
61+
`define EXCEPTIONSM_COVERAGE
62+
`define EXCEPTIONSZC_COVERAGE
63+
`define ZICNTRU_COVERAGE
64+
`define ZICNTRS_COVERAGE
65+
`define ZICNTRM_COVERAGE

config/rv64gc/coverage.svh

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,63 @@
66
// It defines which extensions are enabled for that config.
77

88
// Define XLEN, used in covergroups
9-
`define XLEN64 1
9+
`define XLEN64
1010

1111
// Define relevant addresses
1212
`define ACCESS_FAULT_ADDRESS 64'h00000000
1313
`define CLINT_BASE 64'h02000000
1414

1515
// Unprivileged extensions
16-
`include "I_coverage.svh"
17-
`include "M_coverage.svh"
18-
`include "F_coverage.svh"
19-
`include "D_coverage.svh"
20-
`include "Zba_coverage.svh"
21-
`include "Zbb_coverage.svh"
22-
`include "Zbc_coverage.svh"
23-
`include "Zbs_coverage.svh"
24-
`include "ZfaF_coverage.svh"
25-
`include "ZfaD_coverage.svh"
26-
`include "ZfaZfh_coverage.svh"
27-
`include "ZfhD_coverage.svh"
28-
`include "Zfh_coverage.svh"
16+
`define I_COVERAGE
17+
`define M_COVERAGE
18+
`define F_COVERAGE
19+
`define D_COVERAGE
20+
`define ZBA_COVERAGE
21+
`define ZBB_COVERAGE
22+
`define ZBC_COVERAGE
23+
`define ZBS_COVERAGE
24+
`define ZFA_F_COVERAGE
25+
`define ZFA_D_COVERAGE
26+
`define ZFA_ZFH_COVERAGE
27+
`define ZFA_ZFH_D_COVERAGE
28+
`define ZFH_COVERAGE
29+
`define ZFH_D_COVERAGE
2930
// Note: Zfhmin is a subset of Zfh, so usually only one or the other would be used. When Zfhmin and D are supported, ZfhD should also be enabled
30-
`include "Zfhmin_coverage.svh"
31+
`define ZFHMIN_COVERAGE
32+
`define ZFHMIN_D_COVERAGE
3133
// Note: Zmmul is a subset of M, so usually only one or the other would be used.
32-
`include "Zmmul_coverage.svh"
33-
`include "Zicond_coverage.svh"
34-
`include "Zca_coverage.svh"
35-
`include "Zcb_coverage.svh"
36-
`include "ZcbM_coverage.svh"
37-
`include "ZcbZbb_coverage.svh"
38-
`include "ZcbZba_coverage.svh"
39-
`include "Zcd_coverage.svh"
40-
`include "Zicsr_coverage.svh"
41-
`include "Zbkb_coverage.svh"
42-
`include "Zbkc_coverage.svh"
43-
`include "Zbkx_coverage.svh"
44-
`include "Zknd_coverage.svh"
45-
`include "Zkne_coverage.svh"
46-
`include "Zknh_coverage.svh"
47-
`include "Zaamo_coverage.svh"
48-
`include "Zalrsc_coverage.svh"
34+
`define ZMMUL_COVERAGE
35+
`define ZICOND_COVERAGE
36+
`define ZCA_COVERAGE
37+
`define ZCB_COVERAGE
38+
`define ZCB_M_COVERAGE
39+
`define ZCB_ZBB_COVERAGE
40+
`define ZCB_ZBA_COVERAGE
41+
`define ZCD_COVERAGE
42+
`define ZICSR_COVERAGE
43+
`define ZBKB_COVERAGE
44+
`define ZBKC_COVERAGE
45+
`define ZBKX_COVERAGE
46+
`define ZKND_COVERAGE
47+
`define ZKNE_COVERAGE
48+
`define ZKNH_COVERAGE
49+
`define ZAAMO_COVERAGE
50+
`define ZALRSC_COVERAGE
4951

5052
// Privileged extensions
51-
`include "RV64VM_coverage.svh"
52-
`include "ZicsrM_coverage.svh"
53-
`include "ZicsrF_coverage.svh"
54-
`include "ZicsrU_coverage.svh"
55-
`include "EndianU_coverage.svh"
56-
`include "EndianM_coverage.svh"
57-
`include "EndianS_coverage.svh"
58-
`include "ExceptionsM_coverage.svh"
59-
`include "ExceptionsZc_coverage.svh"
60-
`include "ZicntrU_coverage.svh"
61-
`include "ZicntrS_coverage.svh"
62-
`include "ZicntrM_coverage.svh"
63-
`include "ZfaZfhD_coverage.svh"
64-
`include "ZfhminD_coverage.svh"
53+
`define RV64VM_COVERAGE
54+
`define ZICSRM_COVERAGE
55+
`define ZICSRF_COVERAGE
56+
`define ZICSRU_COVERAGE
57+
`define ENDIANU_COVERAGE
58+
`define ENDIANS_COVERAGE
59+
`define ENDIANM_COVERAGE
60+
`define EXCEPTIONSM_COVERAGE
61+
`define EXCEPTIONSZC_COVERAGE
62+
`define ZICNTRU_COVERAGE
63+
`define ZICNTRS_COVERAGE
64+
`define ZICNTRM_COVERAGE
6565

66-
// `include "RV64VM_PMP_coverage.svh"
67-
// `include "RV64CBO_VM_coverage.svh"
68-
// `include "RV64CBO_PMP_coverage.svh"
66+
// `define RV64VM_PMP_COVERAGE
67+
// `define RV64CBO_VM_COVERAGE
68+
// `define RV64CBO_PMP_COVERAGE

setup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ echo \$WALLY set to "${WALLY}"
3333
# utility functions in Wally repository
3434
export PATH=$WALLY/bin:$PATH
3535

36+
# Setup cvw-arch-verif paths
37+
if [ -e "${WALLY}"/addins/cvw-arch-verif/setup.sh ]; then
38+
source "${WALLY}"/addins/cvw-arch-verif/setup.sh
39+
else
40+
echo "setup.sh not found in \$WALLY/addins/cvw-arch-verif directory. Make sure you cloned the submodules."
41+
fi
42+
3643
# Verilator needs a larger core file size to simulate CORE-V Wally
3744
ulimit -c 300000
3845

@@ -41,6 +48,7 @@ if [ -e "${RISCV}"/site-setup.sh ]; then
4148
source "${RISCV}"/site-setup.sh
4249
else
4350
echo "site-setup.sh not found in \$RISCV directory. Rerun wally-toolchain-install.sh to automatically download it."
51+
exit 1
4452
fi
4553

4654
echo "setup done"

sim/imperas-verbose.ic

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Add Imperas simulator application instruction tracing
2-
--verbose --trace --tracechange --traceshowicount --tracemode -tracemem ASX --monitornetschange # --traceafter 300000000
2+
--verbose --trace --tracechange --traceshowicount --tracemode --tracemem XSL --monitornetschange # --traceafter 300000000
33
--override cpu/debugflags=6 --override cpu/verbose=1
4-
--override cpu/show_c_prefix=T

sim/questa/wally.do

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,20 @@ if {[lcheck lst "--ccov"]} {
112112
# if --fcov found set flag and remove from list
113113
if {[lcheck lst "--fcov"]} {
114114
set FunctCoverage 1
115-
set FCvlog "+incdir+${FCRVVI}/unpriv \
116-
+incdir+${FCRVVI}/priv +incdir+${FCRVVI}/rv64_priv +incdir+${FCRVVI}/rv32_priv \
117-
+incdir+${FCRVVI}/common +incdir+${FCRVVI} \
118-
+incdir+$env(WALLY)/addins/cvw-arch-verif/riscvISACOV/source"
115+
set FCvlog "-f ${FCRVVI}/cvw-arch-verif.f"
119116
}
120117

121-
# if --lockstep or --fcov found set flag and remove from list
122-
if {[lcheck lst "--lockstep"] || $FunctCoverage == 1} {
118+
# if --lockstep found set flag and remove from list
119+
if {[lcheck lst "--lockstep"]} {
123120
set IMPERAS_HOME $::env(IMPERAS_HOME)
124121
set lockstep 1
122+
set SVLib " -sv_lib ${IMPERAS_HOME}/lib/Linux64/ImperasLib/imperas.com/verification/riscv/1.0/model "
125123
set lockstepvlog "+incdir+${IMPERAS_HOME}/ImpPublic/include/host \
126124
+incdir+${IMPERAS_HOME}/ImpProprietary/include/host \
127-
${IMPERAS_HOME}/ImpPublic/source/host/rvvi/*.sv \
125+
${IMPERAS_HOME}/ImpPublic/source/host/rvvi/rvviApiPkg.sv \
128126
${IMPERAS_HOME}/ImpProprietary/source/host/idv/*.sv"
129-
set SVLib " -sv_lib ${IMPERAS_HOME}/lib/Linux64/ImperasLib/imperas.com/verification/riscv/1.0/model "
127+
# only add standard rvviTrace interface if not using the custom one from cvw-arch-verif
128+
if {!$FunctCoverage} {append lockstepvlog " ${IMPERAS_HOME}/ImpPublic/source/host/rvvi/rvviTrace.sv"}
130129
}
131130

132131
# if --breker found set flag and remove from list
@@ -184,7 +183,7 @@ if {$DEBUG > 0} {
184183
# because vsim will run vopt
185184
set INC_DIRS "+incdir+${CONFIG}/${CFG} +incdir+${CONFIG}/deriv/${CFG} +incdir+${CONFIG}/shared"
186185
set SOURCES "${SRC}/cvw.sv ${TB}/${TESTBENCH}.sv ${TB}/common/*.sv ${SRC}/*/*.sv ${SRC}/*/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*/*/*.sv"
187-
vlog -permissive -lint -work ${WKDIR} {*}${INC_DIRS} {*}${FCvlog} {*}${DefineArgs} {*}${lockstepvlog} {*}${brekervlog} {*}${SOURCES} -suppress 2282,2583,7053,7063,2596,13286,2605,2250
186+
vlog -permissive -lint -work ${WKDIR} {*}${INC_DIRS} {*}${DefineArgs} {*}${lockstepvlog} {*}${FCvlog} {*}${brekervlog} {*}${SOURCES} -suppress 2282,2583,7053,7063,2596,13286,2605,2250
188187

189188
# start and run simulation
190189
# remove +acc flag for faster sim during regressions if there is no need to access internal signals

testbench/common/wallyTracer.sv

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ module wallyTracer import cvw::*; #(parameter cvw_t P) (rvviTrace rvvi);
742742
end
743743

744744
always_ff @(posedge clk) begin
745-
if(valid) begin
745+
if(valid) begin
746746
if(`STD_LOG) begin
747747
$fwrite(file, "%016x, %08x, %s\t\t", rvvi.pc_rdata[0][0], rvvi.insn[0][0], instrWName);
748748
for(index2 = 0; index2 < NUM_REGS; index2 += 1) begin
@@ -785,7 +785,16 @@ module wallyTracer import cvw::*; #(parameter cvw_t P) (rvviTrace rvvi);
785785
end
786786
end
787787
end
788-
if(HaltW) $finish;
788+
if(HaltW) begin
789+
`ifdef FCOV
790+
$display("Functional coverage test complete.");
791+
`endif
792+
`ifdef QUESTA
793+
$stop; // if this is changed to $finish for Questa, wally.do does not go to the next step to run coverage and terminates without allowing GUI debug
794+
`else
795+
$finish;
796+
`endif
797+
end
789798
end
790799
endmodule
791800

0 commit comments

Comments
 (0)