当前位置:网站首页>Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test

Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test

2022-07-04 14:07:00 github-3rr0r

Chisel The project build 、 Run and test ( 3、 ... and )——Chisel Tested ScalaTest

The test in hardware design is usually called testbench, It is called test bench , It's still used in the back testbench To express .testbench Will instantiate a piece to be tested DUT(Design Under Test, Design to be tested ), Drive the input interface and observe the output interface , Compare whether the output is compound with the expectation .

Chisel Two test methods are provided in , Namely chiseltest In bag ChiselTest and iotesters In bag PeekPokeTester. however iotesters stay Chisel 3.5 The version has been deprecated at first , This series is based on Chisel 3.5 Of , So I'm not going to introduce iotesters Related content , Just introduce ChiselTest Related content .

Chisel One of its strengths is that it can take advantage of Scala Write with the powerful function of testbench. For example, we can Write the desired hardware functions in the software simulator , Then compare the hardware simulation with the software simulation . This method is very efficient in testing the implementation of processors .

In the next few articles, we will introduce Chisel Four test frameworks that may be used in , First of all, from the ScalaTest Start .

ScalaTest

ScalaTest yes Scala Test tools ,Chisel Test tools ChiselTest It's also ScalaTest Development of . therefore , Let's first learn a simple ScalaTest Example .

To use ScalaTest, The first thing you need to do is build.sbt Contains the corresponding library , We can add a sentence directly at the end :

libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.4" % "test"

It can also be in Chisel-template in build.sbt Based on ( Add ):

libraryDependencies ++= Seq(
	"edu.berkeley.cs" %% "chisel3" % chiselVersion,
	"edu.berkeley.cs" %% "chiseltest" % "0.5.1" % "test",
	"org.scalatest" %% "scalatest" % "3.1.4" % "test"
),

The test is usually done in src/test/scala Under folder , You can run the whole test with the following instructions :

sbt test

Here is a simple test , test Scala Integer addition and multiplication in :

import org.scalatest._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class ExampleTest extends AnyFlatSpec with Matchers {
    
    "Integers" should "add" in {
    
        val i = 2
        val j = 3
        i + j should be (5)
    }

    "Integers" should "multiply" in {
    
        val i = 3
        val j = 4
        i * j should be (12)
    }
}

It looks a little complicated , When you read it carefully, you feel that it is all vernacular , In especial should and should be, It's not like writing code , But it's really easy to understand, good memory .ScalaTest It is to support such simple unit tests that read like executable specifications . The above example contains two tests , The output of the test run will show the specification we give and whether the test passes , Output is as follows :

 Insert picture description here

This grammar is actually very simple , Import three related packages , The rest can be painted according to the gourd , There's not much to explain .

sbt test This command will execute all tests , This is very useful in recursive testing . But if we want to run a single test or a single test suite , You can use this command :

sbt "testOnly ExampleTest"

here ExampleTest That is, the class of the test we run , If we accidentally misspell , Or there is no such class , Then he won't report a red error , It will only quietly output a white result :

[info] No tests to run for Test / testOnly

Conclusion

Testing is a key part of digital design , We must master .ScalaTest The relevant content is still very simple , For the next article ChiselTest It's the play . This article mentioned ChiselTest In fact, that is ScalaTest Development of , So it's not bad , There are some differences in knowledge grammar , Let's learn the next article together .

原网站

版权声明
本文为[github-3rr0r]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041110120891.html