DataWidthConverterSpec.scala 1.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
package chisel.miscutils.datawidthconverter
import  chisel.miscutils._
import  chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
import  org.scalacheck._, org.scalacheck.Prop._
import  org.scalatest.prop.Checkers
import  generators._

class DataWidthConverterSpec extends ChiselFlatSpec with Checkers {
  behavior of "DataWidthConverter"

  it should "preserve data integrity in arbitrary conversions" in
12
    check(forAll(bitWidthGen(64), Arbitrary.arbitrary[Boolean], genLimited(1, 15)) {
13
14
15
16
17
      case (inW, littleEndian, delay) =>
        forAll(conversionWidthGen(inW)) { outW =>
          println("Testing bitwidth conversion from %d bits -> %d bits (%s) with %d delay"
            .format(inW:Int, outW:Int, if (littleEndian) "little-endian" else "big-endian", delay:Int))
          Driver.execute(Array("--fint-write-vcd", "--target-dir", "test/DataWidthConverter"),
18
              () => new CorrectnessHarness(inW, outW, littleEndian, 1))
19
20
            { m => new CorrectnessTester(m) }
        }
21
      }, minSuccessful(25))
22
23
24
25
26
27
28
29
30
31
32
33

  it should "transfer data with minimal delays" in
    check(forAll(bitWidthGen(64), Arbitrary.arbitrary[Boolean]) { case (inW, littleEndian) =>
      forAll(conversionWidthGen(inW)) { outW =>
        println("Testing bitwidth conversion from %d bits -> %d bits (%s)"
          .format(inW:Int, outW:Int, if (littleEndian) "little-endian" else "big-endian"))
        Driver.execute(Array("--fint-write-vcd", "--target-dir", "test/DataWidthConverter"),
            () => new MinimalDelayHarness(inW, outW, littleEndian))
          { m => new MinimalDelayTester(m) }
      }
    })
}