From 2e62da09ed1ed0725a14185ae76a683da73b32f4 Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Thu, 10 Nov 2016 10:05:15 -0800 Subject: Throw exceptions for cloneType failures - fix #358 Add a Builder.exception() method for those cases where continuing is likely to mask the initial error. --- .../MissingCloneBindingExceptionSpec.scala | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala (limited to 'src/test') diff --git a/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala b/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala new file mode 100644 index 00000000..fd48206e --- /dev/null +++ b/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala @@ -0,0 +1,57 @@ +// See LICENSE for license details. + +package chiselTests +import Chisel.ChiselException +import org.scalatest._ + +class MissingCloneBindingExceptionSpec extends FlatSpec with Matchers { + behavior of "missing cloneType in Chisel3" + ( the[ChiselException] thrownBy { + import chisel3._ + + class TestIO(w: Int) extends Bundle { + val a = Vec(4, UInt(width = w)).asInput + + //override def cloneType = (new TestIO(w)).asInstanceOf[this.type] + } + + class Test extends Module { + val io = IO(new TestIO(32)) + } + + class TestTop extends Module { + val io = IO(new Bundle {}) + + val subs = Vec.fill(2) { + Module(new Test).io + } + } + + val dummy = new TestTop + }).getMessage should include("needs cloneType method") + + behavior of "missing cloneType in Chisel2" + ( the[ChiselException] thrownBy { + import Chisel._ + + class TestIO(w: Int) extends Bundle { + val a = Vec(4, UInt(width = w)).asInput + + //override def cloneType = (new TestIO(w)).asInstanceOf[this.type] + } + + class Test extends Module { + val io = IO(new TestIO(32)) + } + + class TestTop extends Module { + val io = IO(new Bundle {}) + + val subs = Vec.fill(2) { + Module(new Test).io + } + } + + val dummy = new TestTop + }).getMessage should include("needs cloneType method") +} -- cgit v1.2.3 From 1b53d893816d349f5ea18fa0ed13325b9f1b6917 Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Mon, 14 Nov 2016 09:58:52 -0800 Subject: Avoid dynamicContext issues - use ChiselRunners.elaborate() --- src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/test') diff --git a/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala b/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala index fd48206e..719484ac 100644 --- a/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala +++ b/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala @@ -4,7 +4,7 @@ package chiselTests import Chisel.ChiselException import org.scalatest._ -class MissingCloneBindingExceptionSpec extends FlatSpec with Matchers { +class MissingCloneBindingExceptionSpec extends ChiselFlatSpec with Matchers { behavior of "missing cloneType in Chisel3" ( the[ChiselException] thrownBy { import chisel3._ @@ -27,7 +27,7 @@ class MissingCloneBindingExceptionSpec extends FlatSpec with Matchers { } } - val dummy = new TestTop + elaborate(new TestTop) }).getMessage should include("needs cloneType method") behavior of "missing cloneType in Chisel2" @@ -52,6 +52,6 @@ class MissingCloneBindingExceptionSpec extends FlatSpec with Matchers { } } - val dummy = new TestTop + elaborate(new TestTop) }).getMessage should include("needs cloneType method") } -- cgit v1.2.3