diff options
| author | mergify[bot] | 2022-08-15 20:37:55 +0000 |
|---|---|---|
| committer | GitHub | 2022-08-15 20:37:55 +0000 |
| commit | 29702d7dd10a9eb7595a102bfffcee665bcf7394 (patch) | |
| tree | 0f42007fe7952dabae91632733166c53a25a8fda /src/test/scala | |
| parent | c4dec947d54a52c3092bd7855180d42afaae3776 (diff) | |
Printables for verification preconditions (backport #2663) (#2680)
* Printables for verification preconditions (#2663)
Add support for printable within assert and assume verification statements
Co-authored-by: Girish Pai <girish.pai@sifive.com>
Co-authored-by: Megan Wachs <megan@sifive.com>
Co-authored-by: Jack Koenig <koenig@sifive.com>
(cherry picked from commit 7df5653309b5e48e1732b335610d9a7e8449f903)
* Waive MiMa false positive
Co-authored-by: Aditya Naik <91489422+adkian-sifive@users.noreply.github.com>
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/test/scala')
| -rw-r--r-- | src/test/scala/chiselTests/Assert.scala | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Assert.scala b/src/test/scala/chiselTests/Assert.scala index 1849ddf8..d7885a3b 100644 --- a/src/test/scala/chiselTests/Assert.scala +++ b/src/test/scala/chiselTests/Assert.scala @@ -61,6 +61,29 @@ class BadUnescapedPercentAssertTester extends BasicTester { stop() } +class PrintableFormattedAssertTester extends BasicTester { + val foobar = Wire(UInt(32.W)) + foobar := 123.U + assert(foobar === 123.U, cf"Error! Wire foobar =/= $foobar%x This is 100%% wrong.\n") + stop() +} + +class PrintableBadUnescapedPercentAssertTester extends BasicTester { + assert(1.U === 1.U, p"I'm 110% sure this is an invalid message") + stop() +} + +class PrintableAssumeTester extends Module { + val in = IO(Input(UInt(8.W))) + val out = IO(Output(UInt(8.W))) + + val w = Wire(UInt(8.W)) + w := 255.U + assume(w === 255.U, cf"Assumption failed, Wire w =/= $w%x") + + out := in +} + class AssertSpec extends ChiselFlatSpec with Utils { "A failing assertion" should "fail the testbench" in { assert(!runTester { new FailingAssertTester }) @@ -77,6 +100,12 @@ class AssertSpec extends ChiselFlatSpec with Utils { they should "allow printf-style format strings with arguments" in { assertTesterPasses { new FormattedAssertTester } } + they should "allow printf-style format strings in Assumes" in { + val chirrtl = ChiselStage.emitChirrtl(new PrintableAssumeTester) + chirrtl should include( + """assume(w === 255.U, cf\"Assumption failed, Wire w =/= $w%%%%x\")\n", w)""" + ) + } they should "not allow unescaped % in the message" in { a[java.util.UnknownFormatConversionException] should be thrownBy { extractCause[java.util.UnknownFormatConversionException] { @@ -84,4 +113,16 @@ class AssertSpec extends ChiselFlatSpec with Utils { } } } + + they should "allow printable format strings with arguments" in { + assertTesterPasses { new FormattedAssertTester } + } + they should "not allow unescaped % in the printable message" in { + a[java.util.UnknownFormatConversionException] should be thrownBy { + extractCause[java.util.UnknownFormatConversionException] { + ChiselStage.elaborate { new BadUnescapedPercentAssertTester } + } + } + } + } |
