2、chiseltest实验与大坑

目的

这次的目的是利用chisel test完成对硬件代码的测试。相当于Verilog写Testbench测试硬件代码的过程。因为chisel-bootcamp和chisel-book用的chisel test都过老,和直接clone下来的chisel-templete的chisel test不符,所以这里在下还是搞了很久…
主要参考:
https://github.com/ucb-bar/chisel-testers2
和chisel-templete中test中的gcd测试

流程

在之前的MyPacket.scala中添加AND硬件代码

class AND 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
}

在test下创建mypack对应的MyPacket.scala文件
其中代码如下所示:

package mypack
//表明是mypack的包
import chisel3._
import chisel3.tester._
//import chiseltest._
import org.scalatest._
import scala.util._

class ANDSpec extends FreeSpec with ChiselScalatestTester with Matchers{
    "AND should " in {
        test(new AND) { c =>
            c.io.a.poke(0.U)     // Set our input to value 0
            c.io.b.poke(0.U)     // Set our input to value 0
            c.io.out.expect(0.U)  // Assert that the output correctly has 0

            c.io.a.poke(1.U)     // Set our input to value 1
            c.io.out.expect(0.U)  // Assert that the output correctly has 1
            c.io.b.poke(1.U)     // Set our input to value 2
            c.io.out.expect(1.U)  // Assert that the output correctly has 2
        }

    }
    
}

其中 extends FreeSpec with ChiselScalatestTester with Matchers 这些是取自scala test的东西,chisel-test2似乎将之前的PeekPokeTester与Scala test合并,所以相对来说很像chisel-book中提到的scala test的测试方法。
这里要注意的是和bootcamp与book不同的是,这里的test一定要在前面写个“字符串” in {},在大括号里放置test才可以,据大佬说是scala test框架的锅。

然后在终端输入

sbt test

即可验证。若想单独验证,输入如下代码即可

sbt "testOnly mypack.ANDSpec"
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值