summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/aop
diff options
context:
space:
mode:
authorJack Koenig2021-09-17 21:01:26 -0700
committerJack Koenig2021-09-17 21:01:26 -0700
commit5c8c19345e6711279594cf1f9ddab33623c8eba7 (patch)
treed9d6ced3934aa4a8be3dec19ddcefe50a7a93d5a /src/test/scala/chiselTests/aop
parente63b9667d89768e0ec6dc8a9153335cb48a213a7 (diff)
parent958904cb2f2f65d02b2ab3ec6d9ec2e06d04e482 (diff)
Merge branch 'master' into 3.5-release
Diffstat (limited to 'src/test/scala/chiselTests/aop')
-rw-r--r--src/test/scala/chiselTests/aop/InjectionSpec.scala25
-rw-r--r--src/test/scala/chiselTests/aop/SelectSpec.scala66
2 files changed, 87 insertions, 4 deletions
diff --git a/src/test/scala/chiselTests/aop/InjectionSpec.scala b/src/test/scala/chiselTests/aop/InjectionSpec.scala
index c9fa2e5e..a28501a5 100644
--- a/src/test/scala/chiselTests/aop/InjectionSpec.scala
+++ b/src/test/scala/chiselTests/aop/InjectionSpec.scala
@@ -5,6 +5,7 @@ package chiselTests.aop
import chisel3.testers.{BasicTester, TesterDriver}
import chiselTests.{ChiselFlatSpec, Utils}
import chisel3._
+import chisel3.aop.Select
import chisel3.aop.injecting.InjectingAspect
import logger.{LogLevel, LogLevelAnnotation}
@@ -14,6 +15,11 @@ object InjectionHierarchy {
val moduleSubmoduleA = Module(new SubmoduleA)
}
+ class MultiModuleInjectionTester extends BasicTester {
+ val subA0 = Module(new SubmoduleA)
+ val subA1 = Module(new SubmoduleA)
+ }
+
class SubmoduleA extends Module {
val io = IO(new Bundle {
val out = Output(Bool())
@@ -104,6 +110,17 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
}
)
+ val multiModuleInjectionAspect = InjectingAspect(
+ { top: MultiModuleInjectionTester =>
+ Select.collectDeep(top) { case m: SubmoduleA => m }
+ },
+ { m: Module =>
+ val wire = Wire(Bool())
+ wire := m.reset.asBool()
+ dontTouch(wire)
+ stop()
+ }
+ )
"Test" should "pass if inserted the correct values" in {
assertTesterPasses{ new AspectTester(Seq(0, 1, 2)) }
@@ -142,4 +159,12 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
Seq(addingExternalModules) ++ TesterDriver.verilatorOnly
)
}
+
+ "Injection into multiple submodules of the same class" should "work" in {
+ assertTesterPasses(
+ {new MultiModuleInjectionTester},
+ Nil,
+ Seq(multiModuleInjectionAspect) ++ TesterDriver.verilatorOnly
+ )
+ }
}
diff --git a/src/test/scala/chiselTests/aop/SelectSpec.scala b/src/test/scala/chiselTests/aop/SelectSpec.scala
index 91353f5a..e09e78c8 100644
--- a/src/test/scala/chiselTests/aop/SelectSpec.scala
+++ b/src/test/scala/chiselTests/aop/SelectSpec.scala
@@ -22,14 +22,16 @@ class SelectTester(results: Seq[Int]) extends BasicTester {
val nreset = reset.asBool() === false.B
val selected = values(counter)
val zero = 0.U + 0.U
+ var p: printf.Printf = null
when(overflow) {
counter := zero
stop()
}.otherwise {
when(nreset) {
assert(counter === values(counter))
- printf("values(%d) = %d\n", counter, selected)
+ p = printf("values(%d) = %d\n", counter, selected)
}
+
}
}
@@ -81,17 +83,18 @@ class SelectSpec extends ChiselFlatSpec {
"Test" should "pass if selecting correct printfs" in {
execute(
() => new SelectTester(Seq(0, 1, 2)),
- { dut: SelectTester => Seq(Select.printfs(dut).last) },
+ { dut: SelectTester => Seq(Select.printfs(dut).last.toString) },
{ dut: SelectTester =>
Seq(Select.Printf(
+ dut.p,
Seq(
When(Select.ops("eq")(dut).last.asInstanceOf[Bool]),
When(dut.nreset),
WhenNot(dut.overflow)
),
- Printable.pack("values(%d) = %d\n", dut.counter, dut.selected),
+ dut.p.pable,
dut.clock
- ))
+ ).toString)
}
)
}
@@ -153,5 +156,60 @@ class SelectSpec extends ChiselFlatSpec {
assert(bbs.size == 1)
}
+ "CloneModuleAsRecord" should "NOT show up in Select aspects" in {
+ import chisel3.experimental.CloneModuleAsRecord
+ class Child extends RawModule {
+ val in = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+ out := in
+ }
+ class Top extends Module {
+ val in = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+ val inst0 = Module(new Child)
+ val inst1 = CloneModuleAsRecord(inst0)
+ inst0.in := in
+ inst1("in") := inst0.out
+ out := inst1("out")
+ }
+ val top = ChiselGeneratorAnnotation(() => {
+ new Top()
+ }).elaborate
+ .collectFirst { case DesignAnnotation(design: Top) => design }
+ .get
+ Select.collectDeep(top) { case x => x } should equal (Seq(top, top.inst0))
+ Select.getDeep(top)(x => Seq(x)) should equal (Seq(top, top.inst0))
+ Select.instances(top) should equal (Seq(top.inst0))
+ }
+
+ "Using Definition/Instance with Injecting Aspects" should "throw an error" in {
+ import chisel3.experimental.CloneModuleAsRecord
+ import chisel3.experimental.hierarchy._
+ @instantiable
+ class Child extends RawModule {
+ @public val in = IO(Input(UInt(8.W)))
+ @public val out = IO(Output(UInt(8.W)))
+ out := in
+ }
+ class Top extends Module {
+ val in = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+ val definition = Definition(new Child)
+ val inst0 = Instance(definition)
+ val inst1 = Instance(definition)
+ inst0.in := in
+ inst1.in := inst0.out
+ out := inst1.out
+ }
+ val top = ChiselGeneratorAnnotation(() => {
+ new Top()
+ }).elaborate
+ .collectFirst { case DesignAnnotation(design: Top) => design }
+ .get
+ intercept[Exception] { Select.collectDeep(top) { case x => x } }
+ intercept[Exception] { Select.getDeep(top)(x => Seq(x)) }
+ intercept[Exception] { Select.instances(top) }
+ }
+
}