-
Notifications
You must be signed in to change notification settings - Fork 637
[Chiselsim] Replace Chiselspec w/ ChiselSim #4706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
behavior.of("BoringUtils.{addSink, addSource}") | ||
behavior.of("BoringUtils.addSink and BoringUtils.addSource") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verilator or the Makefiles we generate have problems with some more exotic symbols. I need to circle back and replace these with simpler ones, like we do for whitespace.
58a1586
to
bd1218d
Compare
runTester( | ||
new ShouldntAssertTester { val dut = Module(new BoringInverter) } | ||
) should be(true) | ||
simulate(new ShouldntAssertTester { val dut = Module(new BoringInverter) })(Stimulus.runUntilFinished(3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is neat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I was primarily concerned about. Two alternatives to this API are a dedicated simulateWithTimeout
or a default argument timeout: BigInt
to this method. I liked the factoring in this patch better as it seemed like keeping all stimulus separate was cleaner.
def runUntilFinished[T <: Module](maxCycles: Int): (T) => Unit = { dut => | ||
AnySimulatedModule.current | ||
.port(dut.clock) | ||
.tick( | ||
timestepsPerPhase = 1, | ||
maxCycles = maxCycles, | ||
inPhaseValue = 1, | ||
outOfPhaseValue = 0, | ||
sentinel = None, | ||
checkElapsedCycleCount = (count: BigInt) => { | ||
if (count == maxCycles) | ||
throw new Exceptions.Timeout(maxCycles, "Expected a $finish, but none received") | ||
} | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good--we could consider doing a typeclass instead of T <: Module
. I say that because this won't be overloadable with other types so if someone wanted to use runUnitFinished
for a type like BasicTester
(or some future new version of that that has a done
output like in the new inline unit testing stuff), then they'd have to give the new function a different name. Not sure if it's worthwhile and we can also add it later in a source-compatible way so not sure it matters now. Just pointing it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched to a type class style approach in d33e461. Let me know what you think. (There are comments included in a later commit. It is best to just view the complete diff.)
c160dba
to
098d81d
Compare
16ec7fe
to
ac56d63
Compare
098d81d
to
b966876
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
src/main/scala/chisel3/simulator/stimulus/RunUntilFinished.scala
Outdated
Show resolved
Hide resolved
b966876
to
2ed0865
Compare
Add a generic Timeout exception that can be used to indicate that a simulation failed due to something that was supposed to happen within a timeout, but did not. This is intended to be used by other, higher-level Simulator APIs. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add a new package, `chisel3.simulator.stimulus`, that contains canned stimulus for use with ChiselSim. Add one stimulus to this package, `RunUntilFinished`, which will run a simulation and expect it to terminate naturally (via `chisel3.stop`, i.e., a Verilog `$finish`). If the simulation runs, but does not finish, then throw a timeout-specific exception. Use a type class pattern for this, as suggested by @jackkoenig with implementation generators for `Module`, when provided with a timeout, and any type when provided with a timeout and a function to get a `Clock`. This moves towards removing the unpublished ChiselSpec (which is currently part of the tests), but forms a core component of how users are expected to use ChiselSim. This works towards providing a published replacement for ChiselSpec that avoids downstream users having to effectively replicate ChiselSpec. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Replace existing usages of ChiselSpec.runTester with ChiselSim APIs. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2ed0865
to
89ce522
Compare
Add timeout exception and
runUntilFinished
. Use this to replace some usages ofChiselSpec
.This is stacked on #4699. This PR is intended to show where I am going with this and to get buy-in on how tests will look before rolling this out everywhere (to replace more widely used
ChiselSpec
methods likeassertTesterPasses
andassertTesterFails
.Release Notes
Add
Stimulus
object toSimulatorAPI
which is intended to contain basic, common stimulus that should be applied to a circuit. These can be chained together in series if desired. For now, only addrunUntilFinished
which is stimulus that runs for a number of cycles and then throws an exception if the simulation doesn't finish before the timeout.