ChiselScalatestTester

chiseltest.ChiselScalatestTester

ChiselTest-compatible API that delegates to ChiselSim (Chisel 7)

This trait provides the ChiselTest API that users are familiar with from Chisel 6, but internally uses ChiselSim from Chisel 7 to perform the actual testing.

VCD GENERATION SUPPORT: This compatibility layer supports VCD generation when WriteVcdAnnotation is used. VCD files are generated in: build/chiselsim/ /workdir-verilator/trace.vcd

AUTOMATIC RESET FEATURE: By default, this trait automatically resets the module before running tests, mimicking ChiselTest's behavior from Chisel 6.

To disable auto-reset or customize the reset duration:

class MyTest extends AnyFlatSpec with ChiselScalatestTester {
 override def autoResetEnabled: Boolean = false  // Disable auto-reset
 override def resetCycles: Int = 5               // Or change duration
}

Example usage with VCD:

import chiseltest._
import org.scalatest.flatspec.AnyFlatSpec

class MyModuleSpec extends AnyFlatSpec with ChiselScalatestTester {
 behavior of "MyModule"

 it should "generate waveforms" in {
   test(new MyModule).withAnnotations(Seq(WriteVcdAnnotation)) { dut =>
     dut.io.in.poke(42.U)
     dut.clock.step()
     dut.io.out.expect(42.U)
   }
   // VCD file: build/chiselsim/<timestamp>/workdir-verilator/trace.vcd
 }
}

Attributes

Source
ChiselScalatestTester.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Type members

Classlikes

class TestBuilder[T <: Module](dutGen: => T, autoReset: Boolean, resetCyc: Int)

Builder class to support .withAnnotations() chaining

Builder class to support .withAnnotations() chaining

Value parameters

autoReset

Whether automatic reset is enabled

dutGen

Generator for the device under test

resetCyc

Number of reset cycles to apply

Attributes

Source
ChiselScalatestTester.scala
Supertypes
class Object
trait Matchable
class Any
class TestRunner[T <: Module](dutGen: => T, autoReset: Boolean, resetCyc: Int, annotations: Seq[Any] = ...)

Runner class that executes the test with VCD support

Runner class that executes the test with VCD support

Value parameters

annotations

Annotation list used to configure execution behavior

autoReset

Whether automatic reset is enabled

dutGen

Generator for the device under test

resetCyc

Number of reset cycles to apply

Attributes

Source
ChiselScalatestTester.scala
Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

def autoResetEnabled: Boolean

Enable automatic reset before each test. Override this to disable auto-reset if needed.

Enable automatic reset before each test. Override this to disable auto-reset if needed.

Attributes

Source
ChiselScalatestTester.scala
def resetCycles: Int

Number of clock cycles to assert reset. Override this to change reset duration.

Number of clock cycles to assert reset. Override this to change reset duration.

Attributes

Source
ChiselScalatestTester.scala
def test[T <: Module](dutGen: => T): TestBuilder[T]

Test a module with the given stimulus

Test a module with the given stimulus

This method provides the ChiselTest interface.

Type parameters

T

The type of module being tested

Value parameters

dutGen

A generator function that creates the device under test

Attributes

Source
ChiselScalatestTester.scala