[英]Testing Chisel object functions that use hardware constructs
What is the proper way to test a Chisel function not part of a Module that generates hardware constructs?测试 Chisel function 不是生成硬件结构的模块的一部分的正确方法是什么?
object Util {
def getSquare(vec2d: Vec[Vec[Bool]]) : Seq[Seq[Bool]] = {
val size = vec2d.size max vec2d(0).size
return Seq.fill(size, size) {Wire(Bool())}
}
}
How can I test this function?我如何测试这个 function? Because it isn't a Module, the standard Chisel test format complains.因为它不是模块,所以标准的 Chisel 测试格式会报错。
In general you can only use code that generates chisel hardware constructs within a Module (literals are an exception).通常,您只能使用在模块中生成凿子硬件构造的代码(文字除外)。 So the typical methodology would be to write a wrapper and see that the generated code contains what you expect.因此,典型的方法是编写包装器并查看生成的代码是否包含您期望的内容。 For example here's a little test of your function例如,这是对您的 function 的一个小测试
"test non-module generator" in {
// pads out rectangular vec into square nested seq, fills with values based on indices
class Wrapper extends Module {
val square = (Util.getSquare(Vec(4, Vec(2,Bool()))))
square.indices.foreach { i => square(i).indices.foreach { j => square(i)(j) := ((i + j ) % 2 == 0).B}}
val out = IO(Output(Vec(4, Vec(4,Bool()))))
out.indices.foreach { i => out(i).indices.foreach { j => out(i)(j) := square(i)(j)}}
}
val firrtlSource = ChiselStage.emitFirrtl(new Wrapper)
println(firrtlSource)
firrtlSource should contain ("wire square_4_4")
}
You can also test your wrapper function with the chiseltest basic test harness, for example:您还可以使用 chiseltest 基本测试工具测试包装器 function,例如:
test(new Wrapper) { dut =>
dut.out(3)(3).expect(true.B)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.