Toffee
Toffee 是一个 Python 硬件验证框架。用 async / await 描述输入时序与条件等待,
用 pytest 运行测试,再通过参考模型、结果检查和覆盖率构建完整的验证环境。
- 时钟与事件:等待时钟边沿、信号条件和跨周期事件;支持将条件编译到原生后端求值。
- 驱动与检查:用 Driver、Monitor 和 Agent 组织可复用组件,通过 Scoreboard 检查顺序或乱序响应。
- 覆盖与回归:定义功能覆盖、交叉覆盖和时序覆盖,在多进程回归后汇总功能与原生覆盖率。
快速开始
需要 Python 3.11+。PyPI 分发名为 uc-toffee,导入名为 toffee,
原生绑定由依赖 uc-xcomm 提供。可用 python3 -m pip install "uc-toffee[runner]" 安装。
下面在仓库根目录创建环境并从源码安装,以便运行仓库自带的例子:
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -e '.[test]'
下面用仓库自带的 8 位累加器模型演示一个测试,无需安装 RTL 仿真器。 测试送入数字 3,等待一个时钟周期,再检查累加结果与空闲时的行为:
import pytest
from toffee import ClockCycles, Execution
from examples.getting_started.toy_dut import TutorialDut
@pytest.mark.asyncio
async def test_one_input_and_idle():
dut = TutorialDut()
try:
async with Execution(dut.backend):
assert dut.total.U() == 0
dut.operand.Set(3)
dut.enable.Set(1)
await ClockCycles(dut.clock, 1)
dut.enable.Set(0)
assert dut.total.U() == 3
await ClockCycles(dut.clock, 2)
assert dut.total.U() == 3
finally:
dut.close()
这个用例已包含在示例文件中,可以直接运行:
python3 -m pytest -q examples/getting_started/test_accumulator.py::test_one_input_and_idle
预期得到 1 passed。继续阅读累加器教程,
逐步加入边界测试、Driver、Monitor、参考模型与覆盖率。
用于项目验证
接入真实 RTL 时,使用 Picker 生成的 DUT Python 包,通过 XCommClockBackend
连接 xspcomm 的时钟与信号。具体准备和依赖要求见真实 DUT 接入指南。
测试增多后,用 toffee run 并行执行并汇总覆盖率。例如,运行整个入门示例目录:
toffee run examples/getting_started --workers 4
终端会显示本次运行的产物目录;有覆盖数据时会生成 coverage.html。
将示例路径换成项目测试目录即可运行自己的回归,更多选项见回归运行指南。
文档
- 入门教程:从一条断言到完整的验证环境。
- 操作指南:接入 DUT、组织组件、采集覆盖率和运行回归。
- 接口参考:API、命令行参数和行为限制。
- 原理说明:仿真调度、资源归属与覆盖率含义。
- 可运行示例 · 参与开发
Toffee Legacy
旧版 Toffee 保留在 master 分支。
当前版本是一次 breaking change,与 Toffee Legacy 的 API 不兼容。
Metadata
Release files for uc-toffee 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| uc_toffee-2.0.0.tar.gz | 789.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| uc_toffee-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 935.3 kB
Release files / uc_toffee-2.0.0.tar.gz
| Download URL | uc_toffee-2.0.0.tar.gz |
|---|---|
| Size | 789.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6712f3cfe8601fa75bc928c03cbd8a6c1690385299c8af1f2d592d080782d5c
|
|
BLAKE2b-256 checksum How to use checksums |
abb62f7af6aa47fff798a245fe9f26039155b972b326d66f1ca7300c5d1bb4fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.
Transparency logRelease files / uc_toffee-2.0.0-py3-none-any.whl
| Download URL | uc_toffee-2.0.0-py3-none-any.whl |
|---|---|
| Size | 146.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d7e8f3ce8181f659fab28d57c5dbe74ae4f87f90fee05ffb4635976bac65186
|
|
BLAKE2b-256 checksum How to use checksums |
e15ca2c1ad676c245b8524e7c58e8eff2a39e97576eb6e35176e1b2ad106f83f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.
Transparency logSecurity for uc-toffee 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for uc_toffee-2.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.