forked from TinyTapeout/tinyqv-byte-peripheral-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
51 lines (38 loc) · 1.85 KB
/
test.py
File metadata and controls
51 lines (38 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# SPDX-FileCopyrightText: © 2025 Tiny Tapeout
# SPDX-License-Identifier: Apache-2.0
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import ClockCycles
from tqv import TinyQV
# When submitting your design, change this to 16 + the peripheral number
# in peripherals.v. e.g. if your design is i_user_simple00, set this to 16.
# The peripheral number is not used by the test harness.
PERIPHERAL_NUM = 16
@cocotb.test()
async def test_project(dut):
dut._log.info("Start")
# Set the clock period to 100 ns (10 MHz)
clock = Clock(dut.clk, 100, units="ns")
cocotb.start_soon(clock.start())
# Interact with your design's registers through this TinyQV class.
# This will allow the same test to be run when your design is integrated
# with TinyQV - the implementation of this class will be replaces with a
# different version that uses Risc-V instructions instead of the SPI
# interface to read and write the registers.
tqv = TinyQV(dut, PERIPHERAL_NUM)
# Reset, always start the test by resetting TinyQV
await tqv.reset()
dut._log.info("Test project behavior")
# Test register write and read back
await tqv.write_reg(0, 20)
assert await tqv.read_reg(0) == 20
# Set an input value, in the example this will be added to the register value
dut.ui_in.value = 30
# Wait for two clock cycles to see the output values, because ui_in is synchronized over two clocks,
# and a further clock is required for the output to propagate.
await ClockCycles(dut.clk, 3)
# The following assertion is just an example of how to check the output values.
# Change it to match the actual expected output of your module:
assert dut.uo_out.value == 50
# Keep testing the module by changing the input values, waiting for
# one or more clock cycles, and asserting the expected output values.