Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

StepIn this flowProduces
modelBuilds the Sail model in reference.source for archThe reference model’s RVFI-DII binary
engineBuilds QCVEngine from engine.sourceThe QCVEngine binary
filelistAsks FuseSoC for the default target of dut.core, the testbenchA copy of every source, and a .scr
flattenRewrites the .scr for the build stepfilelist.f
instrumentVerilator only. Makes the build’s filelist, with covergroups as cover propertiesfilelist.f and rewritten sources
buildCompiles and elaborates dut.top in the simulatorThe simulation snapshot
runRuns QCVEngine against the model and the simulator. The test resultStats, logs, counterexamples, coverage
coverageReports on the coverage of the run. Only with dut.coverage.functionalCoverage 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:

RoleToolsUsed byIf the config leaves it out
dutxcelium, verilatorbuild, runThe project file’s tool.testrig.dut. An error if that is unset too
referencesailmodel, runThe project file’s tool.testrig.reference. An error if that is unset too
coverageimc, doriscoverageThe project file’s tool.testrig.coverage. Otherwise the simulator’s own reporter
tool: {
  dut: [
    xcelium
    verilator
  ]
  reference: sail
}
  • dut is 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>@xcelium and testrig/<design>@verilator. With several tools for more than one role there is a job for each combination, and a role other than dut that has several adds its tool to the name after a +, such as testrig/<design>@xcelium+imc.
  • The coverage reporter goes with the simulator. imc reads the databases Xcelium writes, and doris, doris’s own reporter, reads the file a Verilator run writes. With coverage left 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 for coverage gives every simulator a job with every reporter, and a pair that can’t work stops the plan. So leave coverage out, above all in a config with both simulators. The role is only used, and the pair only checked, in a job with dut.coverage.functional.
  • The coverage role is only used with dut.coverage.functional. Without it a job has no coverage step, 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

SimulatorNeedsCoverage report
xceliumxrun and a licence. imc for coverageIMC’s, of the covergroups
verilatorVerilator with make and a C++ compiler: 5.048 is known to work, and 5.040 cannot compile UVM. A UVM library for a UVM testbenchdoris’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.

KeyUsed byEffect
archmodel, runISA string. Picks the model binary, and is passed to QCVEngine as -r
support_misalignedrunPasses -m to the reference model
tests.countrunGenerate mode: QCVEngine -n. Tests per test group, default 100
tests.includerunGenerate mode: QCVEngine -I, a regex of test groups to run
tests.excluderunGenerate mode: QCVEngine -x, a regex of test groups to leave out
tests.lengthrunQCVEngine -L, the maximum test length in instructions
tests.seedrunGenerate mode: QCVEngine --seed. A new seed every run if unset
replayrunReplay mode: the directory of saved traces, QCVEngine -d
timeoutrunWall-clock limit for the run step, such as 2h. No limit if unset
tagsSelectionLabels 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 stepWhat 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>runWhat the simulator and the reference model hold, on top of run’s: threads and memory
tool.dutbuild, runThe simulators: xcelium, verilator. See Tools
tool.referencemodel, runThe reference model. Only sail exists
tool.coveragecoverageThe coverage reporter: imc or doris. Usually left out
reference.sourcemodelThe model’s source tree
engine.sourceengineThe QCVEngine source tree
dut.corefilelistThe FuseSoC core of the testbench
dut.topbuildThe top module
dut.definesbuild+define+ for each
dut.parametersbuildValues for parameters of the top module, by name
dut.dpibuildC and C++ sources of DPI code that the core does not name, relative to the config file
dut.uvmbuildCompile with UVM
dut.testrun+UVM_TESTNAME, and the coverage test name. Unset, no +UVM_TESTNAME is passed and the coverage test is test
dut.coverage.functionalbuild, runCollect functional coverage, and add the coverage step to report it
dut.coverage.scopesbuild, instrumentModules to collect coverage in (Xcelium’s -covdut in build, Verilator’s coverage in instrument)
dut.wavesbuild, runRecord the waves of the run. See Waves
tools.xcelium.build.argsbuildExtra xrun arguments for the build
tools.xcelium.run.argsrunExtra xrun arguments for the run
tools.verilator.commandbuildThe Verilator to simulate with, if it is not verilator
tools.verilator.build.argsbuildExtra Verilator arguments for the build
tools.verilator.run.argsrunExtra arguments for the simulation binary
tools.sail.model.argsmodelExtra arguments for make
tools.sail.run.argsrunExtra arguments for the emulator
tools.imc.coverage.argscoverageExtra 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.

SimulatorBuildRunWaves
xcelium-access +r, read access to every objectThe -input script opens an SHM database and probes every object, to any depthrun/dut/waves.shm/
verilator--trace-fst, and a waves source bound into the top module+doris_waves, which makes the waves source start the dumprun/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 --seed option. 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 arch with CHERI. Sail is built as the CHERI model only, and any other arch is an error when the job is planned.
  • A testbench core whose default target writes one flat filelist (see filelist). The list is compiled in one go, so that macros such as ASSERT are 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 handStep
make -C sail-cheri-riscv ARCH=RV64 rvfimodel
cabal install --offline in qcvengine/engine
fusesoc run --setup example::my_core_testrigfilelist, flatten
xrun -elaborate -snapshot workbuild
testrig.py -a sail -b my_core_coveragerun
imc -exec coverage/coverage_report.tclcoverage

Some things work differently:

  • testrig.py is not used. doris starts the model, the simulator and QCVEngine itself. It waits for each port to be listening where testrig.py sleeps for five seconds, and the xrun command line comes from doris, not from a patch to the vendored script.
  • Nothing is built in the source trees. The Sail Makefile and cabal build 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 -R runs in a directory of its own that links to the snapshot.
  • The library path fixes are in doris. The build’s LD_LIBRARY_PATH and the run’s LD_PRELOAD of the system libstdc++ are set by doris when each step starts.
  • The IMC commands are in doris. The project’s coverage_report.tcl is not read. The coverage report is of one run, in that run’s job directory.
  • dvplan annotation is not run. The coverage step 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 N on the command line if given, otherwise tests.seed from the config, otherwise one doris picks when it plans the job. --seed random asks 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 is seed in result.json, so a failure can be rerun with --seed. --seed can’t be combined with --replay.
  • Replay (--replay) reruns the traces in the replay directory. It is deterministic, so it is cached, with the trace directory as an input. tests.count, tests.include and tests.exclude are 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
  1. Did every step run, with the code you expect? In result.json, check revision has no (dirty) and is the commit you meant, and look at each step’s cached and seconds. 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
    
  2. Were the binaries built from the vendored sources? After a run with --debug, model/stdout.log and engine/stdout.log should show compilation, not Nothing to be done.

  3. Did QCVEngine talk to both sides? run/stdout.log starts with connected to implementation-A and connected to implementation-B. Read any WARNING after them: a trace version one side doesn’t support narrows what is compared.

  4. Which test groups ran, and how many tests? Each group that ran prints its name and +++ OK, passed N tests. Each one left out prints Warning: 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
    
  5. 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.log has one line per instruction the model executed, numbered from 0 within each test.

    grep -c 'Received reset command' "$log"
    
  6. Were the instructions the ones you care about? run/stats.txt counts 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.

  7. 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
    
  8. How did the simulation end? For Xcelium, the end of the log should show Simulation received SIGTERM from doris, then the coverage files being written and xrun exiting. The UVM report summary and final phases do not run, because the testbench never ends the test itself.

  9. Is there coverage? run/dut/cov_work/scope/<dut.test>/ should hold a .ucd file written at the end of the run. coverage/detail.txt lists every bin with its hit count: check the bins not hit are ones this run could not have hit. The report is there when the run step failed too.

  10. No counterexamples? run/counterexamples/ is empty on a pass, and counterexamples in result.json is [].

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.