summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/BlackBox.scala
diff options
context:
space:
mode:
authorducky2015-12-10 16:22:59 -0800
committerducky2016-01-30 14:45:55 -0800
commit898efea92e9e13775b39dd7fb92cac420334b9c9 (patch)
treebb7cdb52fbfe90c44de5846f5175b27d894e3b27 /src/test/scala/chiselTests/BlackBox.scala
parent8d8c407c0c1693160d6f0972165e376e09aa99c9 (diff)
Add BlackBox support and test, refactor execute => assertTesterPasses
Diffstat (limited to 'src/test/scala/chiselTests/BlackBox.scala')
-rw-r--r--src/test/scala/chiselTests/BlackBox.scala68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/BlackBox.scala b/src/test/scala/chiselTests/BlackBox.scala
new file mode 100644
index 00000000..574a6335
--- /dev/null
+++ b/src/test/scala/chiselTests/BlackBox.scala
@@ -0,0 +1,68 @@
+// See LICENSE for license details.
+
+package chiselTests
+
+import java.io.File
+import org.scalatest._
+import Chisel._
+import Chisel.testers.BasicTester
+
+class BlackBoxInverter extends BlackBox {
+ val io = new Bundle() {
+ val in = Bool(INPUT)
+ val out = Bool(OUTPUT)
+ }
+}
+
+class BlackBoxPassthrough extends BlackBox {
+ val io = new Bundle() {
+ val in = Bool(INPUT)
+ val out = Bool(OUTPUT)
+ }
+}
+
+class BlackBoxTester extends BasicTester {
+ val blackBoxPos = Module(new BlackBoxInverter)
+ val blackBoxNeg = Module(new BlackBoxInverter)
+
+ blackBoxPos.io.in := UInt(1)
+ blackBoxNeg.io.in := UInt(0)
+
+ assert(blackBoxNeg.io.out === UInt(1))
+ assert(blackBoxPos.io.out === UInt(0))
+ stop()
+}
+
+/** Instantiate multiple BlackBoxes with similar interfaces but different
+ * functionality. Used to detect failures in BlackBox naming and module
+ * deduplication.
+ */
+
+class MultiBlackBoxTester extends BasicTester {
+ val blackBoxInvPos = Module(new BlackBoxInverter)
+ val blackBoxInvNeg = Module(new BlackBoxInverter)
+ val blackBoxPassPos = Module(new BlackBoxPassthrough)
+ val blackBoxPassNeg = Module(new BlackBoxPassthrough)
+
+ blackBoxInvPos.io.in := UInt(1)
+ blackBoxInvNeg.io.in := UInt(0)
+ blackBoxPassPos.io.in := UInt(1)
+ blackBoxPassNeg.io.in := UInt(0)
+
+ assert(blackBoxInvNeg.io.out === UInt(1))
+ assert(blackBoxInvPos.io.out === UInt(0))
+ assert(blackBoxPassNeg.io.out === UInt(0))
+ assert(blackBoxPassPos.io.out === UInt(1))
+ stop()
+}
+
+class BlackBoxSpec extends ChiselFlatSpec {
+ "A BlackBoxed inverter" should "work" in {
+ assertTesterPasses({ new BlackBoxTester },
+ Seq("/BlackBoxTest.v"))
+ }
+ "Multiple BlackBoxes" should "work" in {
+ assertTesterPasses({ new MultiBlackBoxTester },
+ Seq("/BlackBoxTest.v"))
+ }
+}