-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sc
More file actions
77 lines (70 loc) · 3.95 KB
/
Copy pathtest.sc
File metadata and controls
77 lines (70 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//> using scala 3.8.4
//> using dep io.github.dfiantworks::scalapptainer:0.2.1
//> using dep com.lihaoyi::os-lib:0.11.4
// Validate DFTools images before they are published. Two modes:
//
// scala-cli run scripts/test.sc -- probe <image> <sif>
// Run the image's %test block and per-tool version probes inside the image.
//
// scala-cli run scripts/test.sc -- dfhdl <sif-dir> <dfhdl-checkout-dir>
// DFHDL gate: discover every dftools-<image>.sif under <sif-dir>, point DFHDL at each
// via `-Ddfhdl.dftools.sif.<image>=<path>`, and run the DFHDL unit-test suite (`test`)
// against the checkout. The per-image self-tests already ran in the build-test job
// (probe mode); this gate confirms the DFHDL build is healthy against these images.
import scalapptainer.*
// per-image self-test probes (bare in-image commands)
val probes: Map[String, Seq[Seq[String]]] = Map(
"synth-verilog" -> Seq(Seq("yosys", "-V")),
"synth-vhdl" -> Seq(Seq("ghdl", "version"), Seq("yosys", "-V"),
Seq("yosys", "-m", "ghdl", "-p", "help ghdl")),
"pnr" -> Seq(Seq("nextpnr-ecp5", "--version"), Seq("nextpnr-himbaechel", "--version")),
"sim-llvm" -> Seq(Seq("ghdl", "version"), Seq("nvc", "--version")),
"sim-verilator" -> Seq(Seq("verilator", "--version"), Seq("sh", "-c", "command -v g++ make perl")),
"sim-iverilog" -> Seq(Seq("iverilog", "-V")),
"wavegen" -> Seq(Seq("surfer", "--version")),
"program" -> Seq(Seq("openFPGALoader", "-V")),
"hmi" -> Seq(Seq("ffmpeg", "-version"), Seq("fpga-isv", "--help"))
)
require(args.length >= 2, "usage: test.sc probe <image> <sif> | test.sc dfhdl <sif-dir> <dfhdl-dir>")
args(0) match
case "probe" =>
val image = args(1)
val sif = args(2)
val img = Apptainer.image(sif)
require(img.exists, s"image not found: $sif")
println(s"[dftools-test] apptainer test ($image) ...")
Apptainer.exec(Seq("test", sif)).throwIfFailed()
val failures = probes.getOrElse(image, Nil).flatMap { cmd =>
val r = img.exec(cmd*)
val tag = cmd.mkString(" ")
if r.succeeded then { println(s" ok : $tag"); None }
else { println(s" FAIL : $tag\n${r.out}"); Some(tag) }
}
require(failures.isEmpty, s"image probes failed: ${failures.mkString(", ")}")
println(s"[dftools-test] $image OK")
case "dfhdl" =>
val sifDir = os.Path(args(1), os.pwd)
val dfhdlDir = os.Path(args(2), os.pwd)
// map each present image to its sif via the per-image override system property.
// sif files are named dftools-<image>.sif or dftools-<image>-<arch>.sif.
val sifs = os.list(sifDir).filter(p => p.last.endsWith(".sif"))
val overrides = probes.keys.toSeq.flatMap { image =>
sifs.find(p => p.last == s"dftools-$image.sif" || p.last.startsWith(s"dftools-$image-"))
.map(p => s"-Ddfhdl.dftools.sif.$image=${p.toString}")
}
require(overrides.nonEmpty, s"no dftools-*.sif found under $sifDir")
// local dev on Windows uses the fast sbt client; CI (Linux) uses plain `sbt`, the
// same launcher DFHDL's own CI runs.
val sbtCmd = if scala.util.Properties.isWin then "sbtn.bat" else "sbt"
// Pass the per-image sif overrides as JVM system properties straight to the sbt
// launcher (it forwards leading -D args to the JVM). The `test` suite is pure
// code-generation/string-assertion munit tests and does not invoke external tools,
// but with the dftools default these props keep any image lookup pointed at the
// freshly built sifs rather than an unpublished release.
println(s"[dftools-test] DFHDL gate in $dfhdlDir with:\n ${overrides.mkString("\n ")}")
val res = os.proc(sbtCmd, overrides, "test")
.call(cwd = dfhdlDir, check = false, stdout = os.Inherit, stderr = os.Inherit)
require(res.exitCode == 0, s"DFHDL test failed (exit ${res.exitCode})")
println("[dftools-test] DFHDL gate passed.")
case other =>
sys.error(s"unknown mode '$other' (expected: probe | dfhdl)")