PyHDI / veriloggen

Veriloggen: A Mixed-Paradigm Hardware Construction Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

realtime monitoring of simulation output

sgherbst opened this issue · comments

Hi,

On my platform (macOS Sierra 10.12.5, vvp 11.0, iverilog 11.0) the display=True option of simulation.run doesn't provide realtime output when using the iverilog simulator. The simulation runs, but no simulator output is printed until the simulation finishes. Such realtime feedback would be useful for running long simulations.

I traced the issue back to vvp and opened an issue there.

As workaround for now, I found that the issue can be resolved by calling vvp through unbuffer, which can be installed on macOS via brew install homebrew/dupes/expect. I believe it is standard on Linux systems.

Here is a sample implementation in simulation.run_iverilog, near line 175.

# generate the simulation command
sim_cmd = [os.path.join('.', outputfile)]
if display:
    # use unbuffer if available
    try:
        # unbuffer will print out a usage message to stderr if available, which is suppressed
        subprocess.Popen('unbuffer', stderr=subprocess.DEVNULL).wait()
        sim_cmd = ['unbuffer'] + sim_cmd
    except FileNotFoundError:
        pass

# run the simulation
sim_rslt = ''
with subprocess.Popen(sim_cmd, stdout=subprocess.PIPE) as p:
    for line in p.stdout:
        decoded = line.decode(encode)
        sim_rslt += decoded
        if display:
            print(decoded, end='')

Thanks,
Steven

It looks like this behavior of vvp is expected according to a comment, so I think it's probably necessary to use unbuffer, stdbuf, or similar to achieve realtime output.