我是从蓝语来的,不了解这支的行为。我有一个简单的模块:
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 (而不是本地变量),一切都会正常工作。为什么本地变量的行为与直接分配给io.invalidOperation不同?
谢谢。
发布于 2022-06-05 06:36:35
如果要声明一条新线路,可以尝试以下操作:
val invalidOperation = Wire(Bool())
io.invalidOperation := invalidOperationhttps://stackoverflow.com/questions/72492315
复制相似问题