2016-08-02 01:05:24 +02:00
|
|
|
package junctions.unittests
|
2016-07-14 21:18:11 +02:00
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import junctions._
|
2016-07-14 21:28:20 +02:00
|
|
|
import cde.{Field, Parameters}
|
2016-07-14 21:18:11 +02:00
|
|
|
|
2016-09-10 02:16:35 +02:00
|
|
|
trait HasUnitTestIO {
|
2016-07-14 21:18:11 +02:00
|
|
|
val io = new Bundle {
|
|
|
|
val finished = Bool(OUTPUT)
|
|
|
|
val start = Bool(INPUT)
|
|
|
|
}
|
2016-09-10 02:16:35 +02:00
|
|
|
}
|
2016-07-16 00:40:11 +02:00
|
|
|
|
2016-09-10 02:16:35 +02:00
|
|
|
abstract class UnitTest extends Module with HasUnitTestIO {
|
2016-07-16 00:40:11 +02:00
|
|
|
when (io.start) {
|
2016-07-19 23:42:58 +02:00
|
|
|
printf(s"Started UnitTest ${this.getClass.getSimpleName}\n")
|
2016-07-16 00:40:11 +02:00
|
|
|
}
|
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-07-16 00:40:11 +02:00
|
|
|
val s_idle :: s_start :: s_wait :: s_done :: Nil = Enum(Bits(), 4)
|
2016-07-14 21:18:11 +02:00
|
|
|
val state = Reg(init = s_idle)
|
2016-07-16 00:40:11 +02:00
|
|
|
val test_idx = Reg(init = UInt(0, log2Up(tests.size)))
|
|
|
|
val test_finished = Vec(tests.map(_.io.finished))
|
2016-07-14 21:18:11 +02:00
|
|
|
|
|
|
|
when (state === s_idle) { state := s_start }
|
|
|
|
when (state === s_start) { state := s_wait }
|
2016-07-16 00:40:11 +02:00
|
|
|
when (state === s_wait && test_finished(test_idx)) {
|
|
|
|
state := s_start
|
|
|
|
test_idx := test_idx + UInt(1)
|
|
|
|
state := Mux(test_idx === UInt(tests.size - 1), s_done, s_start)
|
|
|
|
}
|
2016-07-14 21:18:11 +02:00
|
|
|
|
2016-09-13 03:39:50 +02:00
|
|
|
val timer = Module(new Timer(50000, tests.size))
|
2016-08-10 20:23:07 +02:00
|
|
|
timer.io.start.valid := Bool(false)
|
|
|
|
timer.io.stop.valid := Bool(false)
|
2016-08-02 01:05:24 +02:00
|
|
|
|
2016-07-14 21:18:11 +02:00
|
|
|
tests.zipWithIndex.foreach { case (mod, i) =>
|
2016-07-16 00:40:11 +02:00
|
|
|
mod.io.start := (state === s_start) && test_idx === UInt(i)
|
2016-08-02 01:05:24 +02:00
|
|
|
when (test_idx === UInt(i)) {
|
|
|
|
timer.io.start.valid := mod.io.start
|
|
|
|
timer.io.start.bits := UInt(i)
|
|
|
|
timer.io.stop.valid := mod.io.finished
|
|
|
|
timer.io.stop.bits := UInt(i)
|
2016-07-14 21:18:11 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-02 01:05:24 +02:00
|
|
|
io.finished := (state === s_done)
|
|
|
|
|
|
|
|
assert(!timer.io.timeout.valid, "UnitTest timed out")
|
|
|
|
}
|
2016-07-16 00:40:11 +02:00
|
|
|
|
2016-08-02 01:05:24 +02:00
|
|
|
object JunctionsUnitTests {
|
|
|
|
def apply(implicit p: Parameters): Seq[UnitTest] =
|
|
|
|
Seq(
|
|
|
|
Module(new MultiWidthFifoTest),
|
|
|
|
Module(new NastiMemoryDemuxTest),
|
|
|
|
Module(new HastiTest))
|
2016-07-14 21:18:11 +02:00
|
|
|
}
|