Repository navigation
en getting started more cases
A passing “add 3 and hold for two cycles” test covers one scenario. Now check accumulation and boundaries.
| Input sequence | Expected final total | Scenario |
|---|---|---|
| 0 | 0 | Zero is valid input, not absence of input |
| 3, 5 | 8 | State accumulates across requests |
| 255 | 255 | Maximum input |
| 255, 1 | 0 | Overflow exactly to zero |
| 250, 10 | 4 | Keep the low eight bits after overflow |
Derive expectations from the specification, not dut.total.U(), which would compare the DUT with itself.
Continue in examples/getting_started/test_accumulator.py:
@pytest.mark.asyncio
@pytest.mark.parametrize("operands, expected", [
([0], 0),
([3, 5], 8),
([255], 255),
([255, 1], 0),
([250, 10], 4),
])
async def test_accumulator_cases(operands, expected):
dut = TutorialDut()
try:
async with Execution(dut.backend):
for operand in operands:
dut.operand.Set(operand)
dut.enable.Set(1)
await ClockCycles(dut.clock, 1)
dut.enable.Set(0)
assert dut.total.U() == expected
finally:
dut.close()python3 -m pytest -v examples/getting_started/test_accumulator.py::test_accumulator_casesExpect five PASSED entries and 5 passed. -v lists each case.
[3, 5] is a list; for operand in operands: visits its values in order.
Each iteration writes input, waits for an edge, and clears enable.
@pytest.mark.parametrize("operands, expected", [...]) calls the test once per row.
Each invocation creates a fresh DUT, so cases do not inherit prior state.
Add ([128, 128], 0) and expect 6 passed. Writing 256 as the expectation makes only this new case fail,
because an 8-bit register cannot hold 256.
These tests check final state, not yet every response or whether all responses arrive.
The repeated write/enable/wait/disable sequence is the next abstraction to extract:
define a Driver.
内容由 CI 自动同步;请编辑主仓库文档。 Automatically synced by CI; edit the source documentation.
- 首页
- 教程
- 操作指南
- 参考
- 原理说明
- Home
-
Tutorials
- Learning path
- 0. Prepare your environment
- 1. Your first PASS and FAIL
- 2. Inputs and clocks
- 3. More cases and boundaries
- 4. Extract a Driver
- 5. Delayed output and a Monitor
- 6. Assemble an Agent
- 7. Models and the test environment
- 8. Pipelines, batches, and cancellation
- 9. Understand failures
- 10. Functional coverage
- Optional: out-of-order responses
- Optional: native clocks and project DUTs
-
How-to guides
- Find your task
- Simulation and events
- Verification components
- Coverage and regressions
- Migration and maintenance
- Runnable examples
- Reference
- Explanation