diff options
| author | Andrew Waterman | 2016-02-04 00:00:19 -0800 |
|---|---|---|
| committer | Andrew Waterman | 2016-02-04 00:00:19 -0800 |
| commit | 62fa95acc5d3d301fe461c5844c29d0c75ca6a5d (patch) | |
| tree | 89893f19fba9aacc7e18ba8013b428e9f1e03482 /src/test/scala/chiselTests/BlackBox.scala | |
| parent | 7fc2ea6a14da441db9c47d094361fea07436f6d3 (diff) | |
| parent | c5240a3bfe1c05a206c7c34c3c7c5007bbcc3680 (diff) | |
Merge branch 'blackbox't push origin master
Diffstat (limited to 'src/test/scala/chiselTests/BlackBox.scala')
| -rw-r--r-- | src/test/scala/chiselTests/BlackBox.scala | 68 |
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")) + } +} |
