aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJack Koenig2021-05-14 11:12:19 -0700
committerGitHub2021-05-14 18:12:19 +0000
commitc2d72fd8a4f3558094094eed2f4a12f85d080c41 (patch)
tree6da2b363ae2af6639ff0a8b8aae05410711934fb /src/test
parentf33b93101e0e623dc345b27f18520fd5a5ca921d (diff)
Add JsonProtocol.serializeRecover (#2227)
This function will safely wrap any unserializeable annotations in UnserializeableAnnotations so that they can be safely serialized to JSON for logging.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/firrtlTests/annotationTests/JsonProtocolSpec.scala12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/test/scala/firrtlTests/annotationTests/JsonProtocolSpec.scala b/src/test/scala/firrtlTests/annotationTests/JsonProtocolSpec.scala
index 6dd018eb..b2d029f5 100644
--- a/src/test/scala/firrtlTests/annotationTests/JsonProtocolSpec.scala
+++ b/src/test/scala/firrtlTests/annotationTests/JsonProtocolSpec.scala
@@ -3,9 +3,10 @@
package firrtlTests.annotationTests
import firrtl._
-import firrtl.annotations.{JsonProtocol, NoTargetAnnotation, UnserializableAnnotationException}
+import firrtl.annotations._
import firrtl.ir._
import firrtl.options.Dependency
+import firrtl.transforms.DontTouchAnnotation
import scala.util.Failure
import _root_.logger.{LogLevel, LogLevelAnnotation, Logger}
import org.scalatest.flatspec.AnyFlatSpec
@@ -77,4 +78,13 @@ class JsonProtocolSpec extends AnyFlatSpec with Matchers {
e.getMessage should include("Classes defined in method bodies are not supported")
}
}
+ "JsonProtocol.serializeRecover" should "emit even annotations that cannot be serialized" in {
+ case class MyAnno(x: Int) extends NoTargetAnnotation
+ val target = CircuitTarget("Top").module("Foo").ref("x")
+ val annos = MyAnno(3) :: DontTouchAnnotation(target) :: Nil
+ val res = JsonProtocol.serializeRecover(annos)
+ res should include(""""class":"firrtl.annotations.UnserializeableAnnotation",""")
+ res should include(""""error":"Classes defined in method bodies are not supported.",""")
+ res should include(""""content":"MyAnno(3)"""")
+ }
}