選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

75 行
2.1KB

  1. package Core
  2. import chisel3._
  3. import chisel3.iotesters._
  4. import org.scalatest.{Matchers, FlatSpec}
  5. object testUtils {
  6. /**
  7. Somewhat unintuitively named, a cycle task is a list test tasks at some time step.
  8. In order to not have to supply a list the scala varargs syntax (*) is used.
  9. As an example, at step 13 we want to input a value to a signal in: (PeekPokeTester[T] => Unit)
  10. and check an output out: ((PeekPokeTester[T] => Unit) with the possibility of test failure exception)
  11. Thanks to varargs syntax this would be
  12. CycleTask[MyModule](13, in, out)
  13. Sometimes it is convenient to delay a bunch of checks by some set amount of cycles.
  14. For instance, assume a component needs 10 cycles to set up, but it's more convenient
  15. to write tests from T = 0, we do that and then call .delay(10) to ensure the T0 for the
  16. tasks is actually T = 10
  17. */
  18. case class CycleTask[T <: Module](step: Int, run: PeekPokeTester[T] => Unit*){
  19. // :_* is necessary for calling var args with explicit list
  20. def delay(by: Int) = CycleTask[T](step + by, run:_*)
  21. }
  22. /**
  23. Takes in a list of cycle tasks, sorts them by timestep to execute and runs until all cycletasks are done
  24. */
  25. case class IoSpec[T <: Module](
  26. instructions: Seq[CycleTask[T]],
  27. component: T
  28. ){
  29. val lastStep = instructions.maxBy(_.step).step
  30. val instructionsMap = instructions.groupBy(_.step)
  31. class tester(c: T) extends PeekPokeTester(c)
  32. val myTester: PeekPokeTester[T] = new tester(component) {
  33. for(ii <- 0 to lastStep){
  34. instructionsMap.getOrElse(ii, Nil).foreach(_.run.foreach(t => t(this)))
  35. step(1)
  36. }
  37. }
  38. }
  39. }
  40. class testUtilSpec extends FlatSpec with Matchers {
  41. import testUtils._
  42. val ins = List[CycleTask[daisyVector]](
  43. CycleTask(
  44. 1,
  45. d => d.poke(d.dut.io.dataIn, 1),
  46. d => d.expect(d.dut.io.dataOut, 0, s"fail at step ${d.t}")
  47. )
  48. )
  49. behavior of "my simple test harness attempt"
  50. it should "not NPE" in {
  51. iotesters.Driver.execute(() => new daisyVector(4, 32), new TesterOptionsManager) { c =>
  52. val myTest = IoSpec[daisyVector](ins, c)
  53. myTest.myTester
  54. } should be(true)
  55. }
  56. }