Skip to content

Commit

Permalink
[script] fix emu script to latest nix attr
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin authored and sequencer committed Oct 14, 2024
1 parent b021ea1 commit cc5e0b2
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions script/emu/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object Main:
os.proc(args).call().out.trim()

def resolveTestElfPath(
ip: String,
config: String,
caseName: String,
forceX86: Boolean = false
Expand All @@ -58,23 +59,24 @@ object Main:
else ".#"

val nixStorePath = resolveNixPath(
s"${caseAttrRoot}t1.${config}.ip.cases.${caseName}"
s"${caseAttrRoot}t1.${config}.${ip}.cases.${caseName}"
)
val elfFilePath = os.Path(nixStorePath) / "bin" / s"${caseName}.elf"

elfFilePath
end resolveTestElfPath

def resolveTestBenchPath(
ip: String,
config: String,
emuType: String
): os.Path =
val emuPath = os.Path(emuType, os.pwd)
if (os.exists(emuPath)) then return emuPath

val nixStorePath =
if emuType.contains("vcs-") then resolveNixPath(s".#t1.${config}.ip.${emuType}", Seq("--impure"))
else resolveNixPath(s".#t1.${config}.ip.${emuType}")
if emuType.contains("vcs-") then resolveNixPath(s".#t1.${config}.${ip}.${emuType}", Seq("--impure"))
else resolveNixPath(s".#t1.${config}.${ip}.${emuType}")

val elfFilePath = os
.walk(os.Path(nixStorePath) / "bin")
Expand Down Expand Up @@ -142,6 +144,11 @@ object Main:
if (cond) then input else null

@main def run(
@arg(
name = "ip",
short = 'i',
doc = "IP type for emulator, Eg. t1emu, t1rocketemu"
) ip: Option[String],
@arg(
name = "emu",
short = 'e',
Expand Down Expand Up @@ -178,6 +185,12 @@ object Main:
val caseName = leftOver.value.head
if !isValidCaseName(caseName) then Logger.fatal(s"invalid caseName '$caseName', expect 'A.B'")

val finalIp = tryRestoreFromCache("ip", ip)
if finalIp.isEmpty then
Logger.fatal(
s"No cached IP selection nor --ip argument was provided"
)

val finalEmuType = tryRestoreFromCache("emulator", emuType)
if finalEmuType.isEmpty then
Logger.fatal(
Expand All @@ -198,9 +211,9 @@ object Main:
)

val caseElfPath =
resolveTestElfPath(finalConfig.get, caseName, forceX86)
resolveTestElfPath(finalIp.get, finalConfig.get, caseName, forceX86)
val outputPath = prepareOutputDir(outDir.getOrElse("t1-sim-result"))
val emulator = resolveTestBenchPath(finalConfig.get, finalEmuType.get)
val emulator = resolveTestBenchPath(finalIp.get, finalConfig.get, finalEmuType.get)

val leftOverArguments = leftOver.value.dropWhile(arg => arg != "--")

Expand All @@ -226,7 +239,8 @@ object Main:
ujson.Obj(
"config" -> finalConfig.get,
"elf" -> caseElfPath.toString,
"event" -> rtlEventPath.toString
"event" -> rtlEventPath.toString,
"ip" -> finalIp.get
)
)
)
Expand Down Expand Up @@ -281,6 +295,11 @@ object Main:

@main
def check(
@arg(
name = "ip",
short = 'i',
doc = "IP type for emulator, Eg. t1emu, t1rocketemu"
) ip: Option[String],
@arg(
name = "config",
short = 'c',
Expand Down Expand Up @@ -316,6 +335,14 @@ object Main:
if os.exists(resultPath) then ujson.read(os.read(resultPath / "driver-state.json"))
else ujson.Obj()

val finalIp =
if ip.isDefined then ip.get
else
lastState.obj
.get("ip")
.getOrElse(Logger.fatal("No driver-state.json nor --ip"))
.str

val finalConfig =
if config.isDefined then config.get
else
Expand All @@ -325,11 +352,11 @@ object Main:
.str

val offlineChecker = os.Path(
resolveNixPath(s".#t1.${finalConfig}.ip.offline-checker")
resolveNixPath(s".#t1.${finalConfig}.${finalIp}.offline-checker")
) / "bin" / "offline"

val elfFile =
if caseAttr.isDefined then resolveTestElfPath(finalConfig, caseAttr.get).toString
if caseAttr.isDefined then resolveTestElfPath(finalIp, finalConfig, caseAttr.get).toString
else
lastState.obj
.get("elf")
Expand Down Expand Up @@ -362,6 +389,11 @@ object Main:

@main
def listCases(
@arg(
name = "ip",
short = 'i',
doc = "specify the IP, such as t1emu, t1rocketemu"
) ip: String,
@arg(
name = "config",
short = 'c',
Expand All @@ -378,7 +410,7 @@ object Main:
"nix",
"--no-warn-dirty",
"eval",
s".#t1.${config}.ip.cases",
s".#t1.${config}.${ip}.cases",
"--apply",
"""cases: with builtins;
| (map
Expand Down

0 comments on commit cc5e0b2

Please sign in to comment.