summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests
diff options
context:
space:
mode:
authorJosh Bassett2020-08-14 06:37:44 +1000
committerGitHub2020-08-13 20:37:44 +0000
commitd9903de3357336c4bd158a02318b9cafea7bdf46 (patch)
treefab01f11d33df0bb8ec3984736950367a0f49995 /src/test/scala/chiselTests
parenta66d2d152897fa979aea07aa067c27ba455ca054 (diff)
Allow counters to be reset manually (#1527)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'src/test/scala/chiselTests')
-rw-r--r--src/test/scala/chiselTests/Counter.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Counter.scala b/src/test/scala/chiselTests/Counter.scala
index 985cf3fd..41f550a8 100644
--- a/src/test/scala/chiselTests/Counter.scala
+++ b/src/test/scala/chiselTests/Counter.scala
@@ -29,6 +29,19 @@ class EnableTester(seed: Int) extends BasicTester {
}
}
+class ResetTester(n: Int) extends BasicTester {
+ val triggerReset = WireInit(false.B)
+ val wasReset = RegNext(triggerReset)
+ val (value, _) = Counter(0 until 8, reset = triggerReset)
+
+ triggerReset := value === (n-1).U
+
+ when(wasReset) {
+ assert(value === 0.U)
+ stop()
+ }
+}
+
class WrapTester(max: Int) extends BasicTester {
val (cnt, wrap) = Counter(true.B, max)
when(wrap) {
@@ -61,6 +74,10 @@ class CounterSpec extends ChiselPropSpec {
forAll(safeUInts) { (seed: Int) => whenever(seed >= 0) { assertTesterPasses{ new EnableTester(seed) } } }
}
+ property("Counter can be reset") {
+ forAll(smallPosInts) { (seed: Int) => assertTesterPasses{ new ResetTester(seed) } }
+ }
+
property("Counter should wrap") {
forAll(smallPosInts) { (max: Int) => assertTesterPasses{ new WrapTester(max) } }
}