summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/Module.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/chiselTests/Module.scala')
-rw-r--r--src/test/scala/chiselTests/Module.scala52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/test/scala/chiselTests/Module.scala b/src/test/scala/chiselTests/Module.scala
index e84e6a02..5f2927dd 100644
--- a/src/test/scala/chiselTests/Module.scala
+++ b/src/test/scala/chiselTests/Module.scala
@@ -3,6 +3,7 @@
package chiselTests
import chisel3._
+import chisel3.experimental.{withClock, withReset}
class SimpleIO extends Bundle {
val in = Input(UInt(32.W))
@@ -26,19 +27,6 @@ class ModuleVec(val n: Int) extends Module {
}
}
-/*
-class ModuleVecTester(c: ModuleVec) extends Tester(c) {
- for (t <- 0 until 16) {
- val test_ins = Array.fill(c.n){ rnd.nextInt(256) }
- for (i <- 0 until c.n)
- poke(c.io.ins(i), test_ins(i))
- step(1)
- for (i <- 0 until c.n)
- expect(c.io.outs(i), test_ins(i) + 1)
- }
-}
-*/
-
class ModuleWire extends Module {
val io = IO(new SimpleIO)
val inc = Wire(chiselTypeOf(Module(new PlusOne).io))
@@ -46,17 +34,6 @@ class ModuleWire extends Module {
io.out := inc.out
}
-/*
-class ModuleWireTester(c: ModuleWire) extends Tester(c) {
- for (t <- 0 until 16) {
- val test_in = rnd.nextInt(256)
- poke(c.io.in, test_in)
- step(1)
- expect(c.io.out, test_in + 1)
- }
-}
-*/
-
class ModuleWhen extends Module {
val io = IO(new Bundle {
val s = new SimpleIO
@@ -122,4 +99,31 @@ class ModuleSpec extends ChiselPropSpec {
elaborate { new ModuleRewrap }
}).getMessage should include("This is probably due to rewrapping a Module instance")
}
+
+ property("object Module.clock should return a reference to the currently in scope clock") {
+ elaborate(new Module {
+ val io = IO(new Bundle {
+ val clock2 = Input(Clock())
+ })
+ assert(Module.clock eq this.clock)
+ withClock(io.clock2) { assert(Module.clock eq io.clock2) }
+ })
+ }
+ property("object Module.reset should return a reference to the currently in scope reset") {
+ elaborate(new Module {
+ val io = IO(new Bundle {
+ val reset2 = Input(Bool())
+ })
+ assert(Module.reset eq this.reset)
+ withReset(io.reset2) { assert(Module.reset eq io.reset2) }
+ })
+ }
+ property("object Module.currentModule should return an Option reference to the current Module") {
+ def checkModule(mod: Module): Boolean = Module.currentModule.map(_ eq mod).getOrElse(false)
+ elaborate(new Module {
+ val io = IO(new Bundle { })
+ assert(Module.currentModule.get eq this)
+ assert(checkModule(this))
+ })
+ }
}