summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests
diff options
context:
space:
mode:
authorJack Koenig2016-03-20 12:03:02 -0700
committerJack Koenig2016-03-20 12:03:02 -0700
commit28ebd2009f5d37aa0302508d1ce71156cc49a807 (patch)
tree2355641a4d220a9e153bcfe8ba9f002dfc85b704 /src/test/scala/chiselTests
parente7594b79fa1979ca65da15aea0834660292ee378 (diff)
parent7602c999b7c05d290e858bc5a355db9300928070 (diff)
Merge pull request #124 from ucb-bar/fix-assert
Fix assert
Diffstat (limited to 'src/test/scala/chiselTests')
-rw-r--r--src/test/scala/chiselTests/Assert.scala34
-rw-r--r--src/test/scala/chiselTests/Harness.scala23
2 files changed, 43 insertions, 14 deletions
diff --git a/src/test/scala/chiselTests/Assert.scala b/src/test/scala/chiselTests/Assert.scala
index 54ebf366..24eb8b55 100644
--- a/src/test/scala/chiselTests/Assert.scala
+++ b/src/test/scala/chiselTests/Assert.scala
@@ -8,12 +8,39 @@ import Chisel.testers.BasicTester
class FailingAssertTester() extends BasicTester {
assert(Bool(false))
- stop()
+ // Wait to come out of reset
+ val (_, done) = Counter(!reset, 4)
+ when (done) {
+ stop()
+ }
}
class SucceedingAssertTester() extends BasicTester {
assert(Bool(true))
- stop()
+ // Wait to come out of reset
+ val (_, done) = Counter(!reset, 4)
+ when (done) {
+ stop()
+ }
+}
+
+class PipelinedResetModule extends Module {
+ val io = new Bundle { }
+ val a = Reg(init = UInt(0xbeef))
+ val b = Reg(init = UInt(0xbeef))
+ assert(a === b)
+}
+
+// This relies on reset being asserted for 3 or more cycles
+class PipelinedResetTester extends BasicTester {
+ val module = Module(new PipelinedResetModule)
+
+ module.reset := Reg(next = Reg(next = Reg(next = reset)))
+
+ val (_, done) = Counter(!reset, 4)
+ when (done) {
+ stop()
+ }
}
class AssertSpec extends ChiselFlatSpec {
@@ -23,4 +50,7 @@ class AssertSpec extends ChiselFlatSpec {
"A succeeding assertion" should "not fail the testbench" in {
assertTesterPasses{ new SucceedingAssertTester }
}
+ "An assertion" should "not assert until we come out of reset" in {
+ assertTesterPasses{ new PipelinedResetTester }
+ }
}
diff --git a/src/test/scala/chiselTests/Harness.scala b/src/test/scala/chiselTests/Harness.scala
index 1a628e6c..b06f4572 100644
--- a/src/test/scala/chiselTests/Harness.scala
+++ b/src/test/scala/chiselTests/Harness.scala
@@ -50,30 +50,29 @@ int main(int argc, char **argv, char **env) {
def simpleHarnessBackend(make: File => File): (File, String) = {
val target = "test"
val path = createTempDirectory(target)
- val fname = File.createTempFile(target, "", path)
- val prefix = fname.toString.split("/").last
+ val fname = new File(path, target)
val cppHarness = makeCppHarness(fname)
make(fname)
- verilogToCpp(prefix, path, Seq(), cppHarness).!
- cppToExe(prefix, path).!
- (path, prefix)
+ verilogToCpp(target, path, Seq(), cppHarness).!
+ cppToExe(target, path).!
+ (path, target)
}
property("Test making trivial verilog harness and executing") {
- val (path, prefix) = simpleHarnessBackend(makeTrivialVerilog)
+ val (path, target) = simpleHarnessBackend(makeTrivialVerilog)
- assert(executeExpectingSuccess(prefix, path))
+ assert(executeExpectingSuccess(target, path))
}
property("Test that assertion failues in Verilog are caught") {
- val (path, prefix) = simpleHarnessBackend(makeFailingVerilog)
+ val (path, target) = simpleHarnessBackend(makeFailingVerilog)
- assert(!executeExpectingSuccess(prefix, path))
- assert(executeExpectingFailure(prefix, path))
- assert(executeExpectingFailure(prefix, path, "My specific, expected error message!"))
- assert(!executeExpectingFailure(prefix, path, "A string that doesn't match any test output"))
+ assert(!executeExpectingSuccess(target, path))
+ assert(executeExpectingFailure(target, path))
+ assert(executeExpectingFailure(target, path, "My specific, expected error message!"))
+ assert(!executeExpectingFailure(target, path, "A string that doesn't match any test output"))
}
}