当前位置:网站首页>Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
2022-07-04 14:09:00 【github-3rr0r】
Chisel The project build 、 Run and test ( Four )——Chisel Tested ChiselTest
Last article we introduced ScalaTest, It is Scala and Java Test tools . And now Chisel The latest standard test tool for modules is ChiselTest, It is based on ScalaTest Of , Allow us to use Chisel test . In order to use ChiselTest, We also need to build.sbt
It contains chiseltest
The library of :
libraryDependencies += "edu.berkeley.cs" %% "chiseltest" % "0.5.1" % "test"
Or so :
libraryDependencies ++= Seq(
"edu.berkeley.cs" %% "chisel3" % chiselVersion,
"edu.berkeley.cs" %% "chiseltest" % "0.5.1" % "test"
),
Chisel-template Of build.sbt
It contains by default chiseltest
Library , So we can not modify . This method includes ChiselTest Will automatically include the corresponding version ScalaTest, So what I said in the last article includes ScalaTest It's not necessary .
To use ChiselTest Words , We need to import the following packages :
import chisel3._
import chiseltest._
import org.scalatest.flatspec.AnyFlatSpec
Testing the circuit needs to include at least two parts , One is DUT( Parts to be tested ), The other is test logic , Also called testbench. Start the test and ScalaTest It's the same , function sbt test
Just order , There is no need to have an object containing the main function as the program entry .
The following code is a simple DUT, It has two input ports and one output port , Are two unsigned number signals , The function realized is to input a
and b
perform Bitwise AND operation , Then output the results to out
On :
class DeviceUnderTest extends Module {
val io = IO(new Bundle {
val a = Input(UInt(2.W))
val b = Input(UInt(2.W))
val out = Output(UInt(2.W))
})
io.out := io.a & io.b
}
Although the writing method of the module has not been introduced , But this code is also very easy to understand . Now let's give this DUT Of testbench, It's from AnyFlatSpec
and ChiselScalatestTester
Extended , Therefore, it has ChiselTest Functional ScalaTest. And call test()
When the method is used , With the newly created DUT An example of is the parameter , Take the test code as the function number face quantity (function literal). The code is as follows :
class SimpleTest extends AnyFlatSpec with ChiselScalatestTester {
"DUT" should "pass" in {
test(new DeviceUnderTest) {
dut =>
dut.io.a.poke(0.U)
dut.io.b.poke(1.U)
dut.clock.step()
println("Result is: " + dut.io.out.peek().toString)
dut.io.a.poke(3.U)
dut.io.b.poke(2.U)
dut.clock.step()
println("Result is: " + dut.io.out.peek().toString)
}
}
}
DUT The input and output ports of the instance of pass through dut.io
To visit . We can call poke
To assign values to ports , It accepts the corresponding port Chisel Type value . Call on the output port peek
The output of the port can be read out , The return value is also corresponding to the port Chisel Type value , Then call on this value toString
You can convert it to a string , Then you can call println()
Function output on the command line . Call in the test dut.clock.step()
It can advance the clock by one cycle , So that the simulation can move forward . If you want to advance multiple cycles , We can give step()
Provide a parameter .
function sbt test
perhaps :
sbt "testOnly SimpleTest"
You can see the test results on the terminal :
It turns out that ,0
and 1
The result of bitwise and is 0
,3
and 2
The result of bitwise and is 2. Of course, information has more than results , We can still see that toString
Method also outputs the result Chisel type UInt<2>
, That is, two unsigned integers .
It must be bad for us to check the output manually , But it's half done . To automatically complete the comparison with the expected results , We can call on the output port expect(value)
Come on testbench The expected value is given in , The expected value is expect(value)
Parameters of value
. The modified test is as follows :
class SimpleTestExpect extends AnyFlatSpec with ChiselScalatestTester {
"DUT" should "pass" in {
test(new DeviceUnderTest) {
dut =>
dut.io.a.poke(0.U)
dut.io.b.poke(1.U)
dut.clock.step()
dut.io.out.expect(0.U)
dut.io.a.poke(3.U)
dut.io.b.poke(2.U)
dut.clock.step()
dut.io.out.expect(2.U)
}
}
}
Now run this test :
sbt "testOnly SimpleTestExpect"
This test will not output any results from hardware , It automatically compares the result with the expected value in the test , Output is as follows :
If the test fails , such as DUT perhaps testbench There are mistakes in it , The actual result is inconsistent with the expected value , Then generate an error message to describe the difference between the two . For example, we put testbench In the last line of dut.io.out.expect(2.U)
Change to dut.io.out.expect(1.U)
, The output is like this :
A red error report , At the same time, it also gives the reasons why the test failed and the specific differences , This information is very useful when debugging , So testing is very important .
Conclusion
This article talks about how to use ChiselTest Do a simple test , You can see that it is very basic , It's also very convenient . However , The more essential content has not been reflected , At present, the test written has not yet played Scala The power of . for instance , In the above tests, we manually give the expected input and output values of the test , and Scala It can be used to write a reference model , That is, the golden model in another series , In this way, the test can be more automated 、 More comprehensive . But we won't talk about it for the time being , I have to finish talking about several test methods first , Next we will talk about testing with waveforms .
边栏推荐
- #yyds干货盘点# 解决名企真题:连续最大和
- 锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
- E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
- php 日志调试
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
- PHP log debugging
- [R language data science]: cross validation and looking back
- 免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy
- Variable promotion and function promotion in JS
- Read excel table data
猜你喜欢
MySQL version 8 installation Free Tutorial
Unity shader learning (3) try to draw a circle
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
392. 判断子序列
软件测试之测试评估
Unity Shader学习(三)试着绘制一个圆
MySQL5免安装修改
CVPR 2022 | greatly reduce the manual annotation required for zero sample learning, and propose category semantic embedding rich in visual information (source code download)
随机推荐
1200. Minimum absolute difference
Introduction to reverse debugging PE structure resource table 07/07
How to choose a technology stack for web applications in 2022
find命令报错: paths must precede expression(转)
xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
Go 语言入门很简单:Go 实现凯撒密码
CVPR 2022 | greatly reduce the manual annotation required for zero sample learning, and propose category semantic embedding rich in visual information (source code download)
读取 Excel 表数据
Test evaluation of software testing
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
205. 同构字符串
Node の MongoDB安装
软件测试之测试评估
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
Hardware Basics - diode Basics
sharding key type not supported
Use the default route as the route to the Internet
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)