DataWidthConverterSpec.scala 1.64 KB
Newer Older
1
2
3
4
5
6
7
8
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 {
Jens Korinth's avatar
Jens Korinth committed
9
  implicit val logLevel = Logging.Level.Warn
10
11
12
  behavior of "DataWidthConverter"

  it should "preserve data integrity in arbitrary conversions" in
13
    check(forAll(bitWidthGen(64), Arbitrary.arbitrary[Boolean], genLimited(1, 15)) {
14
15
16
17
18
      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"),
19
              () => new CorrectnessHarness(inW, outW, littleEndian, 1))
20
21
            { m => new CorrectnessTester(m) }
        }
22
      }, minSuccessful(15))
23
24
25
26
27
28
29
30
31
32

  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) }
      }
33
    }, minSuccessful(15))
34
}