summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/Module.scala
diff options
context:
space:
mode:
authorJack2016-11-11 14:37:03 -0800
committerJack Koenig2016-11-14 11:11:02 -0800
commit815b1c3cb311b7f4dfb7a2f00e0e2d62795bdc6b (patch)
treec9cb68e6cbb844a0da9af23afce1b470a2d3481e /src/test/scala/chiselTests/Module.scala
parente60761cf72ba572da0bb8387a4506f5c3e211ac9 (diff)
Add checks for misuse or omission of Module()
Implemented by adding a Boolean to check for alternating invocations of object Module.apply and the constructor of abstract class Module. Fixes #192
Diffstat (limited to 'src/test/scala/chiselTests/Module.scala')
-rw-r--r--src/test/scala/chiselTests/Module.scala34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Module.scala b/src/test/scala/chiselTests/Module.scala
index 7a4050db..c902d073 100644
--- a/src/test/scala/chiselTests/Module.scala
+++ b/src/test/scala/chiselTests/Module.scala
@@ -69,6 +69,22 @@ class ModuleWhen extends Module {
} otherwise { io.s.out := io.s.in }
}
+class ModuleForgetWrapper extends Module {
+ val io = IO(new SimpleIO)
+ val inst = new PlusOne
+}
+
+class ModuleDoubleWrap extends Module {
+ val io = IO(new SimpleIO)
+ val inst = Module(Module(new PlusOne))
+}
+
+class ModuleRewrap extends Module {
+ val io = IO(new SimpleIO)
+ val inst = Module(new PlusOne)
+ val inst2 = Module(inst)
+}
+
class ModuleSpec extends ChiselPropSpec {
property("ModuleVec should elaborate") {
@@ -88,4 +104,22 @@ class ModuleSpec extends ChiselPropSpec {
}
ignore("ModuleWhenTester should return the correct result") { }
+
+ property("Forgetting a Module() wrapper should result in an error") {
+ (the [ChiselException] thrownBy {
+ elaborate { new ModuleForgetWrapper }
+ }).getMessage should include("attempted to instantiate a Module without wrapping it")
+ }
+
+ property("Double wrapping a Module should result in an error") {
+ (the [ChiselException] thrownBy {
+ elaborate { new ModuleDoubleWrap }
+ }).getMessage should include("Called Module() twice without instantiating a Module")
+ }
+
+ property("Rewrapping an already instantiated Module should result in an error") {
+ (the [ChiselException] thrownBy {
+ elaborate { new ModuleRewrap }
+ }).getMessage should include("This is probably due to rewrapping a Module instance")
+ }
}