summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/chiselTests')
-rw-r--r--src/test/scala/chiselTests/ChiselSpec.scala36
-rw-r--r--src/test/scala/chiselTests/Decoder.scala2
2 files changed, 28 insertions, 10 deletions
diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala
index 2d546d00..1fe77a0e 100644
--- a/src/test/scala/chiselTests/ChiselSpec.scala
+++ b/src/test/scala/chiselTests/ChiselSpec.scala
@@ -19,30 +19,48 @@ class ChiselFlatSpec extends FlatSpec with ChiselRunners with Matchers
/** Spec base class for property-based testers. */
class ChiselPropSpec extends PropSpec with ChiselRunners with PropertyChecks {
- def popCount(n: Long) = n.toBinaryString.count(_=='1')
+ /** Returns the number of 1s in the binary representation of the input. */
+ def popCount(n: Long): Int = n.toBinaryString.count(_ == '1')
+ // Generator for small positive integers.
val smallPosInts = Gen.choose(1, 7)
+
+ // Generator for widths considered "safe".
val safeUIntWidth = Gen.choose(1, 30)
+
+ // Generators for integers that fit within "safe" widths.
val safeUInts = Gen.choose(0, (1 << 30))
+
+ // Generators for vector sizes.
val vecSizes = Gen.choose(0, 4)
- val binaryString = for(i <- Arbitrary.arbitrary[Int]) yield "b" + i.toBinaryString
- def enSequence(n: Int) = Gen.containerOfN[List,Boolean](n,Gen.oneOf(true,false))
- def safeUIntN(n: Int) = for {
+ // Generator for string representing an arbitrary integer.
+ val binaryString = for (i <- Arbitrary.arbitrary[Int]) yield "b" + i.toBinaryString
+
+ // Generator for a sequence of Booleans of size n.
+ def enSequence(n: Int): Gen[List[Boolean]] = Gen.containerOfN[List, Boolean](n, Gen.oneOf(true, false))
+
+ // Generator which gives a width w and a list (of size n) of numbers up to w bits.
+ def safeUIntN(n: Int): Gen[(Int, List[Int])] = for {
w <- smallPosInts
- i <- Gen.containerOfN[List,Int](n, Gen.choose(0, (1 << w) - 1))
+ i <- Gen.containerOfN[List, Int](n, Gen.choose(0, (1 << w) - 1))
} yield (w, i)
+
+ // Generator which gives a width w and a numbers up to w bits.
val safeUInt = for {
w <- smallPosInts
i <- Gen.choose(0, (1 << w) - 1)
} yield (w, i)
- def safeUIntPairN(n: Int) = for {
+ // Generator which gives a width w and a list (of size n) of a pair of numbers up to w bits.
+ def safeUIntPairN(n: Int): Gen[(Int, List[(Int, Int)])] = for {
w <- smallPosInts
- i <- Gen.containerOfN[List,Int](n, Gen.choose(0, (1 << w) - 1))
- j <- Gen.containerOfN[List,Int](n, Gen.choose(0, (1 << w) - 1))
+ i <- Gen.containerOfN[List, Int](n, Gen.choose(0, (1 << w) - 1))
+ j <- Gen.containerOfN[List, Int](n, Gen.choose(0, (1 << w) - 1))
} yield (w, i zip j)
- val safeUIntPair= for {
+
+ // Generator which gives a width w and a pair of numbers up to w bits.
+ val safeUIntPair = for {
w <- smallPosInts
i <- Gen.choose(0, (1 << w) - 1)
j <- Gen.choose(0, (1 << w) - 1)
diff --git a/src/test/scala/chiselTests/Decoder.scala b/src/test/scala/chiselTests/Decoder.scala
index 69863608..9ac0a3b7 100644
--- a/src/test/scala/chiselTests/Decoder.scala
+++ b/src/test/scala/chiselTests/Decoder.scala
@@ -33,7 +33,7 @@ class DecoderSpec extends ChiselPropSpec {
val bp = bs.map(if(rnd.nextBoolean) _ else "?").mkString
("b" + bs, "b" + bp)
}
- def nPairs(n: Int) = Gen.containerOfN[List, (String,String)](n,bitpatPair)
+ private 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)]) =>