Search code examples
chisel

Generating waveforms with ChiselTest framework


I have a ChiselTest tester written as follows:

class EccTester extends FlatSpec with ChiselScalatestTester with Matchers {
    behavior of "Testers2"
  it should "send data without errors" in {
    test(new EccPair(width=8)) {
      c => {
        val rnd = new Random()
        for (i <- 0 to 20) {
          val testVal = rnd.nextInt(1 << c.getWidthParam)

          c.io.dataIn.poke(testVal.U)
          c.io.errorLocation.poke(0.U)
          c.io.injectError.poke(false.B)
          c.io.injectSecondError.poke(false.B)
          c.clock.step(1)
          c.io.dataOut.expect(testVal.U)
          c.io.outputNotEqual.expect(false.B)
        }
      }
    }
  }
}

I am able to run the test in the shell with

testOnly chisel.lib.ecc.EccTester

But when I try to generate waveforms per the ChiselTest documentation,

testOnly chisel.lib.ecc.EccTester -- -DvwriteVcd=1

The test executes OK but does not dump a waveform.

Documentation I referenced is https://github.com/ucb-bar/chisel-testers2, and the full source code is at https://github.com/hutch31/ip-contributions/blob/ecc/src/test/scala/chisel/lib/ecc/EccTester.scala


Solution

  • I don’t think there is a formal answer to this yet, but here’s what I do. First I add the two following imports.

    import chiseltest.experimental.TestOptionBuilder._
    import chiseltest.internal.WriteVcdAnnotation
    

    then add the annotation to the test like this

      it should "send data without errors" in {
        test(new EccPair(width=8)).withAnnotations(Seq(WriteVcdAnnotation)) {
          c => {
    

    Note: there are two definitions of WriteVcdAnnotation, one is in package treadle and the other is in package chiseltest.internal. Use the latter, as it will work for both treadle and verilator backends.