risc-v中文社区

 找回密码
 立即注册
查看: 1239|回复: 1

[原创] 类似junit的chisel中的iotesters

[复制链接]

347

主题

564

帖子

2237

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2237
发表于 2021-8-14 14:03:59 | 显示全部楼层 |阅读模式
下面的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[String]): Unit = {
   chisel3.iotesters.Driver(()=>new Adder(4))(t=>new AdderTests(t))
  }
}
然后运行本main函数,测试显示如下:
[info] [0.004] Elaborating design...
[info] [1.793] Done elaborating.
Total FIRRTL Compile Time: 732.5 ms
Total FIRRTL Compile Time: 76.9 ms
End of dependency graph
Circuit state created
[info] [0.002] SEED 1628919918517
test Adder Success: 64 tests passed in 37 cycles taking 0.104190 seconds
[info] [0.076] RAN 32 CYCLES PASSED

Process finished with exit code 0


回复

使用道具 举报

347

主题

564

帖子

2237

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2237
 楼主| 发表于 2021-8-14 14:07:44 | 显示全部楼层
其实新版测试架构chisel3.testers比chisel3.iotesters功能更强大。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



Archiver|手机版|小黑屋|risc-v中文社区

GMT+8, 2024-4-27 14:52 , Processed in 0.014629 second(s), 17 queries .

risc-v中文社区论坛 官方网站

Copyright © 2018-2021, risc-v open source

快速回复 返回顶部 返回列表