summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenry Cook2015-08-13 15:47:02 -0700
committerHenry Cook2015-08-13 15:51:53 -0700
commitad96b03f84d0182f5e74f11117331d69752ea0a0 (patch)
tree0d4ed1e56c054fe0ac7d2ef8739fb28c18be2b76 /src
parented69bdea87f7f60cc6b3bac7b6cdd7b6bc787f1d (diff)
testing improvements
Diffstat (limited to 'src')
-rw-r--r--src/test/scala/chiselTests/BitwiseOps.scala4
-rw-r--r--src/test/scala/chiselTests/BundleWire.scala39
-rw-r--r--src/test/scala/chiselTests/ChiselSpec.scala4
-rw-r--r--src/test/scala/chiselTests/GCD.scala19
4 files changed, 54 insertions, 12 deletions
diff --git a/src/test/scala/chiselTests/BitwiseOps.scala b/src/test/scala/chiselTests/BitwiseOps.scala
index 7cd695e6..c4fe7424 100644
--- a/src/test/scala/chiselTests/BitwiseOps.scala
+++ b/src/test/scala/chiselTests/BitwiseOps.scala
@@ -50,7 +50,7 @@ class BitwiseOps(w: Int) extends Module {
io.xor := io.a ^ io.b
}
-class BitwiseOpsSpec extends ChiselSpec {
+class BitwiseOpsSpec extends ChiselPropSpec {
class BitwiseOpsTester(w: Int, a: Int, b: Int) extends BasicTester {
val mask = (1 << w)-1;
@@ -64,7 +64,7 @@ class BitwiseOpsSpec extends ChiselSpec {
when(dut.io.xor != UInt(mask & (a ^ b))) { io.error := UInt(4) }
}
- "BitwiseOps" should "return the correct result" in {
+ property("All bit-wise ops should return the correct result") {
forAll(safeUInts, safeUInts) { (a: Int, b: Int) =>
assert(execute{ new BitwiseOpsTester(32, a, b) })
}
diff --git a/src/test/scala/chiselTests/BundleWire.scala b/src/test/scala/chiselTests/BundleWire.scala
new file mode 100644
index 00000000..99455608
--- /dev/null
+++ b/src/test/scala/chiselTests/BundleWire.scala
@@ -0,0 +1,39 @@
+package chiselTests
+import Chisel._
+import org.scalatest._
+import org.scalatest.prop._
+import Chisel.testers.BasicTester
+
+class Coord extends Bundle {
+ val x = UInt(width = 32)
+ val y = UInt(width = 32)
+}
+
+class BundleWire(n: Int) extends Module {
+ val io = new Bundle {
+ val in = (new Coord).asInput
+ val outs = Vec(new Coord, n).asOutput
+ }
+ val coords = Wire(Vec(new Coord, n))
+ for (i <- 0 until n) {
+ coords(i) := io.in
+ io.outs(i) := coords(i)
+ }
+}
+
+class BundleWireSpec extends ChiselPropSpec {
+
+ class BundleWireTester(n: Int, x: Int, y: Int) extends BasicTester {
+ val dut = Module(new BundleWire(n))
+ io.done := Bool(true)
+ dut.io.in.x := UInt(x)
+ dut.io.in.y := UInt(y)
+ io.error := dut.io.outs.map(o => o.x != UInt(x) || o.y != UInt(y)).foldLeft(UInt(0))(_##_)
+ }
+
+ property("All vec elems should match the inputs") {
+ forAll(vecSizes, safeUInts, safeUInts) { (n: Int, x: Int, y: Int) =>
+ assert(execute{ new BundleWireTester(n, x, y) })
+ }
+ }
+}
diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala
index fd602ef3..002ace8c 100644
--- a/src/test/scala/chiselTests/ChiselSpec.scala
+++ b/src/test/scala/chiselTests/ChiselSpec.scala
@@ -35,11 +35,11 @@ import org.scalatest.prop._
import org.scalacheck._
import Chisel.testers._
-class ChiselSpec extends FlatSpec with PropertyChecks {
+class ChiselPropSpec extends PropSpec with PropertyChecks {
def execute(t: => BasicTester): Boolean = TesterDriver.execute(t)
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/GCD.scala b/src/test/scala/chiselTests/GCD.scala
index 1ef20610..12499abf 100644
--- a/src/test/scala/chiselTests/GCD.scala
+++ b/src/test/scala/chiselTests/GCD.scala
@@ -37,22 +37,22 @@ import org.scalatest.prop._
class GCD extends Module {
val io = new Bundle {
- val a = Bits(INPUT, 16)
- val b = Bits(INPUT, 16)
+ val a = UInt(INPUT, 32)
+ val b = UInt(INPUT, 32)
val e = Bool(INPUT)
- val z = Bits(OUTPUT, 16)
+ val z = UInt(OUTPUT, 32)
val v = Bool(OUTPUT)
}
- val x = Reg(Bits(width = 16))
- val y = Reg(Bits(width = 16))
+ val x = Reg(UInt(width = 32))
+ val y = Reg(UInt(width = 32))
when (x > y) { x := x -% y }
.otherwise { y := y -% x }
when (io.e) { x := io.a; y := io.b }
io.z := x
- io.v := y === Bits(0)
+ io.v := y === UInt(0)
}
-class GCDSpec extends ChiselSpec {
+class GCDSpec extends ChiselPropSpec {
class GCDTester(a: Int, b: Int, z: Int) extends BasicTester {
val dut = Module(new GCD)
@@ -67,13 +67,16 @@ class GCDSpec extends ChiselSpec {
}
}
+ //TODO: use generators and this function to make z's
+ def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a%b)
+
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 {
+ property("GCD should return the correct result") {
forAll (gcds) { (a: Int, b: Int, z: Int) =>
assert(execute{ new GCDTester(a, b, z) })
}