summaryrefslogtreecommitdiff
path: root/integration-tests/src/test/scala/chiselTests/util/experimental/DecoderSpec.scala
blob: c75113f6835b66e625f32f984fc93a2cea0318af (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
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: Apache-2.0

package chiselTests.util.experimental

import chisel3.util.experimental.decode.{DecodeTableAnnotation, Minimizer, QMCMinimizer, TruthTable}
import chiselTests.util.experimental.minimizer.DecodeTestModule
import firrtl.annotations.ReferenceTarget
import org.scalatest.flatspec.AnyFlatSpec
import chiseltest._
import chiseltest.formal._

class DecoderSpec extends AnyFlatSpec with ChiselScalatestTester with Formal {
  val xor = TruthTable.fromString("""10->1
                                    |01->1
                                    |    0""".stripMargin)

  def minimizer: Minimizer = QMCMinimizer

  "decoder" should "pass without DecodeTableAnnotation" in {
    verify(new DecodeTestModule(minimizer, table = xor), Seq(BoundedCheck(1)))
  }

  "decoder" should "fail with a incorrect DecodeTableAnnotation" in {
    val annos = Seq(
      DecodeTableAnnotation(
        ReferenceTarget("", "", Nil, "", Nil),
        """10->1
          |01->1
          |    0""".stripMargin,
        """10->1
          |    0""".stripMargin
      )
    )
    assertThrows[FailedBoundedCheckException] {
      verify(new DecodeTestModule(minimizer, table = xor), BoundedCheck(1) +: annos)
    }
  }

  "decoder" should "success with a correct DecodeTableAnnotation" in {
    val annos = Seq(
      DecodeTableAnnotation(
        ReferenceTarget("", "", Nil, "", Nil),
        """10->1
          |01->1
          |    0""".stripMargin,
        QMCMinimizer
          .minimize(TruthTable.fromString("""10->1
                                            |01->1
                                            |    0""".stripMargin))
          .toString
      )
    )
    verify(new DecodeTestModule(minimizer, table = xor), BoundedCheck(1) +: annos)
  }
}