diff options
| -rw-r--r-- | src/main/scala/Chisel/testers/Driver.scala | 2 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/BitwiseOps.scala | 2 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/ChiselSpec.scala | 3 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/Counter.scala | 41 |
4 files changed, 46 insertions, 2 deletions
diff --git a/src/main/scala/Chisel/testers/Driver.scala b/src/main/scala/Chisel/testers/Driver.scala index 23c34f3a..a46c493c 100644 --- a/src/main/scala/Chisel/testers/Driver.scala +++ b/src/main/scala/Chisel/testers/Driver.scala @@ -33,7 +33,7 @@ import Chisel._ object TesterDriver { def execute(t: => BasicTester): Boolean = { - val circuit = Builder.build(t) + val circuit = Builder.build(Module(t)) //val executable = invokeFIRRTL(circuit) //Process(executable) ! true diff --git a/src/test/scala/chiselTests/BitwiseOps.scala b/src/test/scala/chiselTests/BitwiseOps.scala index c4fe7424..5a1f1de8 100644 --- a/src/test/scala/chiselTests/BitwiseOps.scala +++ b/src/test/scala/chiselTests/BitwiseOps.scala @@ -53,7 +53,7 @@ class BitwiseOps(w: Int) extends Module { class BitwiseOpsSpec extends ChiselPropSpec { class BitwiseOpsTester(w: Int, a: Int, b: Int) extends BasicTester { - val mask = (1 << w)-1; + val mask = (1 << w) - 1 val dut = Module(new BitwiseOps(w)) io.done := Bool(true) dut.io.a := UInt(a) diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala index f3dad3dc..e9ec2dae 100644 --- a/src/test/scala/chiselTests/ChiselSpec.scala +++ b/src/test/scala/chiselTests/ChiselSpec.scala @@ -38,6 +38,9 @@ import Chisel.testers._ class ChiselPropSpec extends PropSpec with PropertyChecks { def execute(t: => BasicTester): Boolean = TesterDriver.execute(t) + def popCount(n: Long) = n.toBinaryString.count(_=='1') + + val smallPosInts = Gen.choose(1, 16) val safeUIntWidth = Gen.choose(1, 31) val safeUInts = Gen.choose(0, (1 << 30)) val vecSizes = Gen.choose(0, 4) 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) }) } + } +} |
