summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorRichard Lin2016-02-22 12:54:40 -0800
committerRichard Lin2016-02-22 12:54:40 -0800
commit9bf707687777cc952287219c86e817e0f6a698ae (patch)
tree39d48f546293a02f79bd54234c673b4f830913eb /src/test
parentc85f9ff1c9ca9286d44a94f4a00aed67f4d916d3 (diff)
parentd87db04ff7a5cb12443529861558f1850448170b (diff)
Merge pull request #99 from ucb-bar/chisel_tester_support
Chisel tester support
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/chiselTests/TesterDriverSpec.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/TesterDriverSpec.scala b/src/test/scala/chiselTests/TesterDriverSpec.scala
new file mode 100644
index 00000000..3c57daae
--- /dev/null
+++ b/src/test/scala/chiselTests/TesterDriverSpec.scala
@@ -0,0 +1,44 @@
+// See LICENSE for license details.
+
+package chiselTests
+
+import Chisel._
+import Chisel.testers.BasicTester
+
+/** Extend BasicTester with a simple circuit and finish method. TesterDriver will call the
+ * finish method after the FinishTester's constructor has completed, which will alter the
+ * circuit after the constructor has finished.
+ */
+class FinishTester extends BasicTester {
+ val test_wire_width = 2
+ val test_wire_override_value = 3
+
+ val counter = Counter(1)
+
+ when(counter.inc()) {
+ stop()
+ }
+
+ val test_wire = Wire(UInt(1, width = test_wire_width))
+
+ // though we just set test_wire to 1, the assert below will pass because
+ // the finish will change its value
+ assert(test_wire === UInt(test_wire_override_value))
+
+ /** In finish we use last connect semantics to alter the test_wire in the circuit
+ * with a new value
+ */
+ override def finish(): Unit = {
+ test_wire := UInt(test_wire_override_value)
+ }
+}
+
+class TesterDriverSpec extends ChiselFlatSpec {
+ "TesterDriver calls BasicTester's finish method which" should
+ "allow modifications of test circuit after the tester's constructor is done" in {
+ assertTesterPasses {
+ new FinishTester
+ }
+ }
+}
+