chipsalliance / chisel-template

A template project for beginning new Chisel work
The Unlicense
574 stars 181 forks source link

How to infer a parametrized top module #49

Closed tampler closed 5 years ago

tampler commented 5 years ago

Hello I'm trying to run a test for a parametrized top with the following:

testOnly my_pkg.DspTester -- -z verilator

This works fine for a non-parametrized top, like

class DspTop(dwin:Int, dwout:Int) extends Module {...}

Buf fails for

class DspTop[A <: Data, B <: Data](inType:A, outType:B) extends Module {...}

giving: No tests to run for Test / testOnly

My tester is

object MaccMain extends App with Params {

  val inType  = UInt(dwin.W)
  val outType = UInt(dwout.W)
  //val inType  = FixedPoint(16.W, 10.BP)
  //val outType = FixedPoint(32.W, 20.BP)

  //iotesters.Driver.execute (args, () => new Macc(dwin, dwout)){
  //  c => new MaccUnitTest(c)
  //}
  iotesters.Driver.executeFirrtlRepl(args, () => new DspTop(inType, outType)) 
}

Using Chisel3 and FIRRTL from master and Chisel-Template with changes to the latest Scala and Chisel

PS: Using Chisel-Template only, NOT DspTools

edwardcwang commented 5 years ago

Can you share the definition of DspTester?

tampler commented 5 years ago

My DSP Module definition is the following:

class Grid[A <: Data, B <: Data] (inType:A, outType:B, xlen:Int = 1, ylen:Int = 1) 
extends Module with Common { ... }

Here's my GridTest.scala

package my_pkg

import chisel3._
import chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
import Cfg._

// Unit Tester
class GridUnitTest [A <: Data, B <: Data](inType:A, outType:B)(c: Grid[A,B]) 
extends PeekPokeTester(c) {...}

// Top Tester
class GridTester[A <: Data, B <: Data] (inType:A, outType:B) extends ChiselFlatSpec {
  private val backendNames = Array("verilator")

  "using --backend-name verilator" should "be an alternative way to run using verilator" in {
    if(backendNames.contains("verilator")) {
      iotesters.Driver.execute(Array("--backend-name", "verilator"), () => new Grid(inType, outType)) {
        c => new GridUnitTest(inType, outType)(c)
      } should be(true)
    }
  }
}

// Top app
object GridMain extends App {
  //iotesters.Driver.execute (args, () => new Grid(inType, outType)){
  //  c => new GridUnitTest(inType, outType)(c)
  //}
  iotesters.Driver.executeFirrtlRepl(args, () => new Grid(inType, outType)) 
}

If I remove parametrization, the test runs seamlessly. If I run this code, I get "No tests were executed" Any ideas ?

edwardcwang commented 5 years ago

I'm not sure it's possible for ScalaTest classes to take parameters like (inType:A, outType:B).

You could try something like https://stackoverflow.com/questions/35433177/passing-additional-arguments-to-tests-with-scalatest to pass arguments from the command line if need be.

tampler commented 5 years ago

DspTools tester allows this kind of parametrization. I used it successfully in past. However, I'd like to avoid using DspTools in my project due to a poor tech support and a cumbersome student implementation.

Maybe should lift few constructs from there thou

tampler commented 5 years ago

Solved by adding a non-parametrized wrapper to my top.

It looks like chisel-testers currently doesn't support this feature. DspTester supports.