2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.unittest
|
2016-07-14 21:18:11 +02:00
|
|
|
|
|
|
|
import Chisel._
|
2017-09-14 03:06:03 +02:00
|
|
|
import chisel3.experimental.MultiIOModule
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.config._
|
|
|
|
import freechips.rocketchip.util.SimpleTimer
|
2016-07-14 21:18:11 +02:00
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
trait UnitTestIO {
|
|
|
|
val finished = Bool(OUTPUT)
|
|
|
|
val start = Bool(INPUT)
|
|
|
|
}
|
|
|
|
|
2016-09-10 02:16:35 +02:00
|
|
|
trait HasUnitTestIO {
|
2017-09-14 03:06:03 +02:00
|
|
|
val io: UnitTestIO
|
|
|
|
}
|
|
|
|
|
|
|
|
trait UnitTestLegacyModule extends HasUnitTestIO {
|
|
|
|
val io = new Bundle with UnitTestIO
|
|
|
|
}
|
|
|
|
|
|
|
|
trait UnitTestModule extends MultiIOModule with HasUnitTestIO {
|
|
|
|
val io = IO(new Bundle with UnitTestIO)
|
2016-09-10 02:16:35 +02:00
|
|
|
}
|
2016-07-16 00:40:11 +02:00
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
abstract class UnitTest(val timeout: Int = 4096) extends Module with UnitTestLegacyModule {
|
2016-09-21 22:05:22 +02:00
|
|
|
val testName = this.getClass.getSimpleName
|
|
|
|
|
|
|
|
when (io.start) { printf(s"Started UnitTest $testName\n") }
|
|
|
|
|
|
|
|
val timed_out = SimpleTimer(timeout, io.start, io.finished)
|
|
|
|
assert(!timed_out, s"UnitTest $testName timed out")
|
2016-07-14 21:18:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-14 21:28:20 +02:00
|
|
|
case object UnitTests extends Field[Parameters => Seq[UnitTest]]
|
|
|
|
|
2016-08-02 01:05:24 +02:00
|
|
|
class UnitTestSuite(implicit p: Parameters) extends Module {
|
|
|
|
val io = new Bundle {
|
|
|
|
val finished = Bool(OUTPUT)
|
|
|
|
}
|
|
|
|
|
2016-07-14 21:28:20 +02:00
|
|
|
val tests = p(UnitTests)(p)
|
2016-07-14 21:18:11 +02:00
|
|
|
|
2016-09-21 22:05:22 +02:00
|
|
|
val s_idle :: s_start :: s_busy :: s_done :: Nil = Enum(Bits(), 4)
|
2016-07-14 21:18:11 +02:00
|
|
|
val state = Reg(init = s_idle)
|
2016-09-21 22:05:22 +02:00
|
|
|
val tests_finished = Vec(tests.map(_.io.finished)).reduce(_&&_)
|
2016-07-14 21:18:11 +02:00
|
|
|
|
2016-09-21 22:05:22 +02:00
|
|
|
tests.foreach { _.io.start := (state === s_start) }
|
2016-08-02 01:05:24 +02:00
|
|
|
io.finished := (state === s_done)
|
|
|
|
|
2016-09-21 22:05:22 +02:00
|
|
|
when (state === s_idle) { state := s_start }
|
|
|
|
when (state === s_start) { state := s_busy }
|
|
|
|
when (state === s_busy && tests_finished) { state := s_done }
|
2016-08-02 01:05:24 +02:00
|
|
|
}
|