Skip to content

Commit

Permalink
assertion event update
Browse files Browse the repository at this point in the history
  • Loading branch information
Vict0rAH committed Nov 27, 2020
1 parent 4614377 commit e15e0f2
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 30 deletions.
85 changes: 79 additions & 6 deletions assertion/src/main/scala/assertionTiming/concurrentAssertion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object assertNever {
def apply[T <: Module](dut: T, cond: () => Boolean = () => true, cycles: Int = 1, message: String = "Error") = {

// Assertion for single thread clock cycle 0
assert(cond(), message)
assert(!cond(), message)
fork {
for (i <- 1 until cycles) {
assert(!cond(), message)
Expand All @@ -41,6 +41,20 @@ object assertNever {
}
}

object assertNeverEvent {
def apply[T <: Module](dut: T, cond: () => Boolean = () => true, event: Boolean = false, message: String = "Error") = {

// Assertion for single thread clock cycle 0
assert(!cond(), message)
fork {
while (!event) {
assert(!cond(), message)
dut.clock.step(1)
}
}
}
}

/** assertAlways():
* Checks for the argument condition to be true in the number of cycles passed
*/
Expand All @@ -60,12 +74,28 @@ object assertAlways {
}
}

// Event based version of assert
object assertAlwaysEvent {
def apply[T <: Module](dut: T, cond: () => Boolean = () => true, event: Boolean = false, message: String = "Error") = {

// Assertion for single thread clock cycle 0
assert(cond(), message)

//dut.clock.step(1)
fork {
while (!event) {
assert(cond(), message)
dut.clock.step(1)
}
}
}
}

/** assertEventually():
* Checks for the argument condition to be true just once within the number of
* clock cycles passed, a liveness property. Fails if the condition is not true
* at least once within the window of cycles
*
* Must be joined
* Clock cycle zero is executed as soon as assertionEventually is called. Therefore,
* to step to max window of cycles, one must step with regards to the first cycle
* already executed (cycle zero)
Expand All @@ -87,20 +117,31 @@ object assertEventually {
}
}

// Event based version of assertEventually
object assertEventuallyEvent {
def apply[T <: Module](dut: T, cond: () => Boolean = () => true, event: Boolean = false, message: String = "Error") = {

fork {
while (!cond()) {
if (event) {
assert(false, message)
}
dut.clock.step(1)
}
}
}
}

/** assertEventuallyAlways():
* Checks for the argument condition to be true within the number of
* clock cycles passed, and hold true until the last cycle. Fails if the
* condition is not true at least once within the window of cycles, or if
* condition becomes false after it becomes true.
*
* Must be joined
*/
object assertEventuallyAlways {
def apply[T <: Module](dut: T, cond: () => Boolean = () => true, cycles: Int = 1, message: String = "Error") = {

var i = 1
// Assertion for single thread clock cycle 0
assert(cond(), message)

fork {
while (!cond()) {
Expand All @@ -119,6 +160,29 @@ object assertEventuallyAlways {
}
}

// Event based version of assertEventuallyAlways
object assertEventuallyAlwaysEvent {
def apply[T <: Module](dut: T, cond: () => Boolean = () => true, event: Boolean = false, message: String = "Error") = {

var i = 1

fork {
while (!cond()) {
if (event) {
assert(false, message)
}
i += 1
dut.clock.step(1)
}

while (!event) {
assert(cond(), message)
dut.clock.step(1)
}
}
}
}

/** assertOneHot():
* checks if exactly one bit of the expression is high
* The checker is useful for verifying control circuits,
Expand Down Expand Up @@ -148,4 +212,13 @@ object assertOneHot {

return true
}
}

object assertOnCycle {
def apply[T <: Module](dut: T, cond: () => Boolean = () => true, cycles: Int = 1, message: String = "Error") = {
fork {
dut.clock.step(cycles)
assert(cond(), message)
}
}
}
2 changes: 0 additions & 2 deletions assertion/src/main/scala/mainClass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class mainClass extends Module {

reg := Mux(io.s, 4.U, 0.U)
io.c := reg

//conAssert(true.B, "Error", 10)
}

object main extends App{}
44 changes: 22 additions & 22 deletions assertion/src/test/scala/concurrentAssertionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M

dut.io.s.poke(true.B)
dut.clock.step(1)
assertAlways(dut)
val t = assertAlways(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
}
}
}
Expand All @@ -24,7 +24,7 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
dut.io.s.poke(true.B)
dut.clock.step(1)
val t = assertAlways(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
val t = assertAlways(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
dut.clock.step(10)
dut.io.s.poke(false.B)
Expand All @@ -40,7 +40,7 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
// Test of assertAlways
dut.io.s.poke(true.B)
dut.clock.step(1)
assertAlways(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
assertAlways(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
dut.clock.step(21)
dut.io.s.poke(false.B)
Expand All @@ -49,7 +49,7 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
// Test of assertNever
dut.io.s.poke(false.B)
dut.clock.step(1)
assertNever(dut, () => dut.io.c.peek.litValue == 4, "Error", 40)
assertNever(dut, () => dut.io.c.peek.litValue == 4, 40, "Error")
dut.clock.step(41)
dut.io.s.poke(true.B)
Expand All @@ -65,7 +65,7 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
// Test of assertAlways
dut.io.s.poke(true.B)
dut.clock.step(1)
assertAlways(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
assertAlways(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
dut.clock.step(20)
dut.io.s.poke(false.B)
Expand All @@ -74,7 +74,7 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
// Test of assertNever
dut.io.s.poke(false.B)
dut.clock.step(1)
assertNever(dut, () => dut.io.c.peek.litValue == 4, "Error", 40)
assertNever(dut, () => dut.io.c.peek.litValue == 4, 40, "Error")
dut.clock.step(40)
dut.io.s.poke(true.B)
Expand All @@ -83,25 +83,25 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
}
}
// assertNever
// assertNever
it should "test assertNever" in {
test(new mainClass()) {
dut => {
dut.io.s.poke(false.B)
dut.clock.step(1)
assertNever(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
assertNever(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
}
}
}
it should "test assertNever fails" in {
it should "test assertNever can fail" in {
test(new mainClass()) {
dut => {
dut.io.s.poke(false.B)
dut.clock.step(1)
val t = assertNever(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
val t = assertNever(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
dut.clock.step(15)
dut.io.s.poke(true.B)
Expand All @@ -117,7 +117,7 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
dut.io.s.poke(false.B)
dut.clock.step(1)
val t = assertEventually(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
val t = assertEventually(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
dut.clock.step(5)
dut.io.s.poke(true.B)
Expand All @@ -126,9 +126,9 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
t.join
}
}
}*/
}
it should "test assertEventually passes when truecondition is assertet on last possible cycle" in {
it should "test assertEventually passes when true condition is asserted on last possible cycle" in {
test(new mainClass()) {
dut => {
Expand All @@ -145,18 +145,18 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
}
}
/*it should "test assertEventually fails when exceeding clock cycles" in {
it should "test assertEventually fails when exceeding clock cycles" in {
test(new mainClass()) {
dut => {
dut.io.s.poke(false.B)
dut.clock.step(1)
val t = assertEventually(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
val t = assertEventually(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
t.join
}
}
}*/
}
it should "test if the dut steps correctly" in {
test(new dummyDUT()) {
Expand Down Expand Up @@ -219,32 +219,32 @@ class concurrentAssertionTest extends FlatSpec with ChiselScalatestTester with M
d.join
}
}
}
}*/

/*// assertEventuallyAlways
// assertEventuallyAlways
it should "test assertEventuallyAlways pass" in {
test(new mainClass()) {
dut => {

dut.io.s.poke(false.B)
dut.clock.step(1)
val t = assertEventuallyAlways(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
val t = assertEventuallyAlways(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")

dut.clock.step(1)
dut.io.s.poke(true.B)

t.join
dut.clock.step(100)
}
}
}

it should "fail, if cond does not hold true once true" in {
/*it should "fail, if cond does not hold true once true" in {
test(new mainClass()) {
dut => {
dut.io.s.poke(false.B)
dut.clock.step(1)
val t = assertEventuallyAlways(dut, () => dut.io.c.peek.litValue == 4, "Error", 20)
val t = assertEventuallyAlways(dut, () => dut.io.c.peek.litValue == 4, 20, "Error")
dut.clock.step(5)
dut.io.s.poke(true.B)
Expand Down
File renamed without changes.

0 comments on commit e15e0f2

Please sign in to comment.