diff options
| author | Henry Cook | 2015-08-13 21:47:27 -0700 |
|---|---|---|
| committer | Henry Cook | 2015-08-13 21:47:45 -0700 |
| commit | 31c5c92fa59cbd9aec00851fd722b9a6317179ef (patch) | |
| tree | 92a7a31e9c9d5c1eb5a72fc9e03eb6d6f4e5af25 /src/test/scala/chiselTests/Counter.scala | |
| parent | ac5bf6a4c953fe39fa97d77bc620c515dc9e1622 (diff) | |
Counter tests
Diffstat (limited to 'src/test/scala/chiselTests/Counter.scala')
| -rw-r--r-- | src/test/scala/chiselTests/Counter.scala | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Counter.scala b/src/test/scala/chiselTests/Counter.scala new file mode 100644 index 00000000..90e3afa3 --- /dev/null +++ b/src/test/scala/chiselTests/Counter.scala @@ -0,0 +1,41 @@ +package chiselTests +import Chisel._ +import org.scalatest._ +import org.scalatest.prop._ +import Chisel.testers.BasicTester + +class CounterSpec extends ChiselPropSpec { + + class CountTester(max: Int) extends BasicTester { + val cnt = Counter(max) + when(cnt.value === UInt(max)) { io.done := Bool(true) } + } + + property("Counter should count up") { + forAll(smallPosInts) { (max: Int) => assert(execute{ new CountTester(max) }) } + } + + 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(32) + when(cnt.value === UInt(31)) { + io.done := Bool(true) + io.error := cnt.value != UInt(popCount(seed)) + } + } + + property("Counter can be en/disabled") { + forAll(safeUInts) { (seed: Int) => assert(execute{ new EnableTester(seed) }) } + } + + class WrapTester(max: Int) extends BasicTester { + val (cnt, wrap) = Counter(Bool(true), max) + when(wrap) { io.done := Bool(true); io.error := cnt != UInt(max) } + } + + property("Counter should wrap") { + forAll(smallPosInts) { (max: Int) => assert(execute{ new WrapTester(max) }) } + } +} |
