diff options
| author | Schuyler Eldridge | 2019-05-06 23:43:27 -0400 |
|---|---|---|
| committer | Schuyler Eldridge | 2019-05-08 15:10:16 -0400 |
| commit | 723cfb0cbe5e20db02637c194f129e57d4071ee2 (patch) | |
| tree | 65a6f87c6e0137ba8052120ebd0f01971d0e6b66 /src/test/scala/chiselTests | |
| parent | 0479e47e8294c5b242bbf36d19b1f5a06c32e6c1 (diff) | |
Genericize LFSR testing infrastructure
Make LFSR testing generic to enable it to test other LFSRs.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/test/scala/chiselTests')
| -rw-r--r-- | src/test/scala/chiselTests/LFSR16.scala | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/test/scala/chiselTests/LFSR16.scala b/src/test/scala/chiselTests/LFSR16.scala index 54a3591f..c3c9dfad 100644 --- a/src/test/scala/chiselTests/LFSR16.scala +++ b/src/test/scala/chiselTests/LFSR16.scala @@ -12,14 +12,16 @@ import chisel3.util._ * The asserts check that the bins show the correct distribution. */ //scalastyle:off magic.number -class LFSRTester extends BasicTester { +class LFSRDistribution(gen: => UInt, cycles: Int = 10000) extends BasicTester { + + val rv = gen val bins = Reg(Vec(8, UInt(32.W))) // Use tap points on each LFSR so values are more independent - val die0 = Cat(Seq.tabulate(2) { i => LFSR16()(i) }) - val die1 = Cat(Seq.tabulate(2) { i => LFSR16()(i + 2) }) + val die0 = Cat(Seq.tabulate(2) { i => rv(i) }) + val die1 = Cat(Seq.tabulate(2) { i => rv(i + 2) }) - val (trial, done) = Counter(true.B, 10000) + val (trial, done) = Counter(true.B, cycles) val rollValue = die0 +& die1 // Note +& is critical because sum will need an extra bit. @@ -41,13 +43,14 @@ class LFSRTester extends BasicTester { } } -class LFSR16MaxPeriod extends BasicTester { +class LFSRMaxPeriod(gen: => UInt) extends BasicTester { - val lfsr16 = LFSR16() + val rv = gen val started = RegNext(true.B, false.B) + val seed = withReset(!started) { RegInit(rv) } - val (_, wrap) = Counter(started, math.pow(2.0, 16).toInt - 1) - when (lfsr16 === 1.U && started) { + val (_, wrap) = Counter(started, math.pow(2.0, rv.getWidth).toInt - 1) + when (rv === seed && started) { chisel3.assert(wrap) stop() } @@ -55,10 +58,10 @@ class LFSR16MaxPeriod extends BasicTester { class LFSRSpec extends ChiselPropSpec { property("LFSR16 can be used to produce pseudo-random numbers, this tests the distribution") { - assertTesterPasses{ new LFSRTester } + assertTesterPasses{ new LFSRDistribution(LFSR16()) } } property("LFSR16 period tester, Period should 2^16 - 1") { - assertTesterPasses { new LFSR16MaxPeriod } + assertTesterPasses { new LFSRMaxPeriod(LFSR16()) } } } |
