跳至主要内容

未提供项目描述

项目描述

cocotb-test

Build Status PyPI version

cocotb-testcocotb 提供标准 Python 单元测试功能

  • 允许 Python 单元测试的外观和感觉
  • 不需要 Makefiles(包括 Makefile 兼容模式)
  • 允许轻松自定义仿真流程
  • 允许使用 pytest-xdistpytest-parallel 进行并行运行

用法

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.svdff_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]
@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 -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

相关资源

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

cocotb-test-0.2.5.tar.gz (20.6 kB 查看哈希值)

上传于

支持