From e15e0f2529c0e0ff705a24f510252dea5a46d5de Mon Sep 17 00:00:00 2001 From: VoldsommeViggo Date: Fri, 27 Nov 2020 12:02:47 +0100 Subject: [PATCH] assertion event update --- .../assertionTiming/concurrentAssertion.scala | 85 +++++++++++++++++-- assertion/src/main/scala/mainClass.scala | 2 - .../test/scala/concurrentAssertionTest.scala | 44 +++++----- .../scala => temporary}/timescopeTest.scala | 0 4 files changed, 101 insertions(+), 30 deletions(-) rename assertion/{src/test/scala => temporary}/timescopeTest.scala (100%) diff --git a/assertion/src/main/scala/assertionTiming/concurrentAssertion.scala b/assertion/src/main/scala/assertionTiming/concurrentAssertion.scala index 1c985d9..8f8302a 100644 --- a/assertion/src/main/scala/assertionTiming/concurrentAssertion.scala +++ b/assertion/src/main/scala/assertionTiming/concurrentAssertion.scala @@ -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) @@ -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 */ @@ -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) @@ -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()) { @@ -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, @@ -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) + } + } } \ No newline at end of file diff --git a/assertion/src/main/scala/mainClass.scala b/assertion/src/main/scala/mainClass.scala index 3b5be78..69f1bb4 100644 --- a/assertion/src/main/scala/mainClass.scala +++ b/assertion/src/main/scala/mainClass.scala @@ -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{} \ No newline at end of file diff --git a/assertion/src/test/scala/concurrentAssertionTest.scala b/assertion/src/test/scala/concurrentAssertionTest.scala index 042cbe1..f8633ff 100644 --- a/assertion/src/test/scala/concurrentAssertionTest.scala +++ b/assertion/src/test/scala/concurrentAssertionTest.scala @@ -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") } } } @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 => { @@ -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()) { @@ -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) diff --git a/assertion/src/test/scala/timescopeTest.scala b/assertion/temporary/timescopeTest.scala similarity index 100% rename from assertion/src/test/scala/timescopeTest.scala rename to assertion/temporary/timescopeTest.scala