summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/ToTargetSpec.scala
diff options
context:
space:
mode:
authorJack2022-07-30 22:41:15 +0000
committerJack2022-07-30 22:41:15 +0000
commit4cd44fa4dab370fcc5c20bcacc1fa0ee02327252 (patch)
tree05730be260feca0d2a870c4bb88325d36631a8fc /src/test/scala/chiselTests/ToTargetSpec.scala
parentfe9635ef21bad233945617a24ab16cfa4055f2d1 (diff)
parentbced77045c8fc5db37e40b159c49220929e15d46 (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'src/test/scala/chiselTests/ToTargetSpec.scala')
-rw-r--r--src/test/scala/chiselTests/ToTargetSpec.scala52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/ToTargetSpec.scala b/src/test/scala/chiselTests/ToTargetSpec.scala
new file mode 100644
index 00000000..dc4ec448
--- /dev/null
+++ b/src/test/scala/chiselTests/ToTargetSpec.scala
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package chiselTests
+
+import chisel3._
+import chisel3.stage.ChiselStage
+import chisel3.util.Queue
+import chisel3.internal.ChiselException
+
+class ToTargetSpec extends ChiselFlatSpec with Utils {
+
+ var m: InstanceNameModule = _
+ ChiselStage.elaborate { m = new InstanceNameModule; m }
+
+ val mn = "InstanceNameModule"
+ val top = s"~$mn|$mn"
+
+ behavior.of(".toTarget")
+
+ val deprecationMsg = "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated"
+
+ it should "work with module IO" in {
+ val io = m.io.toTarget.toString
+ assert(io == s"$top>io")
+ }
+
+ it should "not work for literals" in {
+ a[ChiselException] shouldBe thrownBy {
+ m.x.toTarget.toString
+ }
+ }
+
+ it should "work with non-hardware values (but be deprecated)" in {
+ val (ylog, y) = grabLog(m.y.toTarget.toString)
+ val (zlog, z) = grabLog(m.z.toTarget.toString)
+ assert(y == s"$top>y")
+ ylog should include(deprecationMsg)
+ assert(z == s"$top>z")
+ zlog should include(deprecationMsg)
+ }
+
+ it should "work with non-hardware bundle elements (but be deprecated)" in {
+ val (log, foo) = grabLog(m.z.foo.toTarget.toString)
+ log should include(deprecationMsg)
+ assert(foo == s"$top>z.foo")
+ }
+
+ it should "work with modules" in {
+ val q = m.q.toTarget.toString
+ assert(q == s"~$mn|Queue")
+ }
+}