Skip to content

New Timed Assertions API #28

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

Merged
merged 18 commits into from
Jul 8, 2021
Merged

New Timed Assertions API #28

merged 18 commits into from
Jul 8, 2021

Conversation

dobios
Copy link
Member

@dobios dobios commented Jun 30, 2021

This PR is a response to discussion #26.
A new timed assertions API was added, the previous one still works ofc. Now it looks similarly to ScalaTest's constructs:

eventually { /* TimedOperation goes here */ } delay by ( /*number of cycles*/ ) cycles
always { /* TimedOperation goes here */ } delay by ( /*number of cycles*/ ) cycles
exact { /* TimedOperation goes here */ } delay by ( /*number of cycles*/ ) cycles
never { /* TimedOperation goes here */ } delay by ( /*number of cycles*/ ) cycles

The cycles call replaces the previously needed join() call by hiding it behind a fancy wrapper.
The timed operators also got a new API full of syntactic sugar:

  • ?== is Equals
  • ?< is Lt
  • ?> is Gt
  • ?<= is LtEq
  • ?>= is GtEq

The ? symbol is needed in order to not collide with Chisel's operators.
Here's an example use:

always { dut.io.a ?== dut.io.b } delay by (9) cycles
eventually { dut.io.b ?> dut.io.c } delay by (4) cycles
exact { dut.io.outB ?< dut.io.c } delay by (7) cycles
never { dut.io.outB ?>= dut.io.outC } delay by (10) cycles

EDIT: This is no longer valid, please refer to the next comment !

@dobios dobios requested a review from schoeberl June 30, 2021 16:56
@dobios
Copy link
Member Author

dobios commented Jul 2, 2021

Following this morning's discussion, I changed the TimedAssertion syntax in order to make it closer to ScalaTest's syntax. It thus now looks like:

always(9) { dut.io.aEqb ?== dut.io.isOne }
eventually(4) { dut.io.outB ?> dut.io.outCNotSupB }
exact(7) { dut.io.outB ?< dut.io.outCSupB }
never(10) { dut.io.outB ?>= dut.io.outC }

This can also, of course, be used with arbitrary conditions:

always(9) { dut.io.aEqb.peek().litValue() == dut.io.isOne.peek().litValue() }
eventually(4) { dut.io.outB.peek().litValue() > dut.io.outCNotSupB.peek().litValue() }
exact(7) { dut.io.outB.peek().litValue() < dut.io.outCSupB.peek().litValue() }
never(10) { dut.io.outB.peek().litValue() >= dut.io.outC.peek().litValue() }

As a reminder, doing the same using the previous syntax is still allowed and would look like this:

AssertTimed(dut, dut.io.aEqb.peek().litValue() == dut.io.isOne.peek().litValue(), "ERROR")(Always(9))
AssertTimed(dut, dut.io.outB.peek().litValue() > dut.io.outCNotSupB.peek().litValue(), "ERROR")(Eventually(4))
AssertTimed(dut, dut.io.outB.peek().litValue() < dut.io.outCSupB.peek().litValue(), "ERROR")(Exactly(7))
AssertTimed(dut, dut.io.outB.peek().litValue() >= dut.io.outC.peek().litValue(), "ERROR")(Never(10))

Note that for this new syntax to work, the user needs to define an implicit dut somewhere in his test suite:

implicit val _dut : T = dut

@dobios
Copy link
Member Author

dobios commented Jul 5, 2021

There is also now a new, similar, ExpectTimed API. This follows the same idea as the AssertTimed API and can be used using the same syntax. So what used to look like:

ExpectTimed(dut, dut.io.aEqb, 1.U, "aEqb expected timing is wrong")(Always(9)).join()
ExpectTimed(dut, dut.io.aEvEqC, 1.U, "a never equals b within the first 11 cycles")(Eventually(11)).join()
ExpectTimed(dut, dut.io.aEvEqC, 1.U, "aEqb expected timing is wrong")(Exactly(6)).join()
ExpectTimed(dut, dut.io.aNevEqb, 0.U, "a is equal to b at some point")(Never(10)).join()

Now looks like:

always(9, "aEqb expected timing is wrong") { dut.io.aEqb expected 1.U }
eventually(11, "a never equals b within the first 11 cycles") { dut.io.aEvEqC expected 1.U }
exact(6, "aEqb expected timing is wrong") { dut.io.aEvEqC expected 1.U }
never(10, "a is equal to b at some point") { dut.io.aNevEqb expected 0.U }

The expected method is what tells us that the user wants to write the assertion using ChiselTest's expect rather than a scala assert.

@schoeberl schoeberl merged commit b92ef8e into master Jul 8, 2021
@schoeberl
Copy link
Member

Let us have some more discussion on this Friday.

@dobios dobios deleted the newAssertionAPI branch July 18, 2021 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants