Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
Replace getDataNames with DataMirror.fullModulePorts in PeekPokeTester (
Browse files Browse the repository at this point in the history
  • Loading branch information
konda-x1 authored Aug 21, 2023
1 parent 0ce013b commit 94f5273
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
16 changes: 16 additions & 0 deletions src/test/scala/chiseltest/tests/OpaqueTypeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)))
}

}

0 comments on commit 94f5273

Please sign in to comment.