79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
import sys
|
|
import cocotb
|
|
|
|
from cocotb.clock import Clock
|
|
from cocotb.triggers import Timer, RisingEdge, ReadOnly
|
|
from cocotb.utils import get_sim_time
|
|
from cocotb.drivers import BitDriver
|
|
from cocotb.drivers.avalon import AvalonMaster
|
|
from cocotb.drivers.avalon import AvalonSTPkts as AvalonDriver
|
|
from cocotb.monitors.avalon import AvalonSTPkts as AvalonMonitor
|
|
from cocotb.binary import BinaryValue
|
|
from cocotb.regression import TestFactory
|
|
from cocotb.scoreboard import Scoreboard
|
|
from cocotb.result import TestFailure, TestSuccess, ReturnValue
|
|
|
|
from cocotb.generators.byte import random_data, get_bytes
|
|
from cocotb.generators.bit import wave, intermittent_single_cycles, random_50_percent
|
|
|
|
import lfsr_test
|
|
|
|
class TestModelTB(object):
|
|
# For each test initialise...
|
|
def __init__(self, dut):
|
|
# define the dut
|
|
self.dut = dut
|
|
|
|
# Define the testing modules
|
|
self.lfsr_tests = lfsr_test.tests(self.dut)
|
|
|
|
# This is a coroutine that will be used to reset the test bench at the start of each test
|
|
@cocotb.coroutine
|
|
def try_system_reset(self, duration=10):
|
|
print("INFO: Sending reset to components under test")
|
|
yield RisingEdge(self.dut.clk)
|
|
self.dut.rst <= BinaryValue(1, 1, False)
|
|
yield RisingEdge(self.dut.clk)
|
|
|
|
self.dut.lfsr_enable <= BinaryValue(0, 1, False)
|
|
self.dut.seed <= BinaryValue(0, 128, False)
|
|
|
|
yield Timer(duration)
|
|
yield RisingEdge(self.dut.clk)
|
|
self.dut.rst <= BinaryValue(0, 1, False)
|
|
print("INFO: Reset complete")
|
|
|
|
@cocotb.coroutine
|
|
def run_test(dut, test_selection):
|
|
# Fork the clock process
|
|
print("INFO: Forking clock for sim")
|
|
cocotb.fork(Clock(dut.clk, 10000).start()) # 10000 has been chosen arbirtarily
|
|
|
|
# Give the class a shorthand and set it up
|
|
print("INFO: Importing test class")
|
|
tb = TestModelTB(dut)
|
|
|
|
# Reset component to bring to known state
|
|
yield RisingEdge(dut.clk)
|
|
yield tb.try_system_reset()
|
|
|
|
print("INFO: Determining whch test to run")
|
|
# Determine which test to perform
|
|
test_suite = test_selection.split()[0]
|
|
test_chosen = test_selection.split()[1]
|
|
|
|
print("INFO: Selecting test suite: " + test_suite)
|
|
print("INFO: Selecting test to run: " + test_chosen)
|
|
if test_suite == "lfsr_test":
|
|
if test_chosen == "does_it_run_test":
|
|
yield tb.lfsr_tests.does_it_run_test()
|
|
else:
|
|
raise Exception("Invalid test selected")
|
|
else:
|
|
raise Exception("Invalid test suite selected")
|
|
|
|
# Define the regression tests
|
|
factory = TestFactory(run_test)
|
|
factory.add_option("test_selection", ["lfsr_test does_it_run_test"])
|
|
|
|
factory.generate_tests() |