diff options
Diffstat (limited to 'src/test/scala/chiselTests/ChiselSpec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/ChiselSpec.scala | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala index 2ee6fbcf..7980e772 100644 --- a/src/test/scala/chiselTests/ChiselSpec.scala +++ b/src/test/scala/chiselTests/ChiselSpec.scala @@ -14,6 +14,9 @@ import firrtl.annotations.DeletedAnnotation import firrtl.util.BackendCompilationUtilities import java.io.ByteArrayOutputStream import java.security.Permission + +import chisel3.aop.Aspect +import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage, NoRunFirrtlCompilerAnnotation, PrintFullStackTraceAnnotation} import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks import scala.reflect.ClassTag @@ -270,6 +273,27 @@ trait Utils { } } + + /** A tester which runs generator and uses an aspect to check the returned object + * @param gen function to generate a Chisel module + * @param f a function to check the Chisel module + * @tparam T the Chisel module class + */ + def aspectTest[T <: RawModule](gen: () => T)(f: T => Unit)(implicit scalaMajorVersion: Int): Unit = { + // Runs chisel stage + def run[T <: RawModule](gen: () => T, annotations: AnnotationSeq): AnnotationSeq = { + new ChiselStage().run(Seq(ChiselGeneratorAnnotation(gen), NoRunFirrtlCompilerAnnotation, PrintFullStackTraceAnnotation) ++ annotations) + } + // Creates a wrapping aspect to contain checking function + case object BuiltAspect extends Aspect[T] { + override def toAnnotation(top: T): AnnotationSeq = {f(top); Nil} + } + val currentMajorVersion = scala.util.Properties.versionNumberString.split('.')(1).toInt + if(currentMajorVersion >= scalaMajorVersion) { + run(gen, Seq(BuiltAspect)) + } + } + /** Run some code and rethrow an exception with a specific type if an exception of that type occurs anywhere in the * stack trace. * @@ -306,5 +330,4 @@ trait Utils { } } - } |
