diff --git a/script/src/Main.scala b/script/src/Main.scala index 5118c1984b..13c0a45ff1 100644 --- a/script/src/Main.scala +++ b/script/src/Main.scala @@ -635,6 +635,18 @@ object Main: println(ujson.write(Map("config" -> testPlans))) end generateTestPlan + def nixResolvePath(attr: String): String = + os.proc( + "nix", + "build", + "--no-link", + "--no-warn-dirty", + "--print-out-paths", + attr + ).call() + .out + .trim() + @main def generateRegressionTestPlan(runnersAmount: Int): Unit = // Find emulator configs @@ -647,21 +659,9 @@ object Main: // but all we need is the name. path.segments.toSeq.reverse.drop(1).head - def nixBuild(attr: String): String = - os.proc( - "nix", - "build", - "--no-link", - "--no-warn-dirty", - "--print-out-paths", - attr - ).call() - .out - .trim() - import scala.util.chaining._ val testPlans: Seq[String] = emulatorConfigs.flatMap: configName => - val allCasesPath = nixBuild(s".#t1.$configName.cases.all") + val allCasesPath = nixResolvePath(s".#t1.$configName.cases.all") os.walk(os.Path(allCasesPath) / "configs") .filter: path => path.ext == "json" @@ -700,5 +700,50 @@ object Main: .pipe(println) end generateRegressionTestPlan + @main + def difftest( + @arg( + name = "config", + short = 'c', + doc = "specify the elaborate config for running test case" + ) config: String, + @arg( + name = "case-attr", + short = 'C', + doc = "Specify test case attribute to run diff test" + ) caseAttr: String, + ): Unit = + Logger.info("Building simulator") + val difftest = nixResolvePath(".#t1-simulator") + + val fullCaseAttr = s".#t1.${config}.cases.${caseAttr}" + Logger.info(s"Building cases ${fullCaseAttr}") + val caseElf = nixResolvePath(fullCaseAttr) + + import scala.util.chaining._ + val configJson = nixResolvePath(s".#t1.${config}.elaborateConfigJson") + .pipe(p => os.Path(p)) + .pipe(p => os.read(p)) + .pipe(text => ujson.read(text)) + val dLen = configJson.obj("parameter").obj("dLen").num.toInt + val vLen = configJson.obj("parameter").obj("vLen").num.toInt + Logger.info(s"Using DLEN ${dLen}, VLEN ${vLen}") + + Logger.info(s"Running emulator to get event log") + val eventLog = nixResolvePath(s"${fullCaseAttr}.emu-result") + + os.proc(Seq( + s"${difftest}/bin/t1-simulator", + "--vlen", + vLen.toString(), + "--dlen", + dLen.toString(), + "--elf-file", + s"${caseElf}/bin/${caseAttr}.elf", + "--log-file", + s"${eventLog}/rtl-event.log", + )).call(stdout = os.Inherit, stderr = os.Inherit) + end difftest + def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) end Main