summaryrefslogtreecommitdiff
path: root/src/test/scala/ChiselTests/Stack.scala
diff options
context:
space:
mode:
authorHenry Cook2015-08-12 19:32:43 -0700
committerHenry Cook2015-08-12 19:32:57 -0700
commit85d7403f9bf7bc2b3520f924736c237f21f70ebd (patch)
tree64560f779063a419395a2fb8a31ea52c52af4404 /src/test/scala/ChiselTests/Stack.scala
parent7e69966362b1dbd9835695250494857f3a3767c8 (diff)
being to convert tests to scala-test; tests compile and run
Diffstat (limited to 'src/test/scala/ChiselTests/Stack.scala')
-rw-r--r--src/test/scala/ChiselTests/Stack.scala63
1 files changed, 0 insertions, 63 deletions
diff --git a/src/test/scala/ChiselTests/Stack.scala b/src/test/scala/ChiselTests/Stack.scala
deleted file mode 100644
index c11a9ced..00000000
--- a/src/test/scala/ChiselTests/Stack.scala
+++ /dev/null
@@ -1,63 +0,0 @@
-package ChiselTests
-import scala.collection.mutable.{Stack => ScalaStack}
-import Chisel._
-import Chisel.testers._
-
-class Stack(val depth: Int) extends Module {
- val io = new Bundle {
- val push = Bool(INPUT)
- val pop = Bool(INPUT)
- val en = Bool(INPUT)
- val dataIn = UInt(INPUT, 32)
- val dataOut = UInt(OUTPUT, 32)
- }
-
- val stack_mem = Mem(UInt(width = 32), depth)
- val sp = Reg(init = UInt(0, width = log2Up(depth+1)))
- val out = Reg(init = UInt(0, width = 32))
-
- when (io.en) {
- when(io.push && (sp < UInt(depth))) {
- stack_mem(sp) := io.dataIn
- sp := sp +% UInt(1)
- } .elsewhen(io.pop && (sp > UInt(0))) {
- sp := sp -% UInt(1)
- }
- when (sp > UInt(0)) {
- out := stack_mem(sp -% UInt(1))
- }
- }
- io.dataOut := out
-}
-
-class StackTester(c: Stack) extends Tester(c) {
- var nxtDataOut = 0
- var dataOut = 0
- val stack = new ScalaStack[Int]()
-
- for (t <- 0 until 16) {
- val enable = rnd.nextInt(2)
- val push = rnd.nextInt(2)
- val pop = rnd.nextInt(2)
- val dataIn = rnd.nextInt(256)
-
- if (enable == 1) {
- dataOut = nxtDataOut
- if (push == 1 && stack.length < c.depth) {
- stack.push(dataIn)
- } else if (pop == 1 && stack.length > 0) {
- stack.pop()
- }
- if (stack.length > 0) {
- nxtDataOut = stack.top
- }
- }
-
- poke(c.io.pop, pop)
- poke(c.io.push, push)
- poke(c.io.en, enable)
- poke(c.io.dataIn, dataIn)
- step(1)
- expect(c.io.dataOut, dataOut)
- }
-}