diff --git a/src/main/scala/diplomacy/LazyModule.scala b/src/main/scala/diplomacy/LazyModule.scala index 48243e61..4f56dc6f 100644 --- a/src/main/scala/diplomacy/LazyModule.scala +++ b/src/main/scala/diplomacy/LazyModule.scala @@ -36,7 +36,8 @@ abstract class LazyModule()(implicit val p: Parameters) getClass.getMethods.filter { m => m.getParameterTypes.isEmpty && !java.lang.reflect.Modifier.isStatic(m.getModifiers) && - m.getName != "children" + m.getName != "children" && + m.getName != "getChildren" }.flatMap { m => if (classOf[LazyModule].isAssignableFrom(m.getReturnType)) { val obj = m.invoke(this) @@ -126,6 +127,8 @@ abstract class LazyModule()(implicit val p: Parameters) iterfunc(this) children.foreach( _.nodeIterator(iterfunc) ) } + + def getChildren = children } object LazyModule diff --git a/src/main/scala/unittest/TestGenerator.scala b/src/main/scala/unittest/TestGenerator.scala new file mode 100644 index 00000000..668031ee --- /dev/null +++ b/src/main/scala/unittest/TestGenerator.scala @@ -0,0 +1,35 @@ +// See LICENSE.SiFive for license details. + +package freechips.rocketchip.unittest + +import Chisel._ +import freechips.rocketchip.config._ +import freechips.rocketchip.diplomacy._ + +abstract class LazyUnitTest(implicit p: Parameters) extends LazyModule +{ self => + protected def finished: Bool + + lazy val module = new LazyModuleImp(this) { + val finished = IO(Bool(OUTPUT)) + finished := self.finished + } +} + +// FYI, you can call .finished on a Seq[LazyUnitTest] +class TestGenerator(gen: LazyModule => Seq[LazyUnitTest]) +{ + def apply(lm: LazyModule) = gen(lm) + def ++ (other: TestGenerator) = new TestGenerator(gen = lm => gen(lm) ++ other(lm)) +} + +object TestGenerator +{ + def apply(matcher: PartialFunction[LazyModule, Seq[LazyUnitTest]]): TestGenerator = + new TestGenerator(gen = matcher.lift(_).getOrElse(Nil)) + def recurse(other: TestGenerator): TestGenerator = { + def helper(lm: LazyModule, tail: Seq[LazyUnitTest]): Seq[LazyUnitTest] = + lm.getChildren.foldLeft(other(lm) ++ tail) { case (tail, child) => helper(child, tail) } + new TestGenerator(gen = helper(_, Nil)) + } +} diff --git a/src/main/scala/unittest/package.scala b/src/main/scala/unittest/package.scala new file mode 100644 index 00000000..9b58192c --- /dev/null +++ b/src/main/scala/unittest/package.scala @@ -0,0 +1,12 @@ +// See LICENSE.SiFive for license details. + +package freechips.rocketchip + +import Chisel._ + +package object unittest +{ + implicit class LazyUnitTestSeq(val seq: Seq[LazyUnitTest]) { + def finished = seq.map(_.module.finished).foldLeft(Bool(true))(_ && _) + } +}