summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/ParameterizedModule.scala
blob: 3016728d0defc2d25cc520fe0481025d04a02ec5 (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
// SPDX-License-Identifier: Apache-2.0

package chiselTests

import chisel3._
import chisel3.testers.BasicTester

class ParameterizedModule(invert: Boolean) extends Module {
  val io = IO(new Bundle {
    val in  = Input(Bool())
    val out = Output(Bool())
  })
  if (invert) {
    io.out := !io.in
  } else {
    io.out := io.in
  }
}

/** A simple test to check Module deduplication doesn't affect correctness (two
  * modules with the same name but different contents aren't aliased). Doesn't
  * check that deduplication actually happens, though.
  */
class ParameterizedModuleTester() extends BasicTester {
  val invert = Module(new ParameterizedModule(true))
  val noninvert = Module(new ParameterizedModule(false))

  invert.io.in := true.B
  noninvert.io.in := true.B
  assert(invert.io.out === false.B)
  assert(noninvert.io.out === true.B)

  stop()
}

class ParameterizedModuleSpec extends ChiselFlatSpec {
  "Different parameterized modules" should "have different behavior" in {
    assertTesterPasses(new ParameterizedModuleTester())
  }
}