[Cocotb] Sharing tests between simulation & lab

Jean-Marc Tremblay Jean-Marc.Tremblay at mdacorporation.com
Fri Aug 25 22:44:50 CEST 2017


Hi all,

I'm trying to find a way to have deterministic tests in simulation using a mechanism similar than cocotb.external() function, but blocking. Let me explain why I'm trying to do this.

In order to reuse our tests between the lab and simulation, we created a common high-level Python infrastructure that calls low-level functions (think read/write registers, etc.) based on the environment in use (lab/sim).

The tests are calling the high-level infra functions, which internally calls the Python-cocotb low-level functions decorated with @cocotb.function. I'm in the process of preparing a better example, but here is how this is done in pseudo-code.

I've tried to create my own external function without the use of the threading.Thread, but ran into a situation where the class function.__call__ would hang on self._event.wait().

Is there a cleaner/ better way to do this?

Thank you in advance,
Jean-Marc


Python program (test_prg.py - barely change)
import cocotb
global glog, gdut

def execTestFile(filename):
    execfile(filename)

@cocotb.test()
def test(dut):
    global glog, gdut
    gdut = dut
    glog = dut._log
    # setup env - not shown here
    filename = os.path.join(os.getcwd() + "/../test_file.py")
    yield cocotb.external(execTestFile)(filename)

Python test (filename = test_file.py - many flavors + we don't want yield nor cocotb references in them)
from test_prg import glog
from infra import sleep

for i in range(0,100):
    glog.info("oups, we are consuming time!: %d" % i)

sleep(100)

Python infra (infra.py - high-level infrastructure)
import cocotb
from test_prg import glog, gdut

@cocotb.function
def sleep(num_clk):
    for i in range(0, num_clk):
        yield cocotb.trigger.RisingEdge(dut.clk)
        glog.info("oups, we are consuming time as expected: %d" % i)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.librecores.org/pipermail/cocotb/attachments/20170825/ab01cc37/attachment.html>


More information about the cocotb mailing list