From d1611f81badf54aaf460ba37f01dc98c4005d82a Mon Sep 17 00:00:00 2001 From: chick Date: Tue, 9 Feb 2016 11:24:08 -0800 Subject: Added support for finish method of BasicTester to be overridden in a subclass which allows tester to have clean up and other construction code executed after a user code executed during constructor of that subclass --- src/main/scala/Chisel/testers/BasicTester.scala | 2 ++ src/main/scala/Chisel/testers/TesterDriver.scala | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/scala/Chisel/testers/BasicTester.scala b/src/main/scala/Chisel/testers/BasicTester.scala index 6807a30e..98033486 100644 --- a/src/main/scala/Chisel/testers/BasicTester.scala +++ b/src/main/scala/Chisel/testers/BasicTester.scala @@ -24,4 +24,6 @@ class BasicTester extends Module { pushCommand(Stop(Node(clock), 0)) } } + + def finish(): Unit = {} } diff --git a/src/main/scala/Chisel/testers/TesterDriver.scala b/src/main/scala/Chisel/testers/TesterDriver.scala index b25b160b..2b7019c9 100644 --- a/src/main/scala/Chisel/testers/TesterDriver.scala +++ b/src/main/scala/Chisel/testers/TesterDriver.scala @@ -23,7 +23,7 @@ object TesterDriver extends BackendCompilationUtilities { * frontend, and which can be turned into executables with assertions. */ def execute(t: () => BasicTester, additionalVResources: Seq[String] = Seq()): Boolean = { // Invoke the chisel compiler to get the circuit's IR - val circuit = Driver.elaborate(t) + val circuit = Driver.elaborate(finishWrapper(t)) // Set up a bunch of file handlers based on a random temp filename, // plus the quirks of Verilator's naming conventions @@ -55,4 +55,17 @@ 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 + */ + def finishWrapper(test: () => BasicTester): () => BasicTester = { + () => { + val tester = test() + tester.finish() + tester + } + } } -- cgit v1.2.3 From 82da362037a227a1c16eb56ead69f3f73cea6c4f Mon Sep 17 00:00:00 2001 From: chick Date: Wed, 10 Feb 2016 12:11:51 -0800 Subject: Added some comments describing potential use of the finish method hook clean up the test example --- src/main/scala/Chisel/testers/BasicTester.scala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main') diff --git a/src/main/scala/Chisel/testers/BasicTester.scala b/src/main/scala/Chisel/testers/BasicTester.scala index 98033486..8f4d60f4 100644 --- a/src/main/scala/Chisel/testers/BasicTester.scala +++ b/src/main/scala/Chisel/testers/BasicTester.scala @@ -25,5 +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 + */ def finish(): Unit = {} } -- cgit v1.2.3 From a9355ba3784e3c5ae611f096a48b4ee5c78464ad Mon Sep 17 00:00:00 2001 From: chick Date: Wed, 10 Feb 2016 14:29:49 -0800 Subject: TesterDriverSpec is simpler and cleaner, extraneous circuit has been removed. Cleanup comment for finish method in BasicTester, and finishWrapper in TesterDriver. --- src/main/scala/Chisel/testers/BasicTester.scala | 8 ++++---- src/main/scala/Chisel/testers/TesterDriver.scala | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/main') 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() -- cgit v1.2.3