Repository navigation
en getting started first test
Learn how a test judges a result and where to look when it fails. This lesson does not introduce clocks or verification components.
Open examples/getting_started/test_accumulator.py and find test_addition near the beginning.
The file already contains later lessons; focus on these lines:
def test_addition():
expected = 8
actual = 3 + 5
assert actual == expecteddef defines a function. pytest discovers functions whose names begin with test_.
Use four spaces for indentation. = assigns a value; == compares values.
assert requires a condition to hold and fails the test otherwise.
Here 3 + 5 stands in for the computation under test; the next lesson reads the actual value from a DUT.
Run in the terminal:
python3 -m pytest -q examples/getting_started/test_accumulator.py::test_additionExpect output similar to this, with a different duration:
. [100%]
1 passed in ...
. means a passing test and -q requests concise output. ::test_addition selects just that function.
Running the file with Python alone does not automatically call its test functions.
Change expected = 8 to expected = 9 and repeat the command:
E assert 8 == 9
1 failed in ...
The actual result is 8, while the test expected 9. Check the specification and test data before blaming the DUT. Restore 8 and confirm that the test passes again.
Append this function to the same file:
def test_eight_bit_wraparound():
actual = (250 + 10) % 256
assert actual == 4% computes a remainder. An unsigned 8-bit value holds 0–255; retaining the low 8 bits of 260 gives 4.
Run the new function:
python3 -m pytest -q examples/getting_started/test_accumulator.py::test_eight_bit_wraparoundExpect 1 passed. This still checks the specification without accessing a DUT.
Keep working in the same file and continue with inputs and clocks.
内容由 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