繁体   English   中英

运行特定的测试,并基于凿模板从凿项目中获取Verilog

[英]Running specific tests and getting Verilog from a Chisel project based on the chisel-template

在将我的鼻子大量塞进那里的其他凿子中之后,我决定是时候尝试我自己的东西了。 出乎意料的是,这个东西很简单,但是我基于凿子模板制作的东西仍然可以成功工作。

我什至通过运行最简单的测试来确认这一点。 它是一个虚拟的32位ALU,其中包含(暂时)打算用于按位操作的子模块。 我是在现有GCD测试之后编写测试的,所以我的测试文件Alu32UnitTest.scala包含以下重要行:

package alu32
import chisel3.iotesters
import chisel3.iotesters.{PeekPokeTester,Driver,ChiselFlatSpec}
class Alu32BoolTests(dut: Alu32) extends PeekPokeTester(dut) {
    for (i <- 0 until 9) {
        //first provide random values
        val a = rnd.nextInt(256)
        val b = rnd.nextInt(256)
        val f = rnd.nextInt(16)

        //decide what to expect based on opcode
        var output = 0
        if (f == 8) {
            output = a & b
        } else if (f == 14) {
            output = a | b
        } else if (f == 6) {
            output = a ^ b
        } else output = 0

        //connect the generated inputs to dut
        poke(dut.io.a, a)
        poke(dut.io.b, b)
        poke(dut.io.f, f)

        //clock
        step(1)

        //check if everything is where it should be
        expect(dut.io.y, output)
    }
}
}

class Alu32UnitTester extends ChiselFlatSpec {
    behavior of "Alu32"
    backends foreach {backend =>
    it should s"perform correct math operation on dynamic operand in $backend" 
    in {
      Driver(() => new Alu32, backend)((dut) => new Alu32BoolTests(dut)) should be (true)
    }
  }
}

我使用(运行sbt )运行此测试:

> testOnly alu32.AluUnitTester

当它很好时,它正确地说SUCCESS ,而当我改变ALU的内部时它抱怨。 我来到了testOnly行,仅查看凿模板的自述文件,然后在testtestOnly等之后按[Tab]。

我想做的下一件事是获取Verilog代码,因此我尝试运行chisel-tutorial中提供的命令,我的意思是包括run-main在内的命令。 当然,这会导致错误,因为我意识到,在Alu32UnitTest.scala中未定义此类测试,因此我尝试改编GCD中找到的行,这导致我注意到test / scala中的另一个文件GCDMain.scala 因此,我继续将其修改为:

package alu32

import chisel3._

object Alu32Main extends App {
  iotesters.Driver.execute(args, () => new Alu32) {
    dut => new Alu32UnitTester(dut)
  }
}

object Alu32Repl extends App {
  iotesters.Driver.executeFirrtlRepl(args, () => new Alu32)
}

并将其称为Alu32Main.scala 创建了那个,现在什么都不起作用了:)

当我尝试有效的方法时:

> testOnly alu32.AluUnitTester

我现在得到以下响应:

[info] Compiling 1 Scala source to /home/apaj/ChiselProjects/alu32/target/scala-2.11/classes...
[warn] there were 8 feature warnings; re-run with -feature for details
[warn] one warning found
[info] Compiling 1 Scala source to /home/apaj/ChiselProjects/alu32/target/scala-2.11/test-classes...
[error] /home/apaj/ChiselProjects/alu32/src/test/scala/alu32/alu32Main.scala:7: too many arguments for constructor Alu32UnitTester: ()alu32.Alu32UnitTester
[error]     dut => new Alu32UnitTester(dut)
[error]            ^
[error] one error found
[error] (test:compileIncremental) Compilation failed
[error] Total time: 10 s, completed Jan 15, 2018 5:16:12 PM

我注意到它如何抱怨太多争论。 但是,如果删除了参数dut ,则它抱怨类型不匹配。

有一次,我不知该如何重构,我确实得到了与该问题类似的回答 ,但我真的不记得如何。

我确信这是一个初学者的问题,可以忽略一些可能很明显的问题,所以我希望您能找到时间并提供帮助。

非常感谢。

我认为问题在于您是要引用PeekPokeTester实现类Alu32BoolTests(dut:Alu32),而不是Scala测试工具类Alu32UnitTester
具体而言,第7行应为

dut => new Alu32BoolTests(dut)

并不是

dut => new Alu32UnitTester(dut)

这只是为了完整性,主要问题已由Chick Marley的答案解决。 但是,由于问题的第二部分是有关获取Verilog的,因此需要在alu32UnitTests.scala添加以下alu32UnitTests.scala

class Alu32Tester extends ChiselFlatSpec {
  private val backendNames = if(firrtl.FileUtils.isCommandAvailable("verilator")) {
    Array("firrtl", "verilator")
  }
  else {
    Array("firrtl")
  }
  for ( backendName <- backendNames ) {
    "Alu32" should s"calculate proper greatest common denominator (with $backendName)" in {
      Driver(() => new Alu32, backendName) {
        c => new Alu32BoolTests(c)
      } should be (true)
    }
  }

  "Basic test using Driver.execute" should "be used as an alternative way to run specification" in {
    iotesters.Driver.execute(Array(), () => new Alu32) {
      c => new Alu32BoolTests(c)
    } should be (true)
  }

  "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 Alu32) {
        c => new Alu32BoolTests(c)
      } should be(true)
    }
  }

  "running with --is-verbose" should "show more about what's going on in your tester" in {
    iotesters.Driver.execute(Array("--is-verbose"), () => new Alu32) {
      c => new Alu32BoolTests(c)
    } should be(true)
  }

  "running with --fint-write-vcd" should "create a vcd file from your test" in {
    iotesters.Driver.execute(Array("--fint-write-vcd"), () => new Alu32) {
      c => new Alu32BoolTests(c)
    } should be(true)
  }

  "using --help" should s"show the many options available" in {
    iotesters.Driver.execute(Array("--help"), () => new Alu32) {
      c => new Alu32BoolTests(c)
    } should be (true)
  }
}

保存并编译后,将按以下方式获取Verilog:

test:runMain alu32.Alu32Main --backend-name=verilator

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM