aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJack Koenig2018-03-22 11:53:51 -0700
committerGitHub2018-03-22 11:53:51 -0700
commitebb6847e9d01b424424ae11a0067448a4094e46d (patch)
treefc87aa9d7b7d437914f6a4c9e20487c0973a1fc3 /src/test
parent6ea4ac666e4ce8dfaca1545660f372fccff610f5 (diff)
Better bad annotation file error reporting (#771)
* Propagate exceptions from JsonProtocol deserialization * Add AnnotationFileNotFoundException for better error reporting * Add AnnotationClassNotFoundException for better error reporting * Better propagate JSON parsing errors Also report the file if there is a error deserializing a JSON file * Make exception for non-array JSON file more explicit
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/firrtlTests/AnnotationTests.scala82
1 files changed, 81 insertions, 1 deletions
diff --git a/src/test/scala/firrtlTests/AnnotationTests.scala b/src/test/scala/firrtlTests/AnnotationTests.scala
index f0d4cb25..c1e36b67 100644
--- a/src/test/scala/firrtlTests/AnnotationTests.scala
+++ b/src/test/scala/firrtlTests/AnnotationTests.scala
@@ -10,6 +10,7 @@ import firrtl._
import firrtl.transforms.OptimizableExtModuleAnnotation
import firrtl.passes.InlineAnnotation
import firrtl.passes.memlib.PinAnnotation
+import firrtl.util.BackendCompilationUtilities
import firrtl.transforms.DontTouchAnnotation
import net.jcazevedo.moultingyaml._
import org.scalatest.Matchers
@@ -476,7 +477,7 @@ class LegacyAnnotationTests extends AnnotationTests {
}
}
-class JsonAnnotationTests extends AnnotationTests {
+class JsonAnnotationTests extends AnnotationTests with BackendCompilationUtilities {
// Helper annotations
case class SimpleAnno(target: ComponentName, value: String) extends
SingleTargetAnnotation[ComponentName] {
@@ -511,4 +512,83 @@ class JsonAnnotationTests extends AnnotationTests {
annos should be (readAnnos)
}
+
+ private def setupManager(annoFileText: Option[String]) = {
+ val source = """
+ |circuit test :
+ | module test :
+ | input x : UInt<1>
+ | output z : UInt<1>
+ | z <= x
+ | node y = x""".stripMargin
+ val testDir = createTestDirectory(this.getClass.getSimpleName)
+ val annoFile = new File(testDir, "anno.json")
+
+ annoFileText.foreach { text =>
+ val w = new FileWriter(annoFile)
+ w.write(text)
+ w.close()
+ }
+
+ new ExecutionOptionsManager("annos") with HasFirrtlOptions {
+ commonOptions = CommonOptions(targetDirName = testDir.getPath)
+ firrtlOptions = FirrtlExecutionOptions(
+ firrtlSource = Some(source),
+ annotationFileNames = List(annoFile.getPath)
+ )
+ }
+ }
+
+ "Annotation file not found" should "give a reasonable error message" in {
+ val manager = setupManager(None)
+
+ an [AnnotationFileNotFoundException] shouldBe thrownBy {
+ Driver.execute(manager)
+ }
+ }
+
+ "Annotation class not found" should "give a reasonable error message" in {
+ val anno = """
+ |[
+ | {
+ | "class":"ThisClassDoesNotExist",
+ | "target":"test.test.y"
+ | }
+ |] """.stripMargin
+ val manager = setupManager(Some(anno))
+
+ the [Exception] thrownBy Driver.execute(manager) should matchPattern {
+ case InvalidAnnotationFileException(_, _: AnnotationClassNotFoundException) =>
+ }
+ }
+
+ "Malformed annotation file" should "give a reasonable error message" in {
+ val anno = """
+ |[
+ | {
+ | "class":
+ | "target":"test.test.y"
+ | }
+ |] """.stripMargin
+ val manager = setupManager(Some(anno))
+
+ the [Exception] thrownBy Driver.execute(manager) should matchPattern {
+ case InvalidAnnotationFileException(_, _: InvalidAnnotationJSONException) =>
+ }
+ }
+
+ "Non-array annotation file" should "give a reasonable error message" in {
+ val anno = """
+ |{
+ | "class":"firrtl.transforms.DontTouchAnnotation",
+ | "target":"test.test.y"
+ |}
+ |""".stripMargin
+ val manager = setupManager(Some(anno))
+
+ the [Exception] thrownBy Driver.execute(manager) should matchPattern {
+ case InvalidAnnotationFileException(_, InvalidAnnotationJSONException(msg))
+ if msg.contains("JObject") =>
+ }
+ }
}