未提供项目描述
项目描述
cocotb-test
cocotb-test
为 cocotb 提供标准 Python 单元测试功能
- 允许 Python 单元测试的外观和感觉
- 不需要 Makefiles(包括 Makefile 兼容模式)
- 允许轻松自定义仿真流程
- 允许使用 pytest-xdist 或 pytest-parallel 进行并行运行
用法
-
安装 cocotb。
-
安装模拟器(对于使用 conda 的 Icarus Verilog,在 Windows 上使用 10.3 或开发版 steveicarus/iverilog#395 )
conda install -c conda-forge iverilog==10.3
- 通过 pip 安装包
pip install cocotb-test
或开发版本
pip install -v https://github.com/themperek/cocotb-test/archive/master.zip
或
git clone https://github.com/themperek/cocotb-test.git
pip install -v -e cocotb-test
- 创建一个
test_dff.py
文件(更多示例请查看 test 文件夹)
from cocotb_test.simulator import run
def test_dff():
run(
verilog_sources=["dff.sv"], # sources
toplevel="dff", # top level HDL
module="dff_cocotb" # name of cocotb test module
)
- 运行 pytest(需要
dff.sv
和dff_cocotb.py
在运行pytest
的同一目录中)
SIM=icarus pytest -o log_cli=True test_dff.py
- 为了清理(删除所有
sim_build
文件夹)
cocotb-clean -r
simulator.run
的参数
-
toplevel
:表示要作为 DUT 使用的实例的层次结构中顶层模块的名称。如果模拟器支持,可以指定多个顶层模块,作为一个列表。 -
module
:要搜索测试函数的模块的名称(参见 MODULE )。 -
python_search
:要搜索 Python/cocotb 模块的附加目录列表。 -
verilog_sources
:要包含的 Verilog 源文件。可以指定为list
或作为具有库名称作为键的list
的字典,如果模拟器支持命名库。 -
vhdl_sources
: 要包含的VHDL源文件。可以指定为一个列表
,或者指定为一个以库名为键的字典
,其中字典值为列表
,如果仿真器支持命名库。 -
toplevel_lang
: 参考TOPLEVEL_LANG。 (默认:verilog
) -
includes
: 要搜索包含文件的目录列表。 -
defines
: 定义列表。 -
parameters
: 顶级参数/泛型字典。 -
compile_args
: 传递给仿真编译阶段的任何参数或标志。vhdl_compile_args
: 仅在编译VHDL源文件时传递的附加参数或标志。verilog_compile_args
: 仅在编译Verilog源文件时传递的附加参数或标志。
-
sim_args
: 传递给编译后仿真执行的任何参数或标志。 -
extra_args
: 传递给仿真编译和执行阶段的参数。 -
plus_args
: 传递给模拟器的plusargs参数。 -
force_compile
: 即使源文件未更改也强制编译。 (默认:False
) -
compile_only
: 仅编译源文件。不运行仿真。 (默认:False
) -
testcase
: 要运行的测试函数名称(参考TESTCASE )。 -
sim_build
: 编译测试所使用的目录。 (默认:sim_build
) -
work_dir
: 运行测试所使用的目录。 (默认: 与sim_build
参数相同) -
seed
: 为Python随机模块设置种子以重新创建之前的测试激励(参考RANDOM_SEED )。 -
extra_env
: 在仿真进程设置的额外环境变量字典。 -
waves
: 启用波形转储(并非所有仿真器都支持)。 -
timescale
: 设置仿真器时间单位/精度(默认:None
) -
gui
: 以GUI模式启动(并非所有仿真器都支持)。 -
make_args
: 传递给make阶段的参数(仅限Verilator
)。
环境变量
SIM
: 选择要使用的仿真器。 (默认:icarus
)WAVES
: 覆盖启用波形转储参数。例如使用WAVES=1 pytest test_dff.py
。
pytest参数
cocotbxml
: 合并并保存cocotb测试的junitxml报告。例如使用pytest --cocotbxml=test-cocotb.xml
。
技巧和技巧
- 列出所有可用测试
pytest --collect-only
- 仅运行所选测试
pytest -k test_dff_verilog_param[3]
- 测试参数化(更多信息请参阅: test_parameters.py )
@pytest.mark.parametrize("width", [{"WIDTH_IN": "8"}, {"WIDTH_IN": "16"}])
def test_dff_verilog_testcase(width):
run(
...
parameters=width,
sim_build="sim_build/" + "_".join(("{}={}".format(*i) for i in width.items())),
)
- 并行运行测试(在安装pytest-xdist 之后)
pytest -n NUMCPUS
从cocotb运行(某些)测试和示例
为cocotb测试/示例以可编辑模式安装cocotb
git clone https://github.com/potentialventures/cocotb.git
pip install -e cocotb
SIM=icarus pytest -o log_cli=True --junitxml=test-results.xml --cocotbxml=test-cocotb.xml tests
相关资源
- pytest日志记录 - pytest日志记录文档
- pytest-xdist - 测试运行并行化(参考test_parallel)
- pytest-parallel - 并行和并发测试(参考test_parallel)
- pytest-html - 生成测试结果的HTML报告
- pytest-sugar - 糖
项目详情
cocotb-test-0.2.5.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0f19d9cfc1b7f64fe25394ff5a5d5f788f2d5b4f04b0a742f1330c4b6ebf1343 |
|
MD5 | e7da7d33475e6105ebde664dac3c224d |
|
BLAKE2b-256 | 56275d18c8cc3095615925c112d194bb5c98999cc5e9429d5350b833400fa82e |