-
Notifications
You must be signed in to change notification settings - Fork 647
Add ChiselSim Settings.defaultTest for SimulationTestHarnessInterface modules #5192
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
Changes from all commits
294ad95
438893f
ab4e130
2591193
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,7 +127,7 @@ trait SimulatorAPI { | |
| timeout: Int, | ||
| chiselOpts: Array[String] = Array.empty, | ||
| firtoolOpts: Array[String] = Array.empty, | ||
| settings: Settings[T] = Settings.defaultRaw[T], | ||
| settings: Settings[T] = Settings.defaultTest[T], | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Behavior change here too
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This I missed, what's the change in behavior?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this PR, |
||
| additionalResetCycles: Int = 0, | ||
| subdirectory: Option[String] = None | ||
| )( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -147,6 +147,166 @@ class ChiselSimSpec extends AnyFunSpec with Matchers with ChiselSim with FileChe | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it("should set macros to use init for Settings.defaultTest") { | ||||||||||||||||||||||||
| class Foo extends SimulationTestHarness { | ||||||||||||||||||||||||
| val (_, wrap) = Counter(true.B, 4) | ||||||||||||||||||||||||
| done :<= wrap | ||||||||||||||||||||||||
| success :<= true.B | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| simulateTest(new Foo, timeout = 100, settings = Settings.defaultTest[Foo]) | ||||||||||||||||||||||||
| io.Source | ||||||||||||||||||||||||
| .fromFile( | ||||||||||||||||||||||||
| FileSystems | ||||||||||||||||||||||||
| .getDefault() | ||||||||||||||||||||||||
| .getPath(implicitly[HasTestingDirectory].getDirectory.toString, "workdir-verilator", "Makefile") | ||||||||||||||||||||||||
| .toFile | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .mkString | ||||||||||||||||||||||||
| .fileCheck()( | ||||||||||||||||||||||||
|
Comment on lines
+157
to
+165
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A nit but,
The split line is also a bit ugly, I'd use a val for the makefile path and this should be a lot simpler:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After writing this comment, I see that it follows the style of the rest of the file. So I think it's fine, but consider yourself on notice @seldridge 👀 |
||||||||||||||||||||||||
| """|CHECK: '+define+ASSERT_VERBOSE_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+PRINTF_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+STOP_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |""".stripMargin | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it("should set macros for SimulationTestHarnessInterface with separate IO") { | ||||||||||||||||||||||||
| class SeparateIOHarness extends RawModule with SimulationTestHarnessInterface { | ||||||||||||||||||||||||
| val clock = IO(Input(Clock())) | ||||||||||||||||||||||||
| val init = IO(Input(Bool())) | ||||||||||||||||||||||||
| val done = IO(Output(Bool())) | ||||||||||||||||||||||||
| val success = IO(Output(Bool())) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| withClockAndReset(clock, init) { | ||||||||||||||||||||||||
| val (_, wrap) = Counter(true.B, 4) | ||||||||||||||||||||||||
| done := wrap | ||||||||||||||||||||||||
| success := true.B | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| simulateTest(new SeparateIOHarness, timeout = 100, settings = Settings.defaultTest[SeparateIOHarness]) | ||||||||||||||||||||||||
| io.Source | ||||||||||||||||||||||||
| .fromFile( | ||||||||||||||||||||||||
| FileSystems | ||||||||||||||||||||||||
| .getDefault() | ||||||||||||||||||||||||
| .getPath(implicitly[HasTestingDirectory].getDirectory.toString, "workdir-verilator", "Makefile") | ||||||||||||||||||||||||
| .toFile | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .mkString | ||||||||||||||||||||||||
| .fileCheck()( | ||||||||||||||||||||||||
| """|CHECK: '+define+ASSERT_VERBOSE_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+PRINTF_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+STOP_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |""".stripMargin | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it("should set macros for SimulationTestHarnessInterface with FlatIO") { | ||||||||||||||||||||||||
| class FlatIOHarness extends RawModule with SimulationTestHarnessInterface { | ||||||||||||||||||||||||
| private val io = FlatIO(new Bundle { | ||||||||||||||||||||||||
| val clock = Input(Clock()) | ||||||||||||||||||||||||
| val init = Input(Bool()) | ||||||||||||||||||||||||
| val done = Output(Bool()) | ||||||||||||||||||||||||
| val success = Output(Bool()) | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| def clock = io.clock | ||||||||||||||||||||||||
| def init = io.init | ||||||||||||||||||||||||
| def done = io.done | ||||||||||||||||||||||||
| def success = io.success | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| withClockAndReset(clock, init) { | ||||||||||||||||||||||||
| val (_, wrap) = Counter(true.B, 4) | ||||||||||||||||||||||||
| io.done := wrap | ||||||||||||||||||||||||
| io.success := true.B | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| simulateTest(new FlatIOHarness, timeout = 100, settings = Settings.defaultTest[FlatIOHarness]) | ||||||||||||||||||||||||
| io.Source | ||||||||||||||||||||||||
| .fromFile( | ||||||||||||||||||||||||
| FileSystems | ||||||||||||||||||||||||
| .getDefault() | ||||||||||||||||||||||||
| .getPath(implicitly[HasTestingDirectory].getDirectory.toString, "workdir-verilator", "Makefile") | ||||||||||||||||||||||||
| .toFile | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .mkString | ||||||||||||||||||||||||
| .fileCheck()( | ||||||||||||||||||||||||
| """|CHECK: '+define+ASSERT_VERBOSE_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+PRINTF_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+STOP_COND=!svsimTestbench.init' | ||||||||||||||||||||||||
| |""".stripMargin | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it("should set macros for SimulationTestHarnessInterface with IO of a bundle") { | ||||||||||||||||||||||||
| class BundleIOHarness extends RawModule with SimulationTestHarnessInterface { | ||||||||||||||||||||||||
| private val io = IO(new Bundle { | ||||||||||||||||||||||||
| val clock = Input(Clock()) | ||||||||||||||||||||||||
| val init = Input(Bool()) | ||||||||||||||||||||||||
| val done = Output(Bool()) | ||||||||||||||||||||||||
| val success = Output(Bool()) | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| def clock = io.clock | ||||||||||||||||||||||||
| def init = io.init | ||||||||||||||||||||||||
| def done = io.done | ||||||||||||||||||||||||
| def success = io.success | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| withClockAndReset(clock, init) { | ||||||||||||||||||||||||
| val (_, wrap) = Counter(true.B, 4) | ||||||||||||||||||||||||
| io.done := wrap | ||||||||||||||||||||||||
| io.success := true.B | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| simulateTest(new BundleIOHarness, timeout = 100, settings = Settings.defaultTest[BundleIOHarness]) | ||||||||||||||||||||||||
| io.Source | ||||||||||||||||||||||||
| .fromFile( | ||||||||||||||||||||||||
| FileSystems | ||||||||||||||||||||||||
| .getDefault() | ||||||||||||||||||||||||
| .getPath(implicitly[HasTestingDirectory].getDirectory.toString, "workdir-verilator", "Makefile") | ||||||||||||||||||||||||
| .toFile | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .mkString | ||||||||||||||||||||||||
| .fileCheck()( | ||||||||||||||||||||||||
| """|CHECK: '+define+ASSERT_VERBOSE_COND=!svsimTestbench.io_init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+PRINTF_COND=!svsimTestbench.io_init' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+STOP_COND=!svsimTestbench.io_init' | ||||||||||||||||||||||||
| |""".stripMargin | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it("should set macros for SimulationTestHarnessInterface with renamed ports") { | ||||||||||||||||||||||||
| class RenamedPortHarness extends RawModule with SimulationTestHarnessInterface { | ||||||||||||||||||||||||
| val clk = IO(Input(Clock())) | ||||||||||||||||||||||||
| val reset_n = IO(Input(Bool())) | ||||||||||||||||||||||||
| val finished = IO(Output(Bool())) | ||||||||||||||||||||||||
| val passed = IO(Output(Bool())) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def clock = clk | ||||||||||||||||||||||||
| def init = reset_n | ||||||||||||||||||||||||
| def done = finished | ||||||||||||||||||||||||
| def success = passed | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| withClockAndReset(clk, reset_n) { | ||||||||||||||||||||||||
| val (_, wrap) = Counter(true.B, 4) | ||||||||||||||||||||||||
| finished := wrap | ||||||||||||||||||||||||
| passed := true.B | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| simulateTest(new RenamedPortHarness, timeout = 100, settings = Settings.defaultTest[RenamedPortHarness]) | ||||||||||||||||||||||||
| io.Source | ||||||||||||||||||||||||
| .fromFile( | ||||||||||||||||||||||||
| FileSystems | ||||||||||||||||||||||||
| .getDefault() | ||||||||||||||||||||||||
| .getPath(implicitly[HasTestingDirectory].getDirectory.toString, "workdir-verilator", "Makefile") | ||||||||||||||||||||||||
| .toFile | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .mkString | ||||||||||||||||||||||||
| .fileCheck()( | ||||||||||||||||||||||||
| """|CHECK: '+define+ASSERT_VERBOSE_COND=!svsimTestbench.reset_n' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+PRINTF_COND=!svsimTestbench.reset_n' | ||||||||||||||||||||||||
| |CHECK-NEXT: '+define+STOP_COND=!svsimTestbench.reset_n' | ||||||||||||||||||||||||
| |""".stripMargin | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it("should allow for a user to customize the build directory") { | ||||||||||||||||||||||||
| class Foo extends Module { | ||||||||||||||||||||||||
| stop() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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 guess this is technically a behavior change. Lmk if you'd like me to land this separately @jackkoenig.
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.
It's more of a bugfix than behavior change, but it's fine.