summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/aop
diff options
context:
space:
mode:
authorJack Koenig2022-01-10 10:39:52 -0800
committerJack Koenig2022-01-10 15:53:55 -0800
commit3131c0daad41dea78bede4517669e376c41a325a (patch)
tree55baed78a6a01f80ff3952a08233ca553a19964f /src/test/scala/chiselTests/aop
parentdd36f97a82746cec0b25b94651581fe799e24579 (diff)
Apply scalafmt
Command: sbt scalafmtAll
Diffstat (limited to 'src/test/scala/chiselTests/aop')
-rw-r--r--src/test/scala/chiselTests/aop/InjectionSpec.scala63
-rw-r--r--src/test/scala/chiselTests/aop/SelectSpec.scala94
2 files changed, 91 insertions, 66 deletions
diff --git a/src/test/scala/chiselTests/aop/InjectionSpec.scala b/src/test/scala/chiselTests/aop/InjectionSpec.scala
index a28501a5..9b29b0ba 100644
--- a/src/test/scala/chiselTests/aop/InjectionSpec.scala
+++ b/src/test/scala/chiselTests/aop/InjectionSpec.scala
@@ -38,12 +38,15 @@ object InjectionHierarchy {
val in = Input(Bool())
})
//scalastyle:off regex
- setInline("SubmoduleC.v", s"""
- |module SubmoduleC(
- | input io_in
- |);
- |endmodule
- """.stripMargin)
+ setInline(
+ "SubmoduleC.v",
+ s"""
+ |module SubmoduleC(
+ | input io_in
+ |);
+ |endmodule
+ """.stripMargin
+ )
}
class AspectTester(results: Seq[Int]) extends BasicTester {
@@ -63,26 +66,26 @@ object InjectionHierarchy {
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: 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: 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 =>
+ { 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
@@ -91,8 +94,8 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
)
val duplicateSubmoduleAspect = InjectingAspect(
- {dut: SubmoduleManipulationTester => Seq(dut)},
- {_: SubmoduleManipulationTester =>
+ { 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
@@ -101,8 +104,8 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
)
val addingExternalModules = InjectingAspect(
- {dut: SubmoduleManipulationTester => Seq(dut)},
- {_: SubmoduleManipulationTester =>
+ { dut: SubmoduleManipulationTester => Seq(dut) },
+ { _: SubmoduleManipulationTester =>
// By creating a second SubmoduleA, the module names would conflict unless they were uniquified
val moduleSubmoduleC = Module(new SubmoduleC)
//if we're here then we've elaborated correctly
@@ -123,30 +126,36 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
)
"Test" should "pass if inserted the correct values" in {
- assertTesterPasses{ new AspectTester(Seq(0, 1, 2)) }
+ assertTesterPasses { new AspectTester(Seq(0, 1, 2)) }
}
"Test" should "fail if inserted the wrong values" in {
- assertTesterFails{ new AspectTester(Seq(9, 9, 9)) }
+ 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)
+ 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
+ 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))
+ 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)
+ assertTesterPasses(
+ { new SubmoduleManipulationTester },
+ Nil,
+ Seq(manipulateSubmoduleAspect) ++ TesterDriver.verilatorOnly
+ )
}
"Module name collisions when adding a new module" should "be resolved" in {
assertTesterPasses(
- { new SubmoduleManipulationTester},
+ { new SubmoduleManipulationTester },
Nil,
Seq(duplicateSubmoduleAspect) ++ TesterDriver.verilatorOnly
)
@@ -154,7 +163,7 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
"Adding external modules" should "work" in {
assertTesterPasses(
- { new SubmoduleManipulationTester},
+ { new SubmoduleManipulationTester },
Nil,
Seq(addingExternalModules) ++ TesterDriver.verilatorOnly
)
@@ -162,7 +171,7 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
"Injection into multiple submodules of the same class" should "work" in {
assertTesterPasses(
- {new MultiModuleInjectionTester},
+ { 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 2b47c6b8..72802c80 100644
--- a/src/test/scala/chiselTests/aop/SelectSpec.scala
+++ b/src/test/scala/chiselTests/aop/SelectSpec.scala
@@ -39,22 +39,35 @@ case class SelectAspect[T <: RawModule, X](selector: T => Seq[X], desired: 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!")
+ 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
+ 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"))
+ 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 = {
+ 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),
@@ -85,16 +98,20 @@ class SelectSpec extends ChiselFlatSpec {
() => 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)
+ 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
+ )
}
)
}
@@ -104,8 +121,10 @@ class SelectSpec extends ChiselFlatSpec {
() => 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))
+ Seq(
+ PredicatedConnect(Nil, dut.counter, dut.added, false),
+ PredicatedConnect(Seq(When(dut.overflow)), dut.counter, dut.zero, false)
+ )
}
)
}
@@ -121,7 +140,7 @@ class SelectSpec extends ChiselFlatSpec {
"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 => Select.ops(dut).collect { case ("tail", d) => d } },
{ dut: SelectTester => Seq(dut.added, dut.zero) }
)
}
@@ -131,20 +150,22 @@ class SelectSpec extends ChiselFlatSpec {
() => 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
- ))
+ 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 BB extends ExtModule {}
class Top extends RawModule {
val bb = Module(new BB)
}
@@ -173,12 +194,10 @@ class SelectSpec extends ChiselFlatSpec {
}
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))
+ }).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 {
@@ -202,13 +221,10 @@ class SelectSpec extends ChiselFlatSpec {
}
val top = ChiselGeneratorAnnotation(() => {
new Top()
- }).elaborate
- .collectFirst { case DesignAnnotation(design: Top) => design }
- .get
+ }).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) }
}
}
-