2

Given the D-FF example from cocotb/examples/dff/. What is the proper way to pass an argument from the Makefile to the cocotb testbench dff_cocotb.py without modifying the native cocotb makefiles?

I tried to modify line 30 of cocotb/examples/dff/tests/Makefile:

sim:
    $(MODULE).py testarg

respectively

sim: $(MODULE).py
$(MODULE).py:
    $(MODULE).py testarg

which doesn't work and shows the error message:

usage: cocotb [-h] test
cocotb: error: too few arguments
Marph
  • 176
  • 4
  • 15

2 Answers2

4

Hmm. It looks like the Makefile launches the simulator, which in turn invokes cocotb via VPI hooks into the simulator. If I understand correctly, it specifies the target testbench to the cocotb framework through environment variables.

This implies you may be able to pass your arguments to your $(MODULE).py using the environment as well. I.e., launch make as:

MY_TB_ARGS=<whatver> make

and in $(MODULE).py, access them via

import os
myTbArgs = os.environ['MY_TB_ARGS']
lockcmpxchg8b
  • 2,205
  • 10
  • 16
  • I'm using ghdl as simulator, but I don't want to pass an argument to the simulator directly. I just want to pass the argument from the `Makefile` to the file `dff_cocotb.py` and parse it there. – Marph Nov 24 '17 at 21:33
0

I would do something like

make PLUSARGS="+my_arg1=123 +my_arg2=456"

and access it through cocotb.plusargs

>>>print(cocotb.plusargs)
{'my_arg1': '123', 'my_arg2': '456'}