Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
writeVcd from command line, test run dir name from test
Browse files Browse the repository at this point in the history
  • Loading branch information
ducky64 committed Dec 5, 2018
1 parent 23f772b commit 72bec2c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/main/scala/chisel3/tester/ChiselScalatestTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ trait ChiselScalatestTester extends Assertions with TestSuiteMixin with TestEnvI
Context.run(tester, this, testFn)
}

def getTestOptions(): TesterOptions = {
val test = scalaTestContext.value.get
TesterOptions(test.name, test.configMap.contains("writeVcd"))
}

// This should be the only user-called function
def test[T <: MultiIOModule](dutGen: => T)(testFn: T => Unit) {
runTest(Context.createDefaultTester(() => dutGen, None))(testFn)
runTest(Context.createDefaultTester(() => dutGen, getTestOptions(), None))(testFn)
}

def test[T <: MultiIOModule](dutGen: => T, execOptions: ExecutionOptionsManager)(testFn: T => Unit) {
runTest(Context.createDefaultTester(() => dutGen, Some(execOptions)))(testFn)
runTest(Context.createDefaultTester(() => dutGen, getTestOptions(), Some(execOptions)))(testFn)
}
}
8 changes: 5 additions & 3 deletions src/main/scala/chisel3/tester/Testers2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import chisel3.experimental.MultiIOModule
import firrtl.ExecutionOptionsManager

// Internal common set of options to be understood by all backends
private[tester] case class Testers2Options(
private[tester] case class TesterOptions(
name: String,
writeVcd: Boolean
)

Expand All @@ -26,9 +27,10 @@ object Context {

// TODO: better integration points for default tester selection
// TODO: add TesterOptions (from chisel-testers) and use that to control default tester selection.
def createDefaultTester[T <: MultiIOModule](dutGen: () => T, execOptions: Option[ExecutionOptionsManager]
def createDefaultTester[T <: MultiIOModule](dutGen: () => T, testOptions: TesterOptions,
execOptions: Option[ExecutionOptionsManager]
): BackendInstance[T] = {
TreadleExecutive.start(dutGen, execOptions)
TreadleExecutive.start(dutGen, testOptions, execOptions)
}

def apply(): Instance = context.value.get
Expand Down
21 changes: 13 additions & 8 deletions src/main/scala/chisel3/tester/TreadleBackend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,34 +194,39 @@ object TreadleExecutive {

def start[T <: MultiIOModule](
dutGen: () => T,
userOptions: Option[ExecutionOptionsManager] = None): BackendInstance[T] = {
testOptions: TesterOptions,
execOptions: Option[ExecutionOptionsManager] = None): BackendInstance[T] = {
// Create the base options manager that has all the components we care about, and initialize defaults
val optionsManager = new ExecutionOptionsManager("chisel3")
with HasChiselExecutionOptions with HasFirrtlOptions with HasTreadleSuite

optionsManager.treadleOptions = optionsManager.treadleOptions.copy(writeVCD = true)

// If the user specified options, override the default fields.
// Note: commonOptions and firrtlOptions are part of every ExecutionOptionsManager, so will always be defined
// whether the user intended to or not. In those cases testers2 forces an override to the testers2 defaults.
userOptions foreach {
execOptions foreach {
case userOptions: HasChiselExecutionOptions => optionsManager.chiselOptions = userOptions.chiselOptions
case _ =>
}
optionsManager.commonOptions = optionsManager.commonOptions.copy(
targetDirName = s"test_run_dir/${dutGen.getClass.getName}")

userOptions foreach {
execOptions foreach {
case userOptions: HasFirrtlOptions => optionsManager.firrtlOptions = userOptions.firrtlOptions
case _ =>
}
optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy(compilerName = "low")

userOptions foreach {
execOptions foreach {
case userOptions: HasTreadleSuite => optionsManager.treadleOptions = userOptions.treadleOptions
case _ =>
}

// Tester options take priority over exec options
val testName = testOptions.name.replaceAll(" ", "_").replaceAll("\\W+", "") // sanitize filename
optionsManager.commonOptions = optionsManager.commonOptions.copy(
targetDirName = s"test_run_dir/$testName")
if (testOptions.writeVcd) {
optionsManager.treadleOptions = optionsManager.treadleOptions.copy(writeVCD = true)
}

// Force a cleanup: long SBT runs tend to fail with memory issues
System.gc()

Expand Down

0 comments on commit 72bec2c

Please sign in to comment.