summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/testers/BasicTester.scala
blob: 4cd03863934e3fb9b8a8ed3d4d371e8ea55e09fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// See LICENSE for license details.

package chisel3.testers
import chisel3._

import scala.language.experimental.macros

import internal._
import internal.Builder.pushCommand
import internal.firrtl._
import internal.sourceinfo.SourceInfo
//import chisel3.core.ExplicitCompileOptions.NotStrict

class TesterIO extends Bundle {
  // The testbench has no IOs, rather it should communicate using printf, assert, and stop.
  // This is here (instead of just `new Bundle()`, since that has an implicit compileOptions
  // constructor argument which is misapplied by clonetype
}

class BasicTester extends Module() {
  val io = IO(new TesterIO)

  def popCount(n: Long): Int = n.toBinaryString.count(_=='1')

  /** Ends the test reporting success.
    *
    * Does not fire when in reset (defined as the encapsulating Module's
    * reset). If your definition of reset is not the encapsulating Module's
    * reset, you will need to gate this externally.
    */
  def stop()(implicit sourceInfo: SourceInfo) {
    // TODO: rewrite this using library-style SourceInfo passing.
    when (!reset.toBool) {
      pushCommand(Stop(sourceInfo, Node(clock), 0))
    }
  }

  /** The finish method provides a hook that subclasses of BasicTester can use to
    * alter a circuit after their constructor has been called.
    * For example, a specialized tester subclassing BasicTester could override finish in order to
    * add flow control logic for a decoupled io port of a device under test
    */
  def finish(): Unit = {}
}