summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/TesterDriverSpec.scala
blob: 7c571837fa53b7d2d7d782b31cdea0086257fcdf (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
45
// See LICENSE for license details.

package chiselTests

import chisel3._
import chisel3.testers.BasicTester
import chisel3.util._

/** Extend BasicTester with a simple circuit and finish method.  TesterDriver will call the
  * finish method after the FinishTester's constructor has completed, which will alter the
  * circuit after the constructor has finished.
  */
class FinishTester extends BasicTester {
  val test_wire_width = 2
  val test_wire_override_value = 3

  val counter = Counter(1)

  when(counter.inc()) {
    stop()
  }

  val test_wire = WireDefault(1.U(test_wire_width.W))

  // though we just set test_wire to 1, the assert below will pass because
  // the finish will change its value
  assert(test_wire === test_wire_override_value.asUInt)

  /** In finish we use last connect semantics to alter the test_wire in the circuit
    * with a new value
    */
  override def finish(): Unit = {
    test_wire := test_wire_override_value.asUInt
  }
}

class TesterDriverSpec extends ChiselFlatSpec {
  "TesterDriver calls BasicTester's finish method which" should
    "allow modifications of test circuit after the tester's constructor is done" in {
    assertTesterPasses {
      new FinishTester
    }
  }
}