summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Cook2015-08-13 23:32:14 -0700
committerHenry Cook2015-08-13 23:32:14 -0700
commitcaf993c89ba07a65d05b0e17d109a60f96330136 (patch)
tree9decc9c40d6b39aecf38c6fcbb9a09dabb0c21b7
parent31c5c92fa59cbd9aec00851fd722b9a6317179ef (diff)
add decoder test
-rw-r--r--src/test/scala/chiselTests/ChiselSpec.scala4
-rw-r--r--src/test/scala/chiselTests/ComplexAssign.scala2
-rw-r--r--src/test/scala/chiselTests/Decoder.scala41
3 files changed, 44 insertions, 3 deletions
diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala
index e9ec2dae..1f1b5399 100644
--- a/src/test/scala/chiselTests/ChiselSpec.scala
+++ b/src/test/scala/chiselTests/ChiselSpec.scala
@@ -40,10 +40,10 @@ class ChiselPropSpec extends PropSpec with PropertyChecks {
def popCount(n: Long) = n.toBinaryString.count(_=='1')
- val smallPosInts = Gen.choose(1, 16)
+ val smallPosInts = Gen.choose(1, 8)
val safeUIntWidth = Gen.choose(1, 31)
val safeUInts = Gen.choose(0, (1 << 30))
val vecSizes = Gen.choose(0, 4)
def enSequence(n: Int) = Gen.containerOfN[List,Boolean](n,Gen.oneOf(true,false))
+ val binaryString = for(i <- Arbitrary.arbitrary[Int]) yield "b" + i.toBinaryString
}
-
diff --git a/src/test/scala/chiselTests/ComplexAssign.scala b/src/test/scala/chiselTests/ComplexAssign.scala
index ab940440..47041ddd 100644
--- a/src/test/scala/chiselTests/ComplexAssign.scala
+++ b/src/test/scala/chiselTests/ComplexAssign.scala
@@ -42,7 +42,7 @@ class ComplexAssignSpec extends ChiselPropSpec {
}
property("All complex assignments should return the correct result") {
- forAll(enSequence(16), safeUInts, safeUInts) { (en: List[Boolean], re: Int, im: Int) =>
+ forAll(enSequence(4), safeUInts, safeUInts) { (en: List[Boolean], re: Int, im: Int) =>
assert(execute{ new ComplexAssignTester(en, re, im) })
}
}
diff --git a/src/test/scala/chiselTests/Decoder.scala b/src/test/scala/chiselTests/Decoder.scala
new file mode 100644
index 00000000..cc463600
--- /dev/null
+++ b/src/test/scala/chiselTests/Decoder.scala
@@ -0,0 +1,41 @@
+package chiselTests
+import Chisel._
+import org.scalatest._
+import org.scalatest.prop._
+import org.scalacheck._
+import Chisel.testers.BasicTester
+
+class Decoder(bitpats: List[String]) extends Module {
+ val io = new Bundle {
+ val inst = UInt(INPUT, 32)
+ val match_idx = UInt(OUTPUT, 5)
+ }
+ io.match_idx := Vec(bitpats.map(BitPat(_) === io.inst)).indexWhere{i: Bool => i}
+}
+
+class DecoderSpec extends ChiselPropSpec {
+
+ class DecoderTester(pairs: List[(String, String)]) extends BasicTester {
+ val (insts, bitpats) = pairs.unzip
+ val (cnt, wrap) = Counter(Bool(true), pairs.size)
+ val dut = Module(new Decoder(bitpats))
+ dut.io.inst := Vec(insts.map(UInt(_)))(cnt)
+ when(dut.io.match_idx != cnt) { io.done := Bool(true); io.error := cnt }
+ when(wrap) { io.done := Bool(true) }
+ }
+
+ // Use a single Int to make both a specific instruction and a BitPat that will match it
+ val bitpatPair = for(seed <- Arbitrary.arbitrary[Int]) yield {
+ val rnd = new scala.util.Random(seed)
+ val bs = seed.toBinaryString
+ val bp = bs.map(if(rnd.nextBoolean) _ else "?").mkString
+ ("b"+bs, "b"+bp)
+ }
+ def nPairs(n: Int) = Gen.containerOfN[List, (String,String)](n,bitpatPair)
+
+ property("BitPat wildcards should be usable in decoding") {
+ forAll(nPairs(16)){ (pairs: List[(String, String)]) =>
+ assert(execute{ new DecoderTester(pairs) })
+ }
+ }
+}