Why do poked values change on last clock cycle in chiseltest, thus failing asserts?

112 views Asked by At

I've tried adding some asserts to my code, but these asserts fail when testing my module, even though I've poked the values accordingly. Interestingly, according to some prints, the value changes value in the last simulated cycle, as shown by this minimal example:

package stack_overflow_demo

import chisel3._
import chisel3.tester._
import org.scalatest.FreeSpec
import chisel3.experimental.BundleLiterals._

class AssertFail extends Module {
    val io = IO(new Bundle {
        val input = Input(UInt(2.W))
    })

    printf("%d\n", io.input) // prints 3 and then 0

    assert(io.input === 3.U) // fails, apparently on the second cycle
}

class AssertTest extends FreeSpec with ChiselScalatestTester {
    "break" in {
        test(new AssertFail) { dut =>
            dut.io.input.poke(3.U)
            dut.clock.step()
        }
    }
}

I basically want to understand why that happens and also if I can keep these asserts active in my code or if I have to remove them alltogether.

(The actual code is part of an RISC-V decoder that can not manage the "C" compressed instruction-extension, so for simulation I tried to assert the lowest two bits to be 11)

Thank you!

1

There are 1 answers

0
Chick Markley On BEST ANSWER

I think the problem is that the chiseltest harness uses an implicit scope in your testing block, when the scope is finished it restores the input values to their state when it began. That is what is causing the problem. I think this is a bug, and shouldn't be too hard to fix. You should open and issue on the chiseltest repo. We'll try and get this fixed or provide a workaround