TestRIG
TestRIG checks a RISC-V core against a reference model. QuickCheckVEngine (QCVEngine) generates instruction sequences and sends each one to two implementations over RVFI-DII sockets. Each implementation executes the instructions and sends back one trace packet per instruction. QCVEngine compares the two streams. If they differ it shrinks the sequence to a small counterexample and saves it.
In doris, implementation A is the reference model and implementation B is the design in a simulator. For example, that is the Sail CHERI RISC-V model against the core’s testbench in Xcelium or in Verilator.
This page covers the steps the flow runs, its config, and how to check a run. Each step has its own page under Steps. Read Running flows first for how any step runs and what outcomes mean.
doris plan -v testrig my_core # the steps and exact commands
doris run testrig my_core # generate mode: new random tests
doris run testrig my_core --seed 42 # generate mode: the tests seed 42 makes
doris run testrig my_core --replay # replay mode: rerun saved traces
doris run testrig my_core --until build
doris run testrig my_core --tool verilator # only the Verilator job
The steps
flowchart LR
model --> run
engine --> run
filelist --> flatten --> build --> run
filelist --> build
flatten -.-> instrument -.-> build
run --> coverage
The dotted step is in a Verilator job only.
| Step | In this flow | Produces |
|---|---|---|
model | Builds the Sail model in reference.source for arch | The reference model’s RVFI-DII binary |
engine | Builds QCVEngine from engine.source | The QCVEngine binary |
filelist | Asks FuseSoC for the default target of dut.core, the testbench | A copy of every source, and a .scr |
flatten | Rewrites the .scr for the build step | filelist.f |
instrument | Verilator only. Makes the build’s filelist, with covergroups as cover properties | filelist.f and rewritten sources |
build | Compiles and elaborates dut.top in the simulator | The simulation snapshot |
run | Runs QCVEngine against the model and the simulator. The test result | Stats, logs, counterexamples, coverage |
coverage | Reports on the coverage of the run. Only with dut.coverage.functional | Coverage reports |
There is one job per simulator bound for the design, testrig/<design>@<simulator>, in scratch/doris/testrig/<design>@<simulator>/. The jobs of a design get the same seed, so each simulator is given the same tests, and they share the model and engine builds through the cache. --tool keeps the jobs that use one tool. Every step is cached. model, engine and filelist depend on nothing, so they start together.
The coverage step runs after a run step that failed. A job with a failing test is failed, and still has its coverage report. Every other step is skipped when a step it depends on did not pass, and coverage is too when run did not complete.
Tools
The flow has three roles. The config’s tool table binds a tool to each, by a name or a list of names:
| Role | Tools | Used by | If the config leaves it out |
|---|---|---|---|
dut | xcelium, verilator | build, run | The project file’s tool.testrig.dut. An error if that is unset too |
reference | sail | model, run | The project file’s tool.testrig.reference. An error if that is unset too |
coverage | imc, doris | coverage | The project file’s tool.testrig.coverage. Otherwise the simulator’s own reporter |
tool: {
dut: [
xcelium
verilator
]
reference: sail
}
dutis the main role. Its tool names the job, after the@.- Several tools for a role give a job for each. The config above gives
testrig/<design>@xceliumandtestrig/<design>@verilator. With several tools for more than one role there is a job for each combination, and a role other thandutthat has several adds its tool to the name after a+, such astestrig/<design>@xcelium+imc. - The coverage reporter goes with the simulator.
imcreads the databases Xcelium writes, anddoris, doris’s own reporter, reads the file a Verilator run writes. Withcoverageleft out, each job gets the one that reads its simulator’s. Binding one that can’t is an error when the job is planned:job `testrig/my_core@verilator` pairs simulator `verilator` with coverage reporter `imc`: `verilator` writes Verilator coverage databases, and `imc` only reads Cadence ones. A list forcoveragegives every simulator a job with every reporter, and a pair that can’t work stops the plan. So leavecoverageout, above all in a config with both simulators. The role is only used, and the pair only checked, in a job withdut.coverage.functional. - The
coveragerole is only used withdut.coverage.functional. Without it a job has nocoveragestep, and reporters bound to the role, however many, give no extra jobs. - A binding replaces the project file’s default for that role. See Tools and roles.
Simulators
| Simulator | Needs | Coverage report |
|---|---|---|
xcelium | xrun and a licence. imc for coverage | IMC’s, of the covergroups |
verilator | Verilator with make and a C++ compiler: 5.048 is known to work, and 5.040 cannot compile UVM. A UVM library for a UVM testbench | doris’s own, as text and HTML, of the cover properties instrument makes of the covergroups |
Verilator has no UVM library. For a testbench with dut.uvm, the environment variable UVM_HOME names one Verilator can compile, such as the uvm-2017-1.0-vlt branch of chipsalliance/uvm-verilator: the directory holding src/uvm_pkg.sv. It is compiled with UVM_NO_DPI, so UVM’s command line options that need its DPI code, such as +UVM_PHASE_TRACE, do nothing. The variable’s value is part of the Verilator build step’s cache key, so pointing it at another library builds again. That it is set is a precheck of the build: doris check lists it, and a run without it stops before any step starts.
doris check testrig DESIGN lists everything a design’s jobs need of the machine: the programs, UVM_HOME, and with --replay the trace directory (see Checking the environment).
A testbench written for one simulator may need changes for the other. Verilator is a two-state simulator with no tristate ports, it does not wake a wait on some conditions read through a virtual interface, and processes that start at time 0 may run in another order, which shows up races another simulator hid.
What a config asks of a simulator is checked when the job is planned. Functional coverage, waves, DPI sources and UVM are each a feature a simulator has or lacks, and a job that needs one its simulator lacks fails in doris plan. Xcelium and Verilator have all four.
The job passes when every step passes. What that covers is on each step’s page. For the test result, see what passed means for the run step.
What the config file controls
The flow reads testrig.hjson (schema dv/testrig/1) next to or below the design’s design.hjson.
| Key | Used by | Effect |
|---|---|---|
arch | model, run | ISA string. Picks the model binary, and is passed to QCVEngine as -r |
support_misaligned | run | Passes -m to the reference model |
tests.count | run | Generate mode: QCVEngine -n. Tests per test group, default 100 |
tests.include | run | Generate mode: QCVEngine -I, a regex of test groups to run |
tests.exclude | run | Generate mode: QCVEngine -x, a regex of test groups to leave out |
tests.length | run | QCVEngine -L, the maximum test length in instructions |
tests.seed | run | Generate mode: QCVEngine --seed. A new seed every run if unset |
replay | run | Replay mode: the directory of saved traces, QCVEngine -d |
timeout | run | Wall-clock limit for the run step, such as 2h. No limit if unset |
tags | Selection | Labels for the design’s TestRIG jobs, added to the design file’s tags. -i tag=GLOB and -x tag=GLOB select on them (see Filters). They are not part of any cache key |
resources.<step>, resources.<step>@<tool> | That step | What the step holds while it runs: threads, memory and disk, for every tool or for one. For run, its command’s share: QCVEngine’s. See Resource pools |
resources.run.dut, resources.run.reference, each with @<tool> | run | What the simulator and the reference model hold, on top of run’s: threads and memory |
tool.dut | build, run | The simulators: xcelium, verilator. See Tools |
tool.reference | model, run | The reference model. Only sail exists |
tool.coverage | coverage | The coverage reporter: imc or doris. Usually left out |
reference.source | model | The model’s source tree |
engine.source | engine | The QCVEngine source tree |
dut.core | filelist | The FuseSoC core of the testbench |
dut.top | build | The top module |
dut.defines | build | +define+ for each |
dut.parameters | build | Values for parameters of the top module, by name |
dut.dpi | build | C and C++ sources of DPI code that the core does not name, relative to the config file |
dut.uvm | build | Compile with UVM |
dut.test | run | +UVM_TESTNAME, and the coverage test name. Unset, no +UVM_TESTNAME is passed and the coverage test is test |
dut.coverage.functional | build, run | Collect functional coverage, and add the coverage step to report it |
dut.coverage.scopes | build, instrument | Modules to collect coverage in (Xcelium’s -covdut in build, Verilator’s coverage in instrument) |
dut.waves | build, run | Record the waves of the run. See Waves |
tools.xcelium.build.args | build | Extra xrun arguments for the build |
tools.xcelium.run.args | run | Extra xrun arguments for the run |
tools.verilator.command | build | The Verilator to simulate with, if it is not verilator |
tools.verilator.build.args | build | Extra Verilator arguments for the build |
tools.verilator.run.args | run | Extra arguments for the simulation binary |
tools.sail.model.args | model | Extra arguments for make |
tools.sail.run.args | run | Extra arguments for the emulator |
tools.imc.coverage.args | coverage | Extra imc arguments |
A tool’s options are under its name and then the step it is used in, because a tool can be used in two steps with different arguments in each: xrun builds and runs. A tools.<name> table is read only by the jobs that tool is bound in, so a config has one for each simulator it names. doris, the Verilator coverage reporter, has no options. A table for a tool that can fill none of the flow’s roles, such as tools.slang, is an error.
tools.verilator is also where a lint config keeps Verilator’s options as a linter, so it accepts a lint table here too. TestRIG has no such step, and ignores it.
dut.parameters and dut.dpi. Each parameter becomes -defparam <dut.top>.<name>=<value> for Xcelium and -G<name>=<value> for Verilator. doris passes the value as text and adds no quoting, so a string parameter must carry the quotes its simulator wants. Each DPI source is given to the simulator with the filelist, and is an input of the build step, so an edit to one rebuilds. DPI code the testbench core already lists needs no entry. dut.parameters and dut.dpi have unit tests of the command lines only: neither has yet been run in a real Xcelium or Verilator.
An example
An example config, hw/ip/my_core/dv/testrig/testrig.hjson. It belongs to hw/ip/my_core/design.hjson, which names the design and gives its RTL core. TestRIG doesn’t use that core: dut.core is the testbench wrapper around it.
{
schema: dv/testrig/1
arch: rv64icxcheri
support_misaligned: false
tests: {
count: 100
exclude: unstructured
}
replay: regressions
tool: {
dut: xcelium
reference: sail
}
reference: {
source: ../../../../vendor/dv/sail-cheri-riscv
}
engine: {
source: ../../../../vendor/dv/qcvengine
}
dut: {
core: example::my_core_testrig
top: my_core_testrig_tb_top
uvm: true
test: my_core_testrig_test
defines: [
XSIM
DISABLE_OVERLAP_DETECTION
]
coverage: {
functional: true
scopes: [
isa_coverage
alu_coverage
]
}
}
tools: {
xcelium: {
build: {
args: [
-uvmhome
CDNS-1.2
]
}
}
}
}
Waves
dut.waves: true records the waves of the run. The build is made so that a run can record them, and the run does. The waves are an output of the run step, so they are kept in the cache with its other outputs.
| Simulator | Build | Run | Waves |
|---|---|---|---|
xcelium | -access +r, read access to every object | The -input script opens an SHM database and probes every object, to any depth | run/dut/waves.shm/ |
verilator | --trace-fst, and a waves source bound into the top module | +doris_waves, which makes the waves source start the dump | run/dut/waves.fst |
Every signal is recorded for the whole run, so the build and the run are slower and the waves can be large. Turn it on to look at a failure, with a seed or a replay that shows it, and off again after. Turning it on or off changes the build step’s command, so the testbench is built again.
Waves have been run for real in Verilator, and not in Xcelium. A Verilator job with dut.waves has run and written run/dut/waves.fst, complete though the simulation is stopped with SIGTERM. The Xcelium path has unit tests of the command lines only, so check the first such job by hand.
What the flow needs from the project
- A QCVEngine with a
--seedoption. Upstream QCVEngine has none, so mocha adds it as a vendor patch. - QCVEngine’s Haskell dependencies in the dev shell. The engine is built offline. doris steps never use the network.
- An
archwith CHERI. Sail is built as the CHERI model only, and any otherarchis an error when the job is planned. - A testbench core whose
defaulttarget writes one flat filelist (see filelist). The list is compiled in one go, so that macros such asASSERTare visible in every file.
Coming from the Makefile and testrig.py
The flow replaces the manual steps of mocha’s TestRIG README. Each becomes a step:
| By hand | Step |
|---|---|
make -C sail-cheri-riscv ARCH=RV64 rvfi | model |
cabal install --offline in qcvengine/ | engine |
fusesoc run --setup example::my_core_testrig | filelist, flatten |
xrun -elaborate -snapshot work | build |
testrig.py -a sail -b my_core_coverage | run |
imc -exec coverage/coverage_report.tcl | coverage |
Some things work differently:
testrig.pyis not used. doris starts the model, the simulator and QCVEngine itself. It waits for each port to be listening wheretestrig.pysleeps for five seconds, and thexruncommand line comes from doris, not from a patch to the vendored script.- Nothing is built in the source trees. The Sail Makefile and
cabalbuild next to their sources, so each is given a copy of the tree in its step’s directory. - The run does not write into the build.
xrun -Rruns in a directory of its own that links to the snapshot. - The library path fixes are in doris. The build’s
LD_LIBRARY_PATHand the run’sLD_PRELOADof the systemlibstdc++are set by doris when each step starts. - The IMC commands are in doris. The project’s
coverage_report.tclis not read. The coverage report is of one run, in that run’s job directory. - dvplan annotation is not run. The
coveragestep writes the report data dvplan reads. See the roadmap.
Generate and replay
The flow has two modes. They differ only in the arguments the run step gives QCVEngine.
- Generate is the default. QCVEngine makes its tests from a seed, passed as
--seed, and the same seed with the same arguments makes the same tests. The seed is--seed Non the command line if given, otherwisetests.seedfrom the config, otherwise one doris picks when it plans the job.--seed randomasks for a picked seed even when the config sets one. The seed is an argument, so it is part of the cache key: a run with a seed it has had before is taken from the cache, and a run with a picked seed always runs. The seed is printed when the job ends and isseedinresult.json, so a failure can be rerun with--seed.--seedcan’t be combined with--replay. - Replay (
--replay) reruns the traces in thereplaydirectory. It is deterministic, so it is cached, with the trace directory as an input.tests.count,tests.includeandtests.excludeare not used.
--tests N on the command line replaces tests.count for one run, for a shorter run while working on the flow without editing the config file. It can’t be combined with --replay.
Counterexamples
When a test fails, QCVEngine saves its shrunk trace in run/counterexamples/. That directory is emptied the next time the step runs, so when the job ends doris copies it to counterexamples/<id>/ in the job’s directory and records each file and its content in result.json. The ID is the first 16 characters of the run step’s cache key. Nothing is kept unless the run step completed in this job.
To rerun a saved failure, copy the traces into the config’s replay directory and use --replay. To rerun the whole generated run that found it, pass the seed from result.json as --seed.
Checking a run by hand
Work through these in the job’s directory after a run. They cover what doris does not check.
A step that passed leaves only its outputs, so some of the files named here are gone after a normal run: the logs of model, engine, filelist and build, and run/reference.log. Run the job with --debug to keep every step’s directory whole (see Working directories). The first --debug run after a plain one runs every step again:
doris run testrig my_core --debug
The run step’s own files that these checks read are outputs, and are there after any run: run/stdout.log, run/stats.txt, run/counterexamples/, the coverage data, and the simulator’s log. That log is run/dut/run.log for Xcelium and run/dut.log for Verilator, written $log below.
log=run/dut/run.log # Xcelium; run/dut.log for Verilator
-
Did every step run, with the code you expect? In
result.json, checkrevisionhas no(dirty)and is the commit you meant, and look at each step’scachedandseconds. A cached step’s logs are from an earlier run. A build step that took a fraction of a second did no work.jq -r '.revision, (.steps[] | "\(.name)\t\(.outcome)\t\(.seconds)s\tcached=\(.cached)")' result.json -
Were the binaries built from the vendored sources? After a run with
--debug,model/stdout.logandengine/stdout.logshould show compilation, notNothing to be done. -
Did QCVEngine talk to both sides?
run/stdout.logstarts withconnected to implementation-Aandconnected to implementation-B. Read anyWARNINGafter them: a trace version one side doesn’t support narrows what is compared. -
Which test groups ran, and how many tests? Each group that ran prints its name and
+++ OK, passed N tests.Each one left out printsWarning: skipping .... Check the skipped list is what you expect for the ISA string.grep -c '^+++ OK, passed' run/stdout.log # groups that ran grep 'skipping' run/stdout.log # groups that did not grep -v '^+++ OK\|^Warning: skipping\| -- ' run/stdout.log # anything else -
Did the simulator do the work? Each test starts with a reset, so the testbench should log at least one reset per test. After a run with
--debug, or a failure,run/reference.loghas one line per instruction the model executed, numbered from 0 within each test.grep -c 'Received reset command' "$log" -
Were the instructions the ones you care about?
run/stats.txtcounts each instruction QCVEngine saw, split by whether it trapped. The job’s report has the same counts under “Instructions”, and names the instructions that only ever trapped. Look for instructions that are missing, or that only ever trapped. -
Is the simulator log clean? doris does not look.
grep -c 'UVM_ERROR\|UVM_FATAL' "$log" grep '\*E,\|\*F,' "$log" | cut -c1-200 | sort | uniq -c | sort -rn | head grep -o 'Assertion [^ ]* has failed' "$log" | sort | uniq -c | sort -rn -
How did the simulation end? For Xcelium, the end of the log should show
Simulation received SIGTERMfrom doris, then the coverage files being written andxrunexiting. The UVM report summary and final phases do not run, because the testbench never ends the test itself. -
Is there coverage?
run/dut/cov_work/scope/<dut.test>/should hold a.ucdfile written at the end of the run.coverage/detail.txtlists every bin with its hit count: check the bins not hit are ones this run could not have hit. The report is there when therunstep failed too. -
No counterexamples?
run/counterexamples/is empty on a pass, andcounterexamplesinresult.jsonis[].
A check that the flow can fail at all is worth doing once: break the design on purpose, for example by changing an ALU result, and confirm the job reports failed with a counterexample.