summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchick2016-02-09 11:24:08 -0800
committerchick2016-02-09 11:24:08 -0800
commitd1611f81badf54aaf460ba37f01dc98c4005d82a (patch)
tree19249e3bb9f006b5bb334fff3b8a3fd90e72fe83 /src
parentc2db03d0a752e084c1ca452ee477c88d930d0bc6 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/Chisel/testers/BasicTester.scala2
-rw-r--r--src/main/scala/Chisel/testers/TesterDriver.scala15
-rw-r--r--src/test/scala/chiselTests/DeqIOSpec.scala54
-rw-r--r--src/test/scala/chiselTests/TesterDriverSpec.scala10
4 files changed, 41 insertions, 40 deletions
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
+ }
+ }
}
diff --git a/src/test/scala/chiselTests/DeqIOSpec.scala b/src/test/scala/chiselTests/DeqIOSpec.scala
index 8f7937ab..dfa63eb1 100644
--- a/src/test/scala/chiselTests/DeqIOSpec.scala
+++ b/src/test/scala/chiselTests/DeqIOSpec.scala
@@ -8,52 +8,28 @@ import Chisel.testers.BasicTester
/**
* Created by chick on 2/8/16.
*/
-class UsesDeqIOInfo extends Bundle {
- val test_width = 32
+class FinishTester extends BasicTester {
+ var finish_was_run = false
- val info_data = UInt(width = test_width)
+ override def finish(): Unit = {
+ finish_was_run = true
+ }
}
-class UsesDeqIO extends Module {
- val io = new Bundle {
- val in = new DeqIO(new UsesDeqIOInfo)
- val out = new EnqIO(new UsesDeqIOInfo)
+class FinishTesterSpec extends ChiselFlatSpec {
+ class DummyCircuit extends Module {
+ val io = new Bundle {
+ val in = Bool(INPUT)
+ val out = Bool(OUTPUT)
+ }
}
-}
-class DeqIOSpec extends ChiselFlatSpec {
runTester {
- new BasicTester {
- val dut = new UsesDeqIO
-
- "DeqIO" should "set the direction of it's parameter to INPUT" in {
- assert(dut.io.in.bits.info_data.dir === INPUT)
- }
- "DeqIO" should "create a valid input and ready output" in {
- assert(dut.io.in.valid.dir === INPUT)
- assert(dut.io.in.ready.dir === OUTPUT)
- }
- "EnqIO" should "set the direction of it's parameter OUTPUT" in {
- assert(dut.io.out.bits.info_data.dir === OUTPUT)
- }
- "EnqIO" should "create a valid input and ready output" in {
- assert(dut.io.out.valid.dir === OUTPUT)
- assert(dut.io.out.ready.dir === INPUT)
- }
-
- val in_clone = dut.io.in.cloneType
- val out_clone = dut.io.out.cloneType
-
- "A deqIO device" should "clone itself with it's directions intact" in {
- assert(dut.io.in.bits.info_data.dir == in_clone.bits.info_data.dir)
- assert(dut.io.in.ready.dir == in_clone.ready.dir)
- assert(dut.io.in.valid.dir == in_clone.valid.dir)
- }
+ new FinishTester {
+ val dut = new DummyCircuit
- "A enqIO device" should "clone itself with it's directions intact" in {
- assert(dut.io.out.bits.info_data.dir == out_clone.bits.info_data.dir)
- assert(dut.io.out.ready.dir == out_clone.ready.dir)
- assert(dut.io.out.valid.dir == out_clone.valid.dir)
+ "Extending BasicTester" should "allow developer to have finish method run automatically" in {
+ assert(finish_was_run)
}
}
}
diff --git a/src/test/scala/chiselTests/TesterDriverSpec.scala b/src/test/scala/chiselTests/TesterDriverSpec.scala
new file mode 100644
index 00000000..ea1692f9
--- /dev/null
+++ b/src/test/scala/chiselTests/TesterDriverSpec.scala
@@ -0,0 +1,10 @@
+// See LICENSE for license details.
+
+package chiselTests
+
+/**
+ * Created by chick on 2/9/16.
+ */
+class TesterDriverSpec {
+
+}