From dbd072172f6312893e1922e48ed768ae0fab9a89 Mon Sep 17 00:00:00 2001 From: ducky Date: Fri, 11 Dec 2015 14:25:42 -0800 Subject: Refactor tests to use stop() and assert() instead of io.error/io.done Gate assert, printf, stop by reset Fix testbenches that never worked Change simulation prints to display cycle at which test was signaled to end, not when simulator stops Better documentation for Counter --- src/test/scala/chiselTests/Counter.scala | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/test/scala/chiselTests/Counter.scala') diff --git a/src/test/scala/chiselTests/Counter.scala b/src/test/scala/chiselTests/Counter.scala index 1aa2aaba..aa21423f 100644 --- a/src/test/scala/chiselTests/Counter.scala +++ b/src/test/scala/chiselTests/Counter.scala @@ -9,27 +9,33 @@ import Chisel.testers.BasicTester class CountTester(max: Int) extends BasicTester { val cnt = Counter(max) when(Bool(true)) { cnt.inc() } - when(cnt.value === UInt(max-1)) { io.done := Bool(true) } + when(cnt.value === UInt(max-1)) { + stop() + } } class EnableTester(seed: Int) extends BasicTester { val ens = Reg(init = UInt(seed)) ens := ens >> 1 - val (cntEn, cntWrap) = Counter(ens(0), 32) - val cnt = Counter(Bool(true), 32)._1 - when(cnt === UInt(31)) { - io.done := Bool(true) - io.error := cnt != UInt(popCount(seed)) + + val (cntEnVal, _) = Counter(ens(0), 32) + val (_, done) = Counter(Bool(true), 33) + + when(done) { + assert(cntEnVal === UInt(popCount(seed))) + stop() } } class WrapTester(max: Int) extends BasicTester { val (cnt, wrap) = Counter(Bool(true), max) - when(wrap) { io.done := Bool(true); io.error := cnt != UInt(max) } + when(wrap) { + assert(cnt === UInt(max - 1)) + stop() + } } class CounterSpec extends ChiselPropSpec { - property("Counter should count up") { forAll(smallPosInts) { (max: Int) => assert(execute{ new CountTester(max) }) } } -- cgit v1.2.3