Commit 9749d045 authored by Jens Korinth's avatar Jens Korinth
Browse files

Fix bug in DecoupledDataSourceSuite

* chisel3 is a little finicky with peek/poke: it seems only stuff in the
  io bundle of modules is really safe
* needed to replace peeking in the internal mems, since that seems
  to crash the LoFirrtlEvaluator
* all tests functional again
parent 04f0a4d7
......@@ -20,7 +20,7 @@ class DecoupledDataSourceIO[T <: Data](gen: T) extends Bundle {
otherwise valid will go low after data was
consumed.
**/
class DecoupledDataSource[T <: Data](gen: T, val size : Int, data: (Int) => T, val repeat: Boolean = true) extends Module {
class DecoupledDataSource[T <: Data](gen: T, val size : Int, val data: (Int) => T, val repeat: Boolean = true) extends Module {
println ("DecoupledDataSource: size = %d, repeat = %s".format(size, if (repeat) "true" else "false"))
println(" width = %d".format(log2Ceil(if (repeat) size else size + 1)))
......
......@@ -9,7 +9,7 @@ import chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
* each dequeued output matches the expected value. Also checks whether
* or not the module wraps correctly (in case repeat is true).
**/
class DecoupledDataSource_OutputCheck[T <: UInt](m: DecoupledDataSource[T]) extends PeekPokeTester(m) {
class DecoupledDataSource_OutputCheck[T <: UInt](m: DecoupledDataSource[T], data: Int => Int) extends PeekPokeTester(m) {
import scala.util.Properties.{lineSeparator => NL}
poke(m.io.out.ready, true)
......@@ -20,8 +20,8 @@ class DecoupledDataSource_OutputCheck[T <: UInt](m: DecoupledDataSource[T]) exte
if (! m.repeat)
errors = "repeat is false, but index (%d) exceeds size(%d)".format(i, m.size) :: errors
} else {
if (peek(m.io.out.bits) != peek(m.ds(i))) {
errors = "output #%d: expected %d, found %d".format(i, peek(m.ds(i)), peek(m.io.out.bits)) :: errors
if (peek(m.io.out.bits) != m.data(i)) {
errors = "output #%d: expected %d, found %d".format(i, data(i), peek(m.io.out.bits)) :: errors
} else {
// wait for random time up to 10 cycles
val wait = (scala.math.random * 10).toInt
......@@ -43,24 +43,27 @@ class DecoupledDataSourceSuite extends ChiselFlatSpec {
val cnt = Seq(1, (scala.math.random * 1000).toInt).max
val width = Seq(1, (scala.math.random * 64).toInt).max
val repeat = scala.math.random > 0.5
val data = for (i <- 0 until cnt) yield (scala.math.random * scala.math.pow(2, width)).toInt
println("testing cnt = %d, width = %d, repeat = %b ...".format(cnt, width, repeat))
Driver.execute(Array("--fint-write-vcd", "--target-dir", "test/DecoupledDataSourceSuite/checkRandomOutputs"),
() => new DecoupledDataSource(UInt(width.W), cnt, i => (scala.math.random * scala.math.pow(2, width)).toInt.U, repeat))
{ m => new DecoupledDataSource_OutputCheck(m) }
() => new DecoupledDataSource(UInt(width.W), cnt, i => data(i).U, repeat))
{ m => new DecoupledDataSource_OutputCheck(m, data) }
}
}
/** Performs test for 8bit wide sequential data with repeat. **/
"checkSequentialOutputsWithRepeat" should "be ok" in {
val data = 0 until 256
Driver.execute(Array("--fint-write-vcd", "--target-dir", "test/DecoupledDataSourceSuite/checkSequentialOutputsWithRepeat"),
() => new DecoupledDataSource(UInt(8.W), 256, i => i.U, true))
{ m => new DecoupledDataSource_OutputCheck(m) }
() => new DecoupledDataSource(UInt(8.W), 256, i => data(i).U, true))
{ m => new DecoupledDataSource_OutputCheck(m, data) }
}
/** Performs test for 8bit wide sequential data without repeat. **/
"checkSequentialOutputsWithoutRepeat" should "be ok" in {
val data = 0 until 256
Driver.execute(Array("--fint-write-vcd", "--target-dir", "test/DecoupledDataSourceSuite/checkSequentialOutputWithoutRepeat"),
() => new DecoupledDataSource(UInt(8.W), 256, i => i.U, false))
{ m => new DecoupledDataSource_OutputCheck(m) }
() => new DecoupledDataSource(UInt(8.W), 256, i => data(i).U, false))
{ m => new DecoupledDataSource_OutputCheck(m, data) }
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment