summaryrefslogtreecommitdiff
path: root/src/test/scala/ChiselTests/Tbl.scala
diff options
context:
space:
mode:
authorJim Lawson2015-05-11 13:02:03 -0700
committerJim Lawson2015-07-24 15:50:53 -0700
commit2ae50411cbc5e2cd5fdc9ca4069b9c5f64919bc4 (patch)
treea656e44d86a68a7c53b159fe6c74d328a126126d /src/test/scala/ChiselTests/Tbl.scala
parentb208bfb5691c7b5921dd47d0b599726872acd1cd (diff)
Incorporate chisel3-tests; update Makefile.
Diffstat (limited to 'src/test/scala/ChiselTests/Tbl.scala')
-rw-r--r--src/test/scala/ChiselTests/Tbl.scala31
1 files changed, 31 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..390f5882
--- /dev/null
+++ b/src/test/scala/ChiselTests/Tbl.scala
@@ -0,0 +1,31 @@
+package ChiselTests
+import Chisel._
+
+class Tbl extends Module {
+ val io = new Bundle {
+ val i = Bits(INPUT, 16)
+ val we = Bool(INPUT)
+ val d = Bits(INPUT, 16)
+ val o = Bits(OUTPUT, 16)
+ }
+ val m = Mem(Bits(width = 10), 256)
+ io.o := Bits(0)
+ when (io.we) { m(io.i) := io.d(9, 0) }
+ .otherwise { io.o := m(io.i) }
+}
+
+class TblTester(c: Tbl) extends Tester(c) {
+ val m = Array.fill(1 << 16){ 0 }
+ for (t <- 0 until 16) {
+ val i = rnd.nextInt(1 << 16)
+ val d = rnd.nextInt(1 << 16)
+ val we = rnd.nextInt(2)
+ poke(c.io.i, i)
+ poke(c.io.we, we)
+ poke(c.io.d, d)
+ step(1)
+ expect(c.io.o, if (we == 1) 0 else m(i))
+ if (we == 1)
+ m(i) = d
+ }
+}