[英]Why is this local var not set correctly according to ChiselTest
我来自 Bluespec,不理解这种 Chisel 行为。 我有一个简单的模块:
class WhyFails extends Module {
val io = IO(new Bundle {
val operation = Input(UInt(2.W))
val result = Output(UInt(32.W))
val invalidOperation = Output(Bool())
})
var invalidOperation = false.B
when (io.operation === 0.U) {
io.result := 99.U
printf("WF: Valid operation\n")
}
.otherwise {
io.result := 0.U
invalidOperation = true.B
printf("WF: Invalid operation\n")
}
io.invalidOperation := invalidOperation
}
我试图破译为什么我的测试人员表明 io.invalidOperation 在这个测试中被断言。
class WhyFailsTest extends AnyFlatSpec with ChiselScalatestTester {
behavior of "WhyFails"
it should "Not Fail?" in {
test(new WhyFails) { wf =>
wf.io.operation.poke(0.U)
wf.clock.step() // Step so printf() produces output
wf.io.invalidOperation.expect(false.B)
wf.io.result.expect(99.U)
}
}
}
输出(注意 printf 指示有效操作)
> test
WF: Valid operation
[info] WhyFailsTest:
[info] WhyFails
[info] - should Not Fail? *** FAILED ***
[info] io_invalidOperation=true (1, 0x1) did not equal expected=false (0, 0x0) (lines in WhyFailsTest.scala: 11) (WhyFailsTest.scala:16)
...<snip>...
[info] *** 1 TEST FAILED ***
[error] Failed tests:
[error] temp.WhyFailsTest
[error] (Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 2 s, completed Jun 3, 2022, 8:59:04 AM
如果我改为直接分配 io.invalidOperation(而不是本地 var),则一切正常。 为什么本地 var 的行为与直接分配给 io.invalidOperation 的行为不同?
谢谢。
如果你想声明一个新的电线,你可以试试这个:
val invalidOperation = Wire(Bool())
io.invalidOperation := invalidOperation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.