From af415532cf160e63e971ceb301833b8433c18a50 Mon Sep 17 00:00:00 2001 From: Aditya Naik Date: Thu, 23 Nov 2023 03:11:56 -0800 Subject: cleanup --- src/test/scala/chiselTests/aop/InjectionSpec.scala | 180 ---------------- src/test/scala/chiselTests/aop/SelectSpec.scala | 230 --------------------- 2 files changed, 410 deletions(-) delete mode 100644 src/test/scala/chiselTests/aop/InjectionSpec.scala delete mode 100644 src/test/scala/chiselTests/aop/SelectSpec.scala (limited to 'src/test/scala/chiselTests/aop') diff --git a/src/test/scala/chiselTests/aop/InjectionSpec.scala b/src/test/scala/chiselTests/aop/InjectionSpec.scala deleted file mode 100644 index 1b69efa3..00000000 --- a/src/test/scala/chiselTests/aop/InjectionSpec.scala +++ /dev/null @@ -1,180 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -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} - -object InjectionHierarchy { - - class SubmoduleManipulationTester extends BasicTester { - 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()) - }) - io.out := false.B - } - - class SubmoduleB extends Module { - val io = IO(new Bundle { - val in = Input(Bool()) - }) - } - - class SubmoduleC extends experimental.ExtModule with util.HasExtModuleInline { - val io = IO(new Bundle { - val in = Input(Bool()) - }) - //scalastyle:off regex - setInline( - "SubmoduleC.v", - s""" - |module SubmoduleC( - | input io_in - |); - |endmodule - """.stripMargin - ) - } - - class AspectTester(results: Seq[Int]) extends BasicTester { - val values = VecInit(results.map(_.U)) - val counter = RegInit(0.U(results.length.W)) - counter := counter + 1.U - when(counter >= values.length.U) { - stop() - }.otherwise { - when(reset.asBool() === false.B) { - assert(counter === values(counter)) - } - } - } -} - -class InjectionSpec extends ChiselFlatSpec with Utils { - import InjectionHierarchy._ - val correctValueAspect = InjectingAspect( - { dut: AspectTester => Seq(dut) }, - { dut: AspectTester => - for (i <- 0 until dut.values.length) { - dut.values(i) := i.U - } - } - ) - - val wrongValueAspect = InjectingAspect( - { dut: AspectTester => Seq(dut) }, - { dut: AspectTester => - for (i <- 0 until dut.values.length) { - dut.values(i) := (i + 1).U - } - } - ) - - val manipulateSubmoduleAspect = InjectingAspect( - { dut: SubmoduleManipulationTester => Seq(dut) }, - { dut: SubmoduleManipulationTester => - val moduleSubmoduleB = Module(new SubmoduleB) - moduleSubmoduleB.io.in := dut.moduleSubmoduleA.io.out - //if we're here then we've elaborated correctly - stop() - } - ) - - val duplicateSubmoduleAspect = InjectingAspect( - { dut: SubmoduleManipulationTester => Seq(dut) }, - { _: SubmoduleManipulationTester => - // By creating a second SubmoduleA, the module names would conflict unless they were uniquified - val moduleSubmoduleA2 = Module(new SubmoduleA) - //if we're here then we've elaborated correctly - stop() - } - ) - - val addingExternalModules = InjectingAspect( - { dut: SubmoduleManipulationTester => Seq(dut) }, - { _: SubmoduleManipulationTester => - // By creating a second SubmoduleA, the module names would conflict unless they were uniquified - val moduleSubmoduleC = Module(new SubmoduleC) - moduleSubmoduleC.io <> DontCare - //if we're here then we've elaborated correctly - stop() - } - ) - - 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)) } - } - "Test" should "fail if inserted the wrong values" in { - assertTesterFails { new AspectTester(Seq(9, 9, 9)) } - } - "Test" should "pass if pass wrong values, but correct with aspect" in { - assertTesterPasses({ new AspectTester(Seq(9, 9, 9)) }, Nil, Seq(correctValueAspect) ++ TesterDriver.verilatorOnly) - } - "Test" should "pass if pass wrong values, then wrong aspect, then correct aspect" in { - assertTesterPasses( - new AspectTester(Seq(9, 9, 9)), - Nil, - Seq(wrongValueAspect, correctValueAspect) ++ TesterDriver.verilatorOnly - ) - } - "Test" should "fail if pass wrong values, then correct aspect, then wrong aspect" in { - assertTesterFails({ new AspectTester(Seq(9, 9, 9)) }, Nil, Seq(correctValueAspect, wrongValueAspect)) - } - - "Test" should "pass if the submodules in SubmoduleManipulationTester can be manipulated by manipulateSubmoduleAspect" in { - assertTesterPasses( - { new SubmoduleManipulationTester }, - Nil, - Seq(manipulateSubmoduleAspect) ++ TesterDriver.verilatorOnly - ) - } - - "Module name collisions when adding a new module" should "be resolved" in { - assertTesterPasses( - { new SubmoduleManipulationTester }, - Nil, - Seq(duplicateSubmoduleAspect) ++ TesterDriver.verilatorOnly - ) - } - - "Adding external modules" should "work" in { - assertTesterPasses( - { new SubmoduleManipulationTester }, - Nil, - 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 deleted file mode 100644 index 72802c80..00000000 --- a/src/test/scala/chiselTests/aop/SelectSpec.scala +++ /dev/null @@ -1,230 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package chiselTests.aop - -import chisel3.testers.BasicTester -import chiselTests.ChiselFlatSpec -import chisel3._ -import chisel3.aop.Select.{PredicatedConnect, When, WhenNot} -import chisel3.aop.{Aspect, Select} -import chisel3.experimental.ExtModule -import chisel3.stage.{ChiselGeneratorAnnotation, DesignAnnotation} -import firrtl.AnnotationSeq - -import scala.reflect.runtime.universe.TypeTag - -class SelectTester(results: Seq[Int]) extends BasicTester { - val values = VecInit(results.map(_.U)) - val counter = RegInit(0.U(results.length.W)) - val added = counter + 1.U - counter := added - val overflow = counter >= values.length.U - 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)) - p = printf("values(%d) = %d\n", counter, selected) - } - - } -} - -case class SelectAspect[T <: RawModule, X](selector: T => Seq[X], desired: T => Seq[X]) extends Aspect[T] { - override def toAnnotation(top: T): AnnotationSeq = { - val results = selector(top) - val desiredSeq = desired(top) - assert( - results.length == desiredSeq.length, - s"Failure! Results $results have different length than desired $desiredSeq!" - ) - val mismatches = results.zip(desiredSeq).flatMap { - case (res, des) if res != des => Seq((res, des)) - case other => Nil - } - assert( - mismatches.isEmpty, - s"Failure! The following selected items do not match their desired item:\n" + mismatches.map { - case (res: Select.Serializeable, des: Select.Serializeable) => - s" ${res.serialize} does not match:\n ${des.serialize}" - case (res, des) => s" $res does not match:\n $des" - }.mkString("\n") - ) - Nil - } -} - -class SelectSpec extends ChiselFlatSpec { - - def execute[T <: RawModule, X]( - dut: () => T, - selector: T => Seq[X], - desired: T => Seq[X] - )( - implicit tTag: TypeTag[T] - ): Unit = { - val ret = new chisel3.stage.ChiselStage().run( - Seq( - new chisel3.stage.ChiselGeneratorAnnotation(dut), - SelectAspect(selector, desired), - new chisel3.stage.ChiselOutputFileAnnotation("test_run_dir/Select.fir") - ) - ) - } - - "Test" should "pass if selecting correct registers" in { - execute( - () => new SelectTester(Seq(0, 1, 2)), - { dut: SelectTester => Select.registers(dut) }, - { dut: SelectTester => Seq(dut.counter) } - ) - } - - "Test" should "pass if selecting correct wires" in { - execute( - () => new SelectTester(Seq(0, 1, 2)), - { dut: SelectTester => Select.wires(dut) }, - { dut: SelectTester => Seq(dut.values) } - ) - } - - "Test" should "pass if selecting correct printfs" in { - execute( - () => new SelectTester(Seq(0, 1, 2)), - { 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) - ), - dut.p.pable, - dut.clock - ) - .toString - ) - } - ) - } - - "Test" should "pass if selecting correct connections" in { - execute( - () => new SelectTester(Seq(0, 1, 2)), - { dut: SelectTester => Select.connectionsTo(dut)(dut.counter) }, - { dut: SelectTester => - Seq( - PredicatedConnect(Nil, dut.counter, dut.added, false), - PredicatedConnect(Seq(When(dut.overflow)), dut.counter, dut.zero, false) - ) - } - ) - } - - "Test" should "pass if selecting ops by kind" in { - execute( - () => new SelectTester(Seq(0, 1, 2)), - { dut: SelectTester => Select.ops("tail")(dut) }, - { dut: SelectTester => Seq(dut.added, dut.zero) } - ) - } - - "Test" should "pass if selecting ops" in { - execute( - () => new SelectTester(Seq(0, 1, 2)), - { dut: SelectTester => Select.ops(dut).collect { case ("tail", d) => d } }, - { dut: SelectTester => Seq(dut.added, dut.zero) } - ) - } - - "Test" should "pass if selecting correct stops" in { - execute( - () => new SelectTester(Seq(0, 1, 2)), - { dut: SelectTester => Seq(Select.stops(dut).last) }, - { dut: SelectTester => - Seq( - Select.Stop( - Seq( - When(Select.ops("eq")(dut)(1).asInstanceOf[Bool]), - When(dut.overflow) - ), - 0, - dut.clock - ) - ) - } - ) - } - - "Blackboxes" should "be supported in Select.instances" in { - class BB extends ExtModule {} - class Top extends RawModule { - val bb = Module(new BB) - } - val top = ChiselGeneratorAnnotation(() => { - new Top() - }).elaborate(1).asInstanceOf[DesignAnnotation[Top]].design - val bbs = Select.collectDeep(top) { case b: BB => b } - 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) } - } - -} -- cgit v1.2.3