summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/Chisel/testers/BasicTester.scala8
-rw-r--r--src/main/scala/Chisel/testers/TesterDriver.scala10
-rw-r--r--src/test/scala/chiselTests/TesterDriverSpec.scala48
3 files changed, 26 insertions, 40 deletions
diff --git a/src/main/scala/Chisel/testers/BasicTester.scala b/src/main/scala/Chisel/testers/BasicTester.scala
index 8f4d60f4..d3e9e7c8 100644
--- a/src/main/scala/Chisel/testers/BasicTester.scala
+++ b/src/main/scala/Chisel/testers/BasicTester.scala
@@ -25,10 +25,10 @@ class BasicTester extends Module {
}
}
- /** Called this class or a subclass's constructor has finished giving
- * developers of chisel testers a post construction hook.
- * For example, a decoupled tester subclassing BasicTester could override finish in order to
- * add flow control logic around loading the device under test's input io from a Vec of values
+ /** The finish method provides a hook that subclasses of BasicTester can use to
+ * alter a circuit after their constructor has been called.
+ * For example, a specialized tester subclassing BasicTester could override finish in order to
+ * add flow control logic for a decoupled io port of a device under test
*/
def finish(): Unit = {}
}
diff --git a/src/main/scala/Chisel/testers/TesterDriver.scala b/src/main/scala/Chisel/testers/TesterDriver.scala
index 2b7019c9..4547f48f 100644
--- a/src/main/scala/Chisel/testers/TesterDriver.scala
+++ b/src/main/scala/Chisel/testers/TesterDriver.scala
@@ -55,12 +55,10 @@ object TesterDriver extends BackendCompilationUtilities {
false
}
}
- /*
- * provides a hook for testers to implement necessary control logic for tests after the
- * implementation of the users test definition has been completed.
- * typically the finish method will inspect the users circuit and connect the tester
- * to the device under test
- */
+ /**
+ * Calls the finish method of an BasicTester or a class that extends it.
+ * The finish method is a hook for code that augments the circuit built in the constructor.
+ */
def finishWrapper(test: () => BasicTester): () => BasicTester = {
() => {
val tester = test()
diff --git a/src/test/scala/chiselTests/TesterDriverSpec.scala b/src/test/scala/chiselTests/TesterDriverSpec.scala
index d7cb0305..dfdd07cc 100644
--- a/src/test/scala/chiselTests/TesterDriverSpec.scala
+++ b/src/test/scala/chiselTests/TesterDriverSpec.scala
@@ -5,51 +5,39 @@ package chiselTests
import Chisel._
import Chisel.testers.BasicTester
-/** Extend basic tester with a finish method. TesterDriver will call the
- * finish method after the Tester's constructor has completed
- * -
- * In this example we use last connect semantics to alter the circuit after
- * the constructor has completed
+/** 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))
- test_wire := UInt(1, width = test_wire_width)
- // though we just test_wire to 1, the assert below will be true because
- // the finish will override it
+ // though we just set test_wire to 1, the assert below will pass because
+ // the finish will change it's 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, width = test_wire_width)
- }
-}
-
-class DummyCircuit extends Module {
- val io = new Bundle {
- val in = UInt(INPUT, width = 1)
- val out = UInt(OUTPUT, width = 1)
+ test_wire := UInt(test_wire_override_value)
}
-
- io.out := io.in
-}
-
-class DummyTester extends FinishTester {
- val dut = Module(new DummyCircuit)
-
- dut.io.in := UInt(1)
- Chisel.assert(dut.io.out === UInt(1))
-
- stop()
}
class TesterDriverSpec extends ChiselFlatSpec {
- "TesterDriver calls a BasicTester subclass's finish method which" should
- "allow modifications of test circuit after tester constructor is done" in {
+ "TesterDriver calls BasicTester's finish method which" should
+ "allow modifications of test circuit after the tester's constructor is done" in {
assertTesterPasses {
- new DummyTester
+ new FinishTester
}
}
}