Skip to content

Commit fe3e23f

Browse files
committed
Add flag to stop verilator simulation from writing a VCD (#211)
- Add new flag suppressVerilatorVCD to TesterOptions - setUpVerilatorBackend looks at this flag and uses it - added tests to show that this works - Based on feedback from review - make new top level testing flag "generate-vcd-output" - abbreviation is tgvo - on forces vcd output to on - off forces vcd output to off - default is on for verilator backend - default is off for interpreter and treadle (cherry picked from commit c2942e7)
1 parent 79981cf commit fe3e23f

File tree

6 files changed

+78
-20
lines changed

6 files changed

+78
-20
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def javacOptionsVersion(scalaVersion: String): Seq[String] = {
3535
}
3636

3737
organization := "edu.berkeley.cs"
38-
version := "1.2.4"
38+
version := "1.2.5"
3939
name := "Chisel.iotesters"
4040

4141
scalaVersion := "2.11.12"

src/main/scala/chisel3/iotesters/FirrtlTerpBackend.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ private[iotesters] object setupFirrtlTerpBackend {
125125
optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy(compilerName = "low")
126126
// Workaround to propagate Annotations generated from command-line options to second Firrtl
127127
// invocation, run after updating compilerName so we only get one emitCircuit annotation
128+
129+
// generate VcdOutput overrides setting of writeVcd
130+
if(optionsManager.testerOptions.generateVcdOutput == "on") {
131+
optionsManager.interpreterOptions = optionsManager.interpreterOptions.copy(writeVCD = true)
132+
}
133+
128134
val annos = firrtl.Driver.getAnnotations(optionsManager)
129135
optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy(annotations = annos.toList)
130136
chisel3.Driver.execute(optionsManager, dutGen) match {

src/main/scala/chisel3/iotesters/TesterOptions.scala

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ import treadle.HasTreadleSuite
1212
import scala.util.matching.Regex
1313

1414
case class TesterOptions(
15-
isGenVerilog: Boolean = false,
16-
isGenHarness: Boolean = false,
17-
isCompiling: Boolean = false,
18-
isRunTest: Boolean = false,
19-
isVerbose: Boolean = false,
20-
displayBase: Int = 10,
21-
testerSeed: Long = System.currentTimeMillis,
22-
testCmd: Seq[String] = Seq.empty,
23-
moreVcsFlags: Seq[String] = Seq.empty,
24-
moreVcsCFlags: Seq[String] = Seq.empty,
25-
vcsCommandEdits: String = "",
26-
backendName: String = "treadle",
27-
logFileName: String = "",
28-
waveform: Option[File] = None,
29-
moreIvlFlags: Seq[String] = Seq.empty,
30-
moreIvlCFlags: Seq[String] = Seq.empty,
31-
ivlCommandEdits: String = "") extends ComposableOptions
15+
isGenVerilog: Boolean = false,
16+
isGenHarness: Boolean = false,
17+
isCompiling: Boolean = false,
18+
isRunTest: Boolean = false,
19+
isVerbose: Boolean = false,
20+
displayBase: Int = 10,
21+
testerSeed: Long = System.currentTimeMillis,
22+
testCmd: Seq[String] = Seq.empty,
23+
moreVcsFlags: Seq[String] = Seq.empty,
24+
moreVcsCFlags: Seq[String] = Seq.empty,
25+
vcsCommandEdits: String = "",
26+
backendName: String = "treadle",
27+
logFileName: String = "",
28+
waveform: Option[File] = None,
29+
moreIvlFlags: Seq[String] = Seq.empty,
30+
moreIvlCFlags: Seq[String] = Seq.empty,
31+
ivlCommandEdits: String = "",
32+
generateVcdOutput: String = ""
33+
) extends ComposableOptions
3234

3335
object TesterOptions {
3436
val VcsFileCommands: Regex = """file:(.+)""".r
@@ -127,6 +129,18 @@ trait HasTesterOptions {
127129
.abbr("tts")
128130
.foreach { x => testerOptions = testerOptions.copy(testerSeed = x) }
129131
.text("provides a seed for random number generator")
132+
133+
parser.opt[String]("generate-vcd-output")
134+
.abbr("tgvo")
135+
.validate { x =>
136+
if(Seq("on", "off").contains(x.toLowerCase)) {
137+
parser.success
138+
} else {
139+
parser.failure("generateVcdOutput must be set to on or off")
140+
}
141+
}
142+
.foreach { x => testerOptions = testerOptions.copy(generateVcdOutput = x) }
143+
.text(s"""set this flag to "on" or "off", otherwise it defaults to on for verilator, off for scala backends""")
130144
}
131145

132146
class TesterOptionsManager

src/main/scala/chisel3/iotesters/TreadleBackend.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ private[iotesters] object setupTreadleBackend {
130130
// invocation, run after updating compilerName so we only get one emitCircuit annotation
131131
val annos = firrtl.Driver.getAnnotations(optionsManager)
132132
optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy(annotations = annos.toList)
133+
134+
// generate VcdOutput overrides setting of writeVcd
135+
if(optionsManager.testerOptions.generateVcdOutput == "on") {
136+
optionsManager.treadleOptions = optionsManager.treadleOptions.copy(writeVCD = true)
137+
}
138+
133139
chisel3.Driver.execute(optionsManager, dutGen) match {
134140
case ChiselExecutionSuccess(Some(circuit), _, Some(firrtlExecutionResult)) =>
135141
val dut = getTopModule(circuit).asInstanceOf[T]

src/main/scala/chisel3/iotesters/VerilatorBackend.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ private[iotesters] object setupVerilatorBackend {
210210
optionsManager.chiselOptions = optionsManager.chiselOptions.copy(
211211
runFirrtlCompiler = false
212212
)
213+
213214
val dir = new File(optionsManager.targetDirName)
214215

215216
// Generate CHIRRTL
@@ -219,6 +220,8 @@ private[iotesters] object setupVerilatorBackend {
219220
val chirrtl = firrtl.Parser.parse(emitted)
220221
val dut = getTopModule(circuit).asInstanceOf[T]
221222

223+
val suppressVerilatorVCD = optionsManager.testerOptions.generateVcdOutput == "off"
224+
222225
// This makes sure annotations for command line options get created
223226
val externalAnnotations = firrtl.Driver.getAnnotations(optionsManager)
224227

@@ -260,7 +263,8 @@ private[iotesters] object setupVerilatorBackend {
260263
circuit.name,
261264
dir,
262265
vSources = Seq(),
263-
cppHarnessFile
266+
cppHarnessFile,
267+
suppressVerilatorVCD
264268
).! == 0
265269
)
266270
assert(chisel3.Driver.cppToExe(circuit.name, dir).! == 0)

src/test/scala/examples/GCDSpec.scala

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
package examples
44

5+
import java.io.File
6+
57
import chisel3._
68
import chisel3.util._
79
import chisel3.iotesters._
8-
import org.scalatest.{Matchers, FlatSpec}
10+
import org.scalatest.{FlatSpec, Matchers}
911

1012
object RealGCD2 {
1113
val num_width = 16
@@ -110,5 +112,31 @@ class GCDSpec extends FlatSpec with Matchers {
110112
new GCDPeekPokeTester(c)
111113
} should be (true)
112114
}
115+
116+
"using verilator backend with suppress-verilator-backend" should "not create a vcd" in {
117+
iotesters.Driver.execute(
118+
Array("--backend-name", "verilator", "--generate-vcd-output", "off",
119+
"--target-dir", "test_run_dir/gcd_no_vcd", "--top-name", "gcd_no_vcd"),
120+
() => new RealGCD2
121+
) {
122+
123+
c => new GCDPeekPokeTester(c)
124+
} should be(true)
125+
126+
new File("test_run_dir/gcd_no_vcd/RealGCD2.vcd").exists() should be (false)
127+
}
128+
129+
"using verilator default behavior" should "create a vcd" in {
130+
iotesters.Driver.execute(
131+
Array("--backend-name", "verilator",
132+
"--target-dir", "test_run_dir/gcd_make_vcd", "--top-name", "gcd_make_vcd"),
133+
() => new RealGCD2
134+
) {
135+
136+
c => new GCDPeekPokeTester(c)
137+
} should be(true)
138+
139+
new File("test_run_dir/gcd_make_vcd/RealGCD2.vcd").exists() should be (true)
140+
}
113141
}
114142

0 commit comments

Comments
 (0)