Skip to content

Commit fa66db4

Browse files
author
Oron Port
committed
add testApps command
1 parent d38c5f0 commit fa66db4

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
commands += DFHDLCommands.quickTestSetup
2+
commands += DFHDLCommands.clearSandbox
3+
commands += DFHDLCommands.testApps
24
commands += DFHDLCommands.docExamplesRefUpdate
35

46
// format: off

lib/src/main/scala/dfhdl/app/DFApp.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ trait DFApp:
203203
end simRun
204204

205205
private def listBackends: Unit =
206-
println(
206+
System.out.println(
207207
s"""|Backend option pattern: -b <lang>[.<dialect>]
208208
|<lang> - the required backend language
209209
|<dialect> - the optional language dialect (each language has a default dialect)
@@ -237,7 +237,7 @@ trait DFApp:
237237
case Some(version) => s"Found version $version"
238238
case None => "Not found on your system"
239239
else ""
240-
println(
240+
System.out.println(
241241
s"""|Linter tool option pattern: -t [<verilogLinter>][/][<vhdlLinter>]
242242
|<verilogLinter> - the selected Verilog/SystemVerilog linter
243243
|<vhdlLinter> - the selected VHDL linter
@@ -271,7 +271,7 @@ trait DFApp:
271271
case Some(version) => s"Found version $version"
272272
case None => "Not found on your system"
273273
else ""
274-
println(
274+
System.out.println(
275275
s"""|Simulator tool option pattern: -t [<verilogSimulator>][/][<vhdlSimulator>]
276276
|<verilogSimulator> - the selected Verilog/SystemVerilog simulator
277277
|<vhdlSimulator> - the selected VHDL simulator
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package util
2+
import dfhdl.*
3+
//used to create an empty design app for testing
4+
@top class EmptyDesign extends DFDesign

project/DFHDLCommands.scala

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,72 @@ object DFHDLCommands {
6868

6969
state
7070
}
71+
72+
val clearSandbox = Command.command("clearSandbox") { state =>
73+
// Remove the sandbox folder and all its contents before running the tests
74+
val sandboxPath = java.nio.file.Paths.get("sandbox")
75+
if (java.nio.file.Files.exists(sandboxPath)) {
76+
import java.nio.file._
77+
import java.nio.file.attribute.BasicFileAttributes
78+
79+
Files.walkFileTree(
80+
sandboxPath,
81+
new SimpleFileVisitor[Path] {
82+
override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
83+
Files.delete(file)
84+
FileVisitResult.CONTINUE
85+
}
86+
override def postVisitDirectory(dir: Path, exc: java.io.IOException): FileVisitResult = {
87+
Files.delete(dir)
88+
FileVisitResult.CONTINUE
89+
}
90+
}
91+
)
92+
}
93+
state
94+
}
95+
96+
val vhdlTools = List("ghdl", "nvc", "questa", "vivado")
97+
val verilogTools = List("verilator", "iverilog", "questa", "vivado")
98+
val vhdlDialects = List("vhdl.v93", "vhdl.v2008")
99+
val verilogDialects = List("verilog.v95", "verilog.v2001", "verilog.sv2005")
100+
101+
val testApps = Command.command("testApps") { state =>
102+
var newState = Command.process("clearSandbox", state, _ => ())
103+
val extracted = Project.extract(newState)
104+
val runMainTask = LocalProject("lib") / Test / runMain
105+
val existingTools: Set[String] = {
106+
import java.io.{ByteArrayOutputStream, PrintStream}
107+
val baos = new ByteArrayOutputStream()
108+
val ps = new PrintStream(baos)
109+
val oldOut = System.out
110+
val oldErr = System.err
111+
val arguments = s" util.top_EmptyDesign help simulate-tool -s"
112+
try {
113+
System.setOut(ps)
114+
System.setErr(ps)
115+
val extracted = Project.extract(state)
116+
extracted.runInputTask(runMainTask, arguments, state)
117+
} finally {
118+
System.out.flush()
119+
System.err.flush()
120+
System.setOut(oldOut)
121+
System.setErr(oldErr)
122+
}
123+
val helpStr = baos.toString("UTF-8")
124+
val allTools = (vhdlTools ++ verilogTools).toSet
125+
allTools.filter(tool => helpStr.linesIterator.exists(line => line.contains(tool) && line.contains("Found version")))
126+
}
127+
for (tool <- vhdlTools if existingTools.contains(tool); dialect <- vhdlDialects) {
128+
val arguments = s" AES.top_CipherSim simulate -b $dialect -t $tool --Werror-tool"
129+
val (updatedState, _) = extracted.runInputTask(runMainTask, arguments, newState)
130+
newState = updatedState
131+
}
132+
for (tool <- verilogTools if existingTools.contains(tool); dialect <- verilogDialects) {
133+
val arguments = s" AES.top_CipherSim simulate -b $dialect -t $tool --Werror-tool"
134+
val (updatedState, _) = extracted.runInputTask(runMainTask, arguments, newState)
135+
newState = updatedState
136+
}
137+
newState
138+
}
71139
}

0 commit comments

Comments
 (0)