类似junit的chisel中的iotesters
下面的chisel测试实验类似java中的junit,Adder.scala和FullAdder.scala源码来自https://gitee.com/whoisliang中的chisel-tutorial。项目中的build.sbt内容如下:name := "AdderVerilog"
version := "0.1"
scalaVersion := "2.11.12"
resolvers += "aliyun" at "http://maven.aliyun.com/nexus/content/groups/public/"
libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.1.2"
libraryDependencies += "edu.berkeley.cs" % "chisel-iotesters_2.11" % "1.3.8"
注意:chisel和scala的版本。
在项目的test/scala中建AdderTests.scala,内容如下:
import chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
import com.joe.stu.Adder
class AdderTests(c: Adder) extends PeekPokeTester(c) { //ucb-bar chisel-tutorial
for (t <- 0 until (1 << (c.n + 1))) {
val rnd0 = rnd.nextInt(1 << c.n)
val rnd1 = rnd.nextInt(1 << c.n)
val rnd2 = rnd.nextInt(2)
poke(c.io.A, rnd0)
poke(c.io.B, rnd1)
poke(c.io.Cin, rnd2)
step(1)
val rsum = rnd0 + rnd1 + rnd2
val mask = BigInt("1"*c.n, 2)
expect(c.io.Sum, rsum &mask)
expect(c.io.Cout,((1 << c.n) & rsum) >> c.n)
}
}
object test {
def main(args: Array): Unit = {
chisel3.iotesters.Driver(()=>new Adder(4))(t=>new AdderTests(t))
}
}
然后运行本main函数,测试显示如下:
Elaborating design...
Done elaborating.
Total FIRRTL Compile Time: 732.5 ms
Total FIRRTL Compile Time: 76.9 ms
End of dependency graph
Circuit state created
SEED 1628919918517
test Adder Success: 64 tests passed in 37 cycles taking 0.104190 seconds
RAN 32 CYCLES PASSED
Process finished with exit code 0
其实新版测试架构chisel3.testers比chisel3.iotesters功能更强大。
页:
[1]