summaryrefslogtreecommitdiff
path: root/src/main/scala/Chisel/Tester.scala
diff options
context:
space:
mode:
authorHenry Cook2015-08-05 00:54:32 -0700
committerAndrew Waterman2015-08-05 16:36:08 -0700
commitf98e9e4143a113ac1020ed20c5e01b41aa29efe5 (patch)
tree89fa57975e1f137ee184aafdc7a0a81ec09aa994 /src/main/scala/Chisel/Tester.scala
parenta02d788d9e9c4b42fd866e5c34e42aa771aab68c (diff)
Massive Driver simplification, some tweaks to Parameter api
Diffstat (limited to 'src/main/scala/Chisel/Tester.scala')
-rw-r--r--src/main/scala/Chisel/Tester.scala71
1 files changed, 37 insertions, 34 deletions
diff --git a/src/main/scala/Chisel/Tester.scala b/src/main/scala/Chisel/Tester.scala
index 8f013f7b..9c6f51d0 100644
--- a/src/main/scala/Chisel/Tester.scala
+++ b/src/main/scala/Chisel/Tester.scala
@@ -28,7 +28,7 @@
MODIFICATIONS.
*/
-package Chisel
+package Chisel.testers
import Chisel._
import scala.math._
import scala.collection.mutable.ArrayBuffer
@@ -43,6 +43,36 @@ import scala.sys.process._
import scala.io.Source._
import Literal._
+object TesterDriver extends FileSystemUtilities {
+ // Setting this to TRUE will initialize the tester's RNG with the
+ // seed below.
+ // case "--testerSeed" => {
+ // testerSeedValid = true
+ // testerSeed = args(i+1).toLong }
+ var testerSeedValid = false
+ var testerSeed = System.currentTimeMillis()
+
+ // Setting this to TRUE will case the test harness to print its
+ // standard input stream to a file.
+ var dumpTestInput = false
+
+ private def test[T <: Module](mod: T, ftester: T => Tester[T]): Unit = {
+ // We shouldn't have to do this. There should be a class of Builder that doesn't pushCommand.
+ Builder.pushCommands
+ var res = false
+ var tester: Tester[T] = null
+ try {
+ tester = ftester(mod)
+ } finally {
+ if (tester != null && tester.process != null)
+ res = tester.finish()
+ }
+ println(if (res) "PASSED" else "*** FAILED ***")
+ if(!res) throwException("Module under test FAILED at least one test vector.")
+ }
+
+}
+
case class Poke(val node: Data, val index: Int, val value: BigInt);
class Snapshot(val t: Int) {
@@ -50,7 +80,7 @@ class Snapshot(val t: Int) {
}
class ManualTester[+T <: Module]
- (val c: T, val isT: Boolean = true, val skipVPDMessage: Boolean = true) {
+ (val name: String, val isT: Boolean = true, val skipVPDMessage: Boolean = true) {
var testIn: InputStream = null
var testOut: OutputStream = null
var testErr: InputStream = null
@@ -73,17 +103,6 @@ class ManualTester[+T <: Module]
}
}
- // TODO: MOVE TO SOMEWHERE COMMON TO BACKEND
- def ensureDir(dir: String): String = {
- val d = dir + (if (dir == "" || dir(dir.length-1) == '/') "" else "/")
- new File(d).mkdirs()
- d
- }
- def createOutputFile(name: String): java.io.FileWriter = {
- val baseDir = ensureDir(Driver.targetDir)
- new java.io.FileWriter(baseDir + name)
- }
-
def puts(str: String) = {
while (testOut == null) { Thread.sleep(100) }
for (e <- str) testOut.write(e);
@@ -152,20 +171,6 @@ class ManualTester[+T <: Module]
return sb.toString
}
- /*
- def setClocks(clocks: HashMap[Clock, Int]) {
- var cmd = "set_clocks"
- for (clock <- Driver.clocks) {
- if (clock.srcClock == null) {
- val s = BigInt(clocks(clock)).toString(16)
- cmd = cmd + " " + s
- }
- }
- emulatorCmd(cmd)
- // TODO: check for errors in return
- }
- */
-
def doPeekBits(name: String, off: Int = -1): BigInt = {
if (name == "") {
println("Unable to peek data " + name) // TODO: USE DATA
@@ -353,16 +358,14 @@ class ManualTester[+T <: Module]
"EXPECT " + data.debugName + " <- " + gotFLoat + " == " + expectedFloat)
}
- val rnd = if (Driver.testerSeedValid) new Random(Driver.testerSeed) else new Random()
+ val rnd = if (TesterDriver.testerSeedValid) new Random(TesterDriver.testerSeed) else new Random()
var process: Process = null
def start(): Process = {
- val n = Driver.appendString(Some(c.name),Driver.chiselConfigClassName)
- val target = "cd " + Driver.targetDir + " && ./" + n
- val cmd = target
+ val cmd = "./" + name
println("RUNNING " + cmd)
- println("SEED " + Driver.testerSeed)
- println("STARTING " + n)
+ println("SEED " + TesterDriver.testerSeed)
+ println("STARTING " + name)
val processBuilder = Process(Seq("bash", "-c", cmd))
val pio = new ProcessIO(in => testOut = in, out => testIn = out, err => testErr = err)
process = processBuilder.run(pio)
@@ -399,7 +402,7 @@ class ManualTester[+T <: Module]
}
}
-class Tester[+T <: Module](c: T, isTrace: Boolean = true, skipVPDMessage: Boolean = false) extends ManualTester(c, isTrace, skipVPDMessage) {
+class Tester[+T <: Module](c: T, isTrace: Boolean = true, skipVPDMessage: Boolean = false) extends ManualTester(c.name, isTrace, skipVPDMessage) {
start()
}