Skip to content

Commit

Permalink
[script] add support for difftest wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed May 25, 2024
1 parent 76d3c5b commit 3cb334f
Showing 1 changed file with 58 additions and 13 deletions.
71 changes: 58 additions & 13 deletions script/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -647,21 +659,9 @@ object Main:
// but all we need is the <config> 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"
Expand Down Expand Up @@ -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

0 comments on commit 3cb334f

Please sign in to comment.