diff options
| author | Jack Koenig | 2020-09-05 20:00:35 -0700 |
|---|---|---|
| committer | GitHub | 2020-09-06 03:00:35 +0000 |
| commit | b6de1491af7ba88bb778aaeeba369b6b87151f9e (patch) | |
| tree | f99e6408ff24995e10273537f7db9048bb2ff8e9 /src/test | |
| parent | 47c81ee3e68c96e94dafa389cb53b162e996a4df (diff) | |
Support binary files in CustomFileEmission (#1887)
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala b/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala index 4fe16041..9e58585c 100644 --- a/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala +++ b/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala @@ -142,6 +142,28 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t new File(serializedFileName) should (exist) } + it should "support CustomFileEmission to binary files" in new Fixture { + val file = new File("write-CustomFileEmission-binary-files.anno.json") + val data = Array[Byte](0x0a, 0xa0.toByte) + val annotations = Seq( + TargetDirAnnotation(dir), + OutputAnnotationFileAnnotation(file.toString), + WriteOutputAnnotationsSpec.Binary(data) + ) + + val serializedFileName = view[StageOptions](annotations).getBuildFileName("Binary", Some(".Emission")) + val out = phase.transform(annotations) + + info(s"file '$serializedFileName' exists") + new File(serializedFileName) should (exist) + + info(s"file '$serializedFileName' is correct") + val inputStream = new java.io.FileInputStream(serializedFileName) + val result = new Array[Byte](2) + inputStream.read(result) + result should equal(data) + } + it should "error if multiple annotations try to write to the same file" in new Fixture { val file = new File("write-CustomFileEmission-annotations-error.anno.json") val annotations = Seq( @@ -175,6 +197,15 @@ private object WriteOutputAnnotationsSpec { } + case class Binary(value: Array[Byte]) extends NoTargetAnnotation with CustomFileEmission { + + override protected def baseFileName(a: AnnotationSeq): String = "Binary" + + override protected def suffix: Option[String] = Some(".Emission") + + override def getBytes: Iterable[Byte] = value + } + case class Replacement(file: String) extends NoTargetAnnotation } |
