Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verilator fails test_dff.py example #3801

Open
dpetrisko opened this issue Mar 22, 2024 · 4 comments
Open

Verilator fails test_dff.py example #3801

dpetrisko opened this issue Mar 22, 2024 · 4 comments
Assignees

Comments

@dpetrisko
Copy link

dpetrisko commented Mar 22, 2024

Hello, the default example fails in Verilator (5.022, though it shouldn't matter).

# test_dff.py

import random

import cocotb
from cocotb.clock import Clock
from cocotb.triggers import RisingEdge
from cocotb.types import LogicArray

@cocotb.test()
async def dff_simple_test(dut):
    """Test that d propagates to q"""

    # Assert initial output is unknown
    assert LogicArray(dut.q.value) == LogicArray("X") <- Failure!!
    # Set initial input value to prevent it from floating
    dut.d.value = 0

    clock = Clock(dut.clk, 10, units="us")  # Create a 10us period clock on port clk
    # Start the clock. Start it low to avoid issues on the first RisingEdge
    cocotb.start_soon(clock.start(start_high=False))

    # Synchronize with the clock. This will regisiter the initial `d` value
    await RisingEdge(dut.clk)
    expected_val = 0  # Matches initial input value
    for i in range(10):
        val = random.randint(0, 1)
        dut.d.value = val  # Assign the random value val to the input port d
        await RisingEdge(dut.clk)
        assert dut.q.value == expected_val, f"output q was incorrect on the {i}th cycle"
        expected_val = val # Save random value for next RisingEdge

    # Check the final input on the next clock
    await RisingEdge(dut.clk)
    assert dut.q.value == expected_val, "output q was incorrect on the last cycle"

The issue is that Verilator does not support X's, so the initial value is set by Verilator's
--x-initial <mode> Assign initial Xs to this value
--x-assign <mode> Assign non-initial Xs to this value

Maybe it makes sense to set x-assign for verilator in Makefile.verilator and then modify the backend function of 'X' comparisons to use verilator's x-assign value?

@ktbarrett
Copy link
Member

This is already fixed on master.

@dpetrisko
Copy link
Author

Oh, I see that the example has been fixed. However, the README still has the outstanding bug. Thanks!

@ktbarrett
Copy link
Member

Oh... totally missed that. Good catch!

@cmarqu cmarqu reopened this Mar 23, 2024
@ktbarrett
Copy link
Member

I don't think we want simulator ifdefs in our examples. I will refactor the example and paste it on the README.

@ktbarrett ktbarrett self-assigned this Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants