From d7859368c1a88bb81469e59fa47baf243a6d47f7 Mon Sep 17 00:00:00 2001 From: Jiuyang Liu Date: Sun, 22 Oct 2023 02:48:29 +0800 Subject: [PATCH] add tests.sc to split tests from common.sc --- build.sc | 28 +++++++++++++- tests.sc | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 tests.sc diff --git a/build.sc b/build.sc index 57bb8f97a0d..c6cedc4c9ce 100644 --- a/build.sc +++ b/build.sc @@ -1,11 +1,11 @@ import mill._ import mill.scalalib._ -import mill.scalalib.TestModule._ import mill.scalalib.publish._ import mill.scalalib.scalafmt._ -import coursier.maven.MavenRepository +import mill.define.Cross import mill.scalalib.api.ZincWorkerUtil.matchingVersions import $file.common +import $file.tests object v { val pluginScalaCrossVersions = Seq( @@ -276,3 +276,27 @@ trait CIRCTPanamaBinderModuleTest Seq(PathRef(millSourcePath / "src" / "test")) } } + +object filecheckutility extends Cross[LitUtility](v.scalaCrossVersions) + +trait LitUtility + extends tests.LitUtilityModule + with CrossModuleBase + with ScalafmtModule { + def millSourcePath = super.millSourcePath / "utility" + def circtPanamaBinderModule = circtpanamabinder(crossScalaVersion) +} + +object lit extends Cross[Lit](v.scalaCrossVersions) + +trait Lit + extends tests.LitModule + with Cross.Module[String] { + def scalaVersion: T[String] = crossValue + def runClasspath: T[Seq[os.Path]] = T(filecheckutility(crossValue).runClasspath().map(_.path)) + def pluginJars: T[Seq[os.Path]] = T(Seq(filecheckutility(crossValue).circtPanamaBinderModule.pluginModule.jar().path)) + def javaLibraryPath: T[Seq[os.Path]] = T(filecheckutility(crossValue).circtPanamaBinderModule.libraryPaths().map(_.path)) + def javaHome: T[os.Path] = T(os.Path(sys.props("java.home"))) + def chiselLitDir: T[os.Path] = T(millSourcePath) + def litConfigIn: T[PathRef] = T.source(millSourcePath / "tests" / "lit.site.cfg.py.in") +} diff --git a/tests.sc b/tests.sc new file mode 100644 index 00000000000..841920048ae --- /dev/null +++ b/tests.sc @@ -0,0 +1,114 @@ +import mill._ +import mill.api.Result +import mill.scalalib._ +import mill.scalalib.api.CompilationResult +import mill.util.Jvm + +import java.util +import scala.jdk.StreamConverters.StreamHasToScala + +trait SvsimUnitTestModule + extends TestModule + with ScalaModule + with TestModule.ScalaTest { + def svsimModule: common.SvsimModule + + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def moduleDeps = Seq(svsimModule) + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait FirrtlUnitTestModule + extends TestModule + with ScalaModule + with TestModule.ScalaTest { + def firrtlModule: common.FirrtlModule + + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def moduleDeps = Seq(firrtlModule) + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait ChiselUnitTestModule + extends TestModule + with ScalaModule + with common.HasChisel + with common.HasMacroAnnotations + with TestModule.ScalaTest { + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait CIRCTPanamaBinderModuleTestModule + extends TestModule + with ScalaModule + with common.HasCIRCTPanamaBinderModule + with common.HasMacroAnnotations + with TestModule.ScalaTest { + def scalatestIvy: Dep + + def scalacheckIvy: Dep + + override def defaultCommandName() = "test" + + override def ivyDeps = super.ivyDeps() ++ Agg( + scalatestIvy, + scalacheckIvy + ) +} + +trait LitUtilityModule + extends ScalaModule + with common.HasCIRCTPanamaBinderModule + with common.HasMacroAnnotations + +trait LitModule + extends Module { + def scalaVersion: T[String] + def runClasspath: T[Seq[os.Path]] + def pluginJars: T[Seq[os.Path]] + def javaLibraryPath: T[Seq[os.Path]] + def javaHome: T[os.Path] + def chiselLitDir: T[os.Path] + def litConfigIn: T[PathRef] + def litConfig: T[PathRef] = T { + os.write( + T.dest / "lit.site.cfg.py", + os.read(litConfigIn().path) + .replaceAll("@SCALA_VERSION@", scalaVersion()) + .replaceAll("@RUN_CLASSPATH@", runClasspath().mkString(",")) + .replaceAll("@SCALA_PLUGIN_JARS@", pluginJars().mkString(",")) + .replaceAll("@JAVA_HOME@", javaHome().toString) + .replaceAll("@JAVA_LIBRARY_PATH@", javaLibraryPath().mkString(",")) + .replaceAll("@CHISEL_LIT_DIR@", chiselLitDir().toString) + ) + PathRef(T.dest) + } + def run(args: String*) = T.command(os.proc("llvm-lit", litConfig().path).call(T.dest, stdout = os.ProcessOutput.Readlines(line => T.ctx().log.debug("[lit] " + line)))) + }