diff options
| author | Henry Cook | 2015-08-14 00:53:57 -0700 |
|---|---|---|
| committer | Henry Cook | 2015-08-14 00:53:57 -0700 |
| commit | 5e9be183f98d32164332fa0548fe80686f50c851 (patch) | |
| tree | 03fd0f52b35e6c194077a0b94d03fa3a6ddc26d9 /src/test/scala/chiselTests/Tbl.scala | |
| parent | caf993c89ba07a65d05b0e17d109a60f96330136 (diff) | |
added MulLookup and Tbl tests
Diffstat (limited to 'src/test/scala/chiselTests/Tbl.scala')
| -rw-r--r-- | src/test/scala/chiselTests/Tbl.scala | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Tbl.scala b/src/test/scala/chiselTests/Tbl.scala new file mode 100644 index 00000000..4add985e --- /dev/null +++ b/src/test/scala/chiselTests/Tbl.scala @@ -0,0 +1,47 @@ +package chiselTests + +import Chisel._ +import org.scalatest._ +import org.scalatest.prop._ +import Chisel.testers.BasicTester + +class Tbl(w: Int, n: Int) extends Module { + val io = new Bundle { + val wi = UInt(INPUT, log2Ceil(w)) + val ri = UInt(INPUT, log2Ceil(w)) + val we = Bool(INPUT) + val d = UInt(INPUT, w) + val o = UInt(OUTPUT, w) + } + val m = Mem(UInt(width = w), n) + io.o := m(io.ri) + when (io.we) { + m(io.wi) := io.d + when(io.ri === io.wi) { io.o := io.d } + } +} + +class TblSpec extends ChiselPropSpec { + + class TblTester(w: Int, n: Int, idxs: List[Int], values: List[Int]) extends BasicTester { + val (cnt, wrap) = Counter(Bool(true), idxs.size) + val dut = Module(new Tbl(w, n)) + val vvalues = Vec(values.map(UInt(_))) + val vidxs = Vec(idxs.map(UInt(_))) + val prev_idx = vidxs(cnt - UInt(1)) + val prev_value = vvalues(cnt - UInt(1)) + dut.io.wi := vidxs(cnt) + dut.io.ri := prev_idx + dut.io.we := Bool(true) //TODO enSequence + dut.io.d := vvalues(cnt) + when(cnt > UInt(0) && dut.io.o != prev_value) { io.done := Bool(true); io.error := prev_idx } + when(wrap) { io.done := Bool(true) } + } + + property("All table reads should return the previous write") { + forAll(safeUIntPairN(8)) { case(w: Int, pairs: List[(Int, Int)]) => + val (idxs, values) = pairs.unzip + assert(execute{ new TblTester(w, 1 << w, idxs, values) }) + } + } +} |
