summaryrefslogtreecommitdiff
path: root/src/test/scala/ChiselTests/GCD.scala
diff options
context:
space:
mode:
authorHenry Cook2015-08-12 19:32:43 -0700
committerHenry Cook2015-08-12 19:32:57 -0700
commit85d7403f9bf7bc2b3520f924736c237f21f70ebd (patch)
tree64560f779063a419395a2fb8a31ea52c52af4404 /src/test/scala/ChiselTests/GCD.scala
parent7e69966362b1dbd9835695250494857f3a3767c8 (diff)
being to convert tests to scala-test; tests compile and run
Diffstat (limited to 'src/test/scala/ChiselTests/GCD.scala')
-rw-r--r--src/test/scala/ChiselTests/GCD.scala42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/test/scala/ChiselTests/GCD.scala b/src/test/scala/ChiselTests/GCD.scala
index 164a1cfe..4f861201 100644
--- a/src/test/scala/ChiselTests/GCD.scala
+++ b/src/test/scala/ChiselTests/GCD.scala
@@ -1,6 +1,8 @@
-package ChiselTests
-import Chisel._
+package Chisel
import Chisel.testers._
+import org.scalatest._
+import org.scalatest.prop._
+import org.scalatest.prop.TableDrivenPropertyChecks._
class GCD extends Module {
val io = new Bundle {
@@ -19,14 +21,30 @@ class GCD extends Module {
io.v := y === Bits(0)
}
-class GCDTester(c: GCD) extends Tester(c) {
- val (a, b, z) = (64, 48, 16)
- do {
- val first = if (t == 0) 1 else 0;
- poke(c.io.a, a)
- poke(c.io.b, b)
- poke(c.io.e, first)
- step(1)
- } while (t <= 1 || peek(c.io.v) == 0)
- expect(c.io.z, z)
+class GCDSpec extends ChiselSpec {
+
+ class GCDTester(a: Int, b: Int, z: Int) extends BasicTester {
+ val dut = Module(new GCD)
+ val first = Reg(init=Bool(true))
+ dut.io.a := UInt(a)
+ dut.io.b := UInt(b)
+ dut.io.e := first
+ when(first) { first := Bool(false) }
+ when(dut.io.v) {
+ io.done := Bool(true)
+ io.error := (dut.io.z != UInt(z)).toUInt
+ }
+ }
+
+ val gcds = Table(
+ ("a", "b", "z"), // First tuple defines column names
+ ( 64, 48, 16), // Subsequent tuples define the data
+ ( 12, 9, 3),
+ ( 48, 64, 12))
+
+ "GCD" should "return the correct result" in {
+ forAll (gcds) { (a: Int, b: Int, z: Int) =>
+ assert(TesterDriver.execute{ new GCDTester(a, b, z) })
+ }
+ }
}