-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mlp example #172
base: main
Are you sure you want to change the base?
Mlp example #172
Changes from all commits
2e28da6
08c5fda
8537c2c
c2e47dc
b3081ba
9fd3d67
cf6f26c
3bfe064
caad0b1
5b8990f
0509014
7aaba88
181b537
f93c976
0a8b4dd
35afa85
8ef71cf
9210756
3c272a7
29faf71
50816af
c1d1fd7
8535c57
590f20e
8076bc1
5d26837
cfb256e
d825cbe
3a23cb2
80c671f
8b5309c
047f27b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os, logging | ||
|
||
from mase_cocotb.random_test import check_results | ||
from mase_cocotb.runner import mase_runner | ||
|
||
import cocotb | ||
from cocotb.triggers import Timer | ||
from cocotb.triggers import FallingEdge | ||
from cocotb.clock import Clock | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# DUT test specifications | ||
class VerificationCase: | ||
def __init__(self, iterations=1, samples=10): | ||
self.samples = samples | ||
self.iterations = iterations | ||
|
||
|
||
@cocotb.test() | ||
async def test_top(dut): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This functionality is already implemented in |
||
"""Test top-level model hardware design""" | ||
samples = 1000 | ||
test_case = VerificationCase(samples=samples) | ||
|
||
# Reset cycle | ||
await Timer(20, units="ns") | ||
dut.rst.value = 1 | ||
await Timer(100, units="ns") | ||
dut.rst.value = 0 | ||
|
||
# Create a 10ns-period clock on port clk | ||
clock = Clock(dut.clk, 10, units="ns") | ||
# Start the clock | ||
cocotb.start_soon(clock.start()) | ||
await Timer(500, units="ns") | ||
|
||
# Synchronize with the clock | ||
dut.data_in_0_valid.value = 0 | ||
dut.data_out_0_ready.value = 1 | ||
debug_state(dut, "Pre-clk") | ||
await FallingEdge(dut.clk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Driving handshakes manually by assigning signals and awaiting clock edges is too verbose and error prone. We should use mase_cocotb.interfaces.streaming.StreamDriver instead |
||
debug_state(dut, "Post-clk") | ||
debug_state(dut, "Pre-clk") | ||
await FallingEdge(dut.clk) | ||
debug_state(dut, "Post-clk") | ||
|
||
done = False | ||
# Set a timeout to avoid deadlock | ||
for i in range(samples * 100): | ||
await FallingEdge(dut.clk) | ||
debug_state(dut, "Post-clk") | ||
dut.data_in_0_valid.value = test_case.data_in.pre_compute() | ||
await Timer(1, units="ns") | ||
dut.data_out_0_ready.value = test_case.outputs.pre_compute( | ||
dut.data_out_0_valid.value | ||
) | ||
await Timer(1, units="ns") | ||
debug_state(dut, "Post-clk") | ||
|
||
dut.data_in_0_valid.value, dut.data_in_0.value = test_case.data_in.compute( | ||
dut.data_in_0_ready.value | ||
) | ||
await Timer(1, units="ns") | ||
dut.data_out_0_ready.value = test_case.outputs.compute( | ||
dut.data_out_0_valid.value, dut.data_out_0.value | ||
) | ||
debug_state(dut, "Pre-clk") | ||
|
||
if test_case.data_in.is_empty() and test_case.outputs.is_full(): | ||
done = True | ||
break | ||
assert ( | ||
done | ||
), "Deadlock detected or the simulation reaches the maximum cycle limit (fixed it by adjusting the loop trip count)" | ||
|
||
check_results(test_case.outputs.data, test_case.ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verification classes should inherit from mase_cocotb.testbench.Testbench