简体   繁体   English

为什么根据 ChiselTest 没有正确设置这个本地变量

[英]Why is this local var not set correctly according to ChiselTest

I'm coming from Bluespec and not understanding this Chisel behavior.我来自 Bluespec,不理解这种 Chisel 行为。 I have a simple Module:我有一个简单的模块:

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
}

I'm trying to decipher why my tester is indicating the io.invalidOperation is asserted in this test.我试图破译为什么我的测试人员表明 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)
        }
    }
}

The output (notice the printf indicating the valid operation)输出(注意 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

If I instead assign io.invalidOperation directly (instead of the local var), everything works.如果我改为直接分配 io.invalidOperation(而不是本地 var),则一切正常。 Why is the behavior with the local var different than assigning directly to io.invalidOperation?为什么本地 var 的行为与直接分配给 io.invalidOperation 的行为不同?

Thanks.谢谢。

If you want do declare a new wire, you may try this:如果你想声明一个新的电线,你可以试试这个:

val invalidOperation = Wire(Bool())
io.invalidOperation := invalidOperation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM