f4pga / f4pga-arch-defs

FOSS architecture definitions of FPGA hardware useful for doing PnR device generation.
https://f4pga.org
ISC License
272 stars 113 forks source link

Figure out how to write unit tests for the sim.v files. #59

Open mithro opened 6 years ago

mithro commented 6 years ago

We want a structured way to write unit tests for the sim.v files (and a way to run them).

We want the unit tests to be compatible with at a minimum;

But making it compatible with commercial simulators would be good too.

I think we want to use Cocotb but I have never used it myself.

mcmasterg commented 6 years ago

I don't have a whole lot to say on this / no strong opinion.

But I can add:

mithro commented 6 years ago

@cliffordwolf - Do you have an opinion on how we should be writing unit tests for these models? I'm guessing you are going to say we should be using formal verification? :-P

mithro commented 6 years ago

@awygle - FYI.

elms commented 6 years ago

I've started to look at demonstrating a simple test using cocotb and VUnit.

I have a branch with a simple test using cocotb (think I found an bug in mux2.sim.v).

VUnit doesn't currently support Icarus Verilog, but people are working on it (see vunit/vunit#188). I haven't had success running this branch yet (getting a segfault during compilation).

Other thoughts:

VUnit is a good choice to drive tesbtenches on an existing codebase. Each testbench needs a few lines added to integrate with VUnit. Running VUnit the output is very similar to many unit test frameworks. It looks like it can be extended to report details to other processes (eg octave) and do additional checks.

cocotb takes a different approach and borrows from UVM. The test cases are written in python which opens all the flexibility of python to how to drive DUTs. It also has a built-in concept for generating tests, but I haven't looked at that yet.

Both support GHDL and integration with Jenkins (which hopefully means easily with travis-ci).

mithro commented 6 years ago

By UVM you mean;

UVM is a methodology for the functional verification of digital hardware, primarily using simulation. The hardware or system to be verified would typically be described using Verilog, SystemVerilog, VHDL or SystemC at any appropriate abstraction level.

?

elms commented 6 years ago

Yes.

Cocotb encourages the same philosophy of design re-use and randomised testing as UVM [link]

They also use the scoreboard, driver, and monitor patterns which I believe is terminology shared with/borrowed from UVM. These are available but not required.