diff --git a/src/main/scala/chiseltest/internal/PeekPokeTesterBackend.scala b/src/main/scala/chiseltest/internal/PeekPokeTesterBackend.scala index 2d97b5fd7..537e60127 100644 --- a/src/main/scala/chiseltest/internal/PeekPokeTesterBackend.scala +++ b/src/main/scala/chiseltest/internal/PeekPokeTesterBackend.scala @@ -28,7 +28,7 @@ object PeekPokeTesterBackend { ): AnnotationSeq = { val (sim, covAnnos, dut) = createTester(dutGen, defaults.addDefaultSimulator(annos), chiselAnnos) // extract port names - val portNames = DataMirror.modulePorts(dut).flatMap { case (name, data) => getDataNames(name, data).toList }.toMap + val portNames = DataMirror.fullModulePorts(dut).map(_.swap).toMap val localCtx = IOTestersContext(sim, portNames) // run tests @@ -48,13 +48,6 @@ object PeekPokeTesterBackend { finish(sim, covAnnos) } - /** Returns a Seq of (data reference, fully qualified element names) for the input. name is the name of data. */ - private def getDataNames(name: String, data: Data): Seq[(Data, String)] = Seq(data -> name) ++ (data match { - case _: Element => Seq() - case b: Record => b.elements.toSeq.flatMap { case (n, e) => getDataNames(s"${name}_$n", e) } - case v: Vec[_] => v.zipWithIndex.flatMap { case (e, i) => getDataNames(s"${name}_$i", e) } - }) - } private[chiseltest] case class IOTestersContext(backend: SimulatorContext, dataNames: Map[Data, String]) diff --git a/src/test/scala/chiseltest/tests/OpaqueTypeTest.scala b/src/test/scala/chiseltest/tests/OpaqueTypeTest.scala index 1ab2caadb..9b236d2bd 100644 --- a/src/test/scala/chiseltest/tests/OpaqueTypeTest.scala +++ b/src/test/scala/chiseltest/tests/OpaqueTypeTest.scala @@ -6,6 +6,7 @@ import chisel3.experimental.BundleLiterals.AddBundleLiteralConstructor import chisel3.experimental.OpaqueType import chisel3._ import chiseltest._ +import chiseltest.iotesters.PeekPokeTester import org.scalatest.flatspec.AnyFlatSpec import scala.collection.immutable.SeqMap @@ -30,6 +31,15 @@ class OpaqueTypeTest extends AnyFlatSpec with ChiselScalatestTester { dut.out.expect(rec(_val)) } + class PokeExpectTester[T <: Data](dut: OpaquePassthrough[T], _val: => T) extends PeekPokeTester(dut) { + poke(dut.in, IndexedSeq(_val.litValue)) + expect(dut.out, IndexedSeq(_val.litValue)) + } + + def testPokeExpectTester[T <: Data](_val: => T): Unit = + test(new OpaquePassthrough(_val.cloneType)) + .runPeekPoke(new PokeExpectTester(_, _val)) + behavior of "OpaqueType" it should "poke and expect successfully" in { @@ -38,4 +48,10 @@ class OpaqueTypeTest extends AnyFlatSpec with ChiselScalatestTester { testPokeExpect(rec(5.U(3.W))) } + it should "poke and expect successfully using PeekPokeTester" in { + testPokeExpectTester(4.U(6.W)) + testPokeExpectTester(-4.S(8.W)) + testPokeExpectTester(rec(5.U(3.W))) + } + }