summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAdam Izraelevitz2015-12-11 10:51:32 -0800
committerAdam Izraelevitz2015-12-11 10:51:32 -0800
commit20951ecdbcb81c194ddcdd1e8241b1bdd647dd9f (patch)
treee8d16909dc94b324a4a49caa77f705a7d342adaa /src/test
parentf094430e20d7db5fed60e0a306ab22169d705d71 (diff)
parentf74180a50bf466d275e1faeb78ccf67b51387bcb (diff)
Merge pull request #64 from ucb-bar/optionablebundle
Add Option support in Bundle
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/chiselTests/OptionBundle.scala62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/OptionBundle.scala b/src/test/scala/chiselTests/OptionBundle.scala
new file mode 100644
index 00000000..1b7be1ec
--- /dev/null
+++ b/src/test/scala/chiselTests/OptionBundle.scala
@@ -0,0 +1,62 @@
+// See LICENSE for license details.
+
+package chiselTests
+
+import org.scalatest._
+import Chisel._
+import Chisel.testers.BasicTester
+
+class OptionBundle(hasIn: Boolean) extends Bundle {
+ val in = if (hasIn) {
+ Some(Bool(INPUT))
+ } else {
+ None
+ }
+ val out = Bool(OUTPUT)
+}
+
+class OptionBundleModule(hasIn: Boolean) extends Module {
+ val io = new OptionBundle(hasIn)
+ if (hasIn) {
+ io.out := io.in.get
+ } else {
+ io.out := Bool(false)
+ }
+}
+
+class SomeOptionBundleTester(expected: Boolean) extends BasicTester {
+ val mod = Module(new OptionBundleModule(true))
+ mod.io.in.get := Bool(expected)
+ io.error := mod.io.out != Bool(expected)
+ io.done := Bool(true)
+}
+
+class NoneOptionBundleTester() extends BasicTester {
+ val mod = Module(new OptionBundleModule(true))
+ io.error := mod.io.out != Bool(false)
+ io.done := Bool(true)
+}
+
+class InvalidOptionBundleTester() extends BasicTester {
+ val mod = Module(new OptionBundleModule(false))
+ mod.io.in.get := Bool(true)
+ io.error := UInt(1)
+ io.done := Bool(true)
+}
+
+class OptionBundleSpec extends ChiselFlatSpec {
+ "A Bundle with an Option field" should "work properly if the Option field is not None" in {
+ assert(execute { new SomeOptionBundleTester(true) })
+ assert(execute { new SomeOptionBundleTester(false) })
+ }
+
+ "A Bundle with an Option field" should "compile if the Option field is None" in {
+ assert(execute { new NoneOptionBundleTester() })
+ }
+
+ "A Bundle with an Option field" should "assert out accessing a None Option field" in {
+ a [Exception] should be thrownBy {
+ elaborate { new InvalidOptionBundleTester() }
+ }
+ }
+}