Build options and Environment Variables¶
Makefiles are provided for a variety of simulators in
The common Makefile
cocotb/share/makefiles/Makefile.sim includes the appropriate simulator Makefile based on the contents of the
Makefiles define two targets,
sim, the default target is
Both rules create a results file with the name taken from
COCOTB_RESULTS_FILE, defaulting to
results.xml. This file is a JUnit-compatible output file suitable for use with Jenkins. The
sim targets unconditionally re-runs the simulator whereas the
regression target only re-builds if any dependencies have changed.
Typically the makefiles provided with cocotb for various simulators use a separate
run target. This allows for a rapid re-running of a simulator if none of the RTL source files have changed and therefore the simulator does not need to recompile the RTL.
Set this to 1 to enable the GUI mode in the simulator (if supported).
Selects which simulator Makefile to use. Attempts to include a simulator specific makefile from
Set this to 1 to enable wave traces dump for the Aldec Riviera-PRO and Mentor Graphics Questa simulators. To get wave traces in Icarus Verilog see Simulator Support.
A list of the Verilog source files to include.
A list of the VHDL source files to include.
A list of the VHDL source files to include in the VHDL library lib (currently for the GHDL simulator only).
Any arguments or flags to pass to the compile stage of the simulation.
Any arguments or flags to pass to the execution of the compiled simulation.
Passed to both the compile and execute phases of simulators with two rules, or passed to the single compile and run command for simulators which don’t have a distinct compilation stage.
“Plusargs” are options that are starting with a plus (
+) sign. They are passed to the simulator and are also available within cocotb as
cocotb.plusargs. In the simulator, they can be read by the Verilog/SystemVerilog system functions
The special plusargs
+seed, if present, are evaluated to set the random seed value if
RANDOM_SEEDis not set. If both
The default time unit that should be assumed for simulation when not specified by modules in the design. If this isn’t specified then it is assumed to be
1ns. Allowed values are 1, 10, and 100. Allowed units are
New in version 1.3.
The default time precision that should be assumed for simulation when not specified by modules in the design. If this isn’t specified then it is assumed to be
1ps. Allowed values are 1, 10, and 100. Allowed units are
New in version 1.3.
Use to add additional dependencies to the compilation target; useful for defining additional rules to run pre-compilation or if the compilation phase depends on files other than the RTL sources listed in
Use to add additional dependencies to the simulation target.
Set this to 1 to enable display of VHPI traces when using the NVC VHDL simulator.
Use to define a scratch directory for use by the simulator. The path is relative to the Makefile location. If not provided, the default scratch directory is
Use this to indicate the instance in the hierarchy to use as the DUT. If this isn’t defined then the first root instance is used.
Seed the Python random module to recreate a previous test stimulus. At the beginning of every test a message is displayed with the seed used for that execution:
INFO cocotb.gpi __init__.py:89 in _initialise_testbench Seeding Python random module with 1377424946
To recreate the same stimuli use the following:
Use this to override the default behavior of annotating cocotb output with ANSI color codes if the output is a terminal (
COCOTB_ANSI_OUTPUT=1forces output to be ANSI regardless of the type of
COCOTB_ANSI_OUTPUT=0suppresses the ANSI output in the log messages
If defined, log lines displayed in the terminal will be shorter. It will print only time, message type (
ERROR, …) and the log message itself.
The name of the module(s) to search for test functions. Multiple modules can be specified using a comma-separated list.
Multiple test functions can be specified using a comma-separated list.
The file name where xUnit XML tests results are stored. If not provided, the default is
New in version 1.3.
Additional Environment Variables¶
In order to give yourself time to attach a debugger to the simulator process before it starts to run, you can set the environment variable
COCOTB_ATTACHto a pause time value in seconds. If set, cocotb will print the process ID (PID) to attach to and wait the specified time before actually letting the simulator run.
Enable performance analysis of the Python portion of cocotb. When set, a file
test_profile.pstatwill be written which contains statistics about the cumulative time spent in the functions.
From this, a callgraph diagram can be generated with gprof2dot and
graphviz. See the
profileMake target in the
endian_swapperexample on how to set this up.
A comma-separated list of modules that should be executed before the first test. You can also use the
cocotb.hookdecorator to mark a function to be run before test code.
The default logging level to use. This is set to
INFOunless overridden. Valid values are
Defines how to resolve bits with a value of
Wwhen being converted to integer. Valid settings are:
randomly resolve to a
Enable additional log output of the coroutine scheduler.
Enable to report Python coverage data. For some simulators, this will also report HDL coverage.
This needs the
coveragePython module to be installed.
HTTP port to use for debugging Python’s memory usage. When set to e.g.
8088, data will be presented at http://localhost:8088.
This needs the
dowserPython modules installed.
Path to the directory containing the cocotb Python package in the
cocotbsubdirectory. You don’t normally need to modify this.
Path to the directory containing the cocotb Makefiles and simulator libraries in the subdirectories
makefiles. You don’t normally need to modify this.