67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
import sys
|
|
import cocotb
|
|
|
|
from cocotb.clock import Clock
|
|
from cocotb.triggers import Timer, RisingEdge, ReadOnly
|
|
from cocotb.drivers import BitDriver
|
|
from cocotb.binary import BinaryValue
|
|
from cocotb.result import TestFailure, TestSuccess, ReturnValue
|
|
|
|
class tests:
|
|
def __init__(self, dut):
|
|
self.dut = dut
|
|
|
|
@cocotb.coroutine
|
|
def does_it_run_test(self):
|
|
# This test will let the lfsr run for a bit.
|
|
# We will verify the every time a valid goes high the value outputted is different from the previous value
|
|
# This is testing that some operation is happening
|
|
|
|
print("INFO: Performing does_it_run_test test")
|
|
yield RisingEdge(self.dut.clk)
|
|
|
|
print("INFO: Setting our test passing conditon to true")
|
|
test_passing = True
|
|
|
|
print("INFO: Making the seed 0xDEADBEEF")
|
|
self.dut.seed <= BinaryValue(0xDEADBEEF, 32, False)
|
|
yield RisingEdge(self.dut.clk)
|
|
|
|
print("INFO: Pushing rst high to lock in the seed")
|
|
self.dut.rst <= BinaryValue(1, 1, False)
|
|
yield RisingEdge(self.dut.clk)
|
|
|
|
print("INFO: Pushing rst low for operation")
|
|
self.dut.rst <= BinaryValue(0, 1, False)
|
|
yield RisingEdge(self.dut.clk)
|
|
|
|
print("INFO: Pushing lfsr_enable high")
|
|
self.dut.lfsr_enable <= BinaryValue(1, 1, False)
|
|
yield RisingEdge(self.dut.clk)
|
|
|
|
print("INFO: Establishing value to check against's initial value to 0xDEADBEEF")
|
|
lfsr_data = BinaryValue(0xDEADBEEF, 32, False)
|
|
|
|
print("INFO: Running for 100 cycles")
|
|
for i in range(100):
|
|
yield RisingEdge(self.dut.clk)
|
|
|
|
# Checking that the lfsr output has changed after a clock cycle
|
|
if self.dut.lfsr_output == lfsr_data:
|
|
# Mark the first time that this did not work
|
|
if test_passing == True:
|
|
print("ERROR: Test failed at lfsr loop %d", i)
|
|
print("ERROR: Old lfsr value was %d", lfsr_data)
|
|
print("ERROR: Dut lfsr value was %d", self.dut.lfsr_output)
|
|
|
|
# Now we change the "passing" bool to false
|
|
test_passing = False
|
|
|
|
# Making value to check the current value of the lfsr's output
|
|
lfsr_data = self.dut.lfsr_output.value
|
|
|
|
print("INFO: Evaluating result")
|
|
if test_passing == True:
|
|
raise TestSuccess("INFO: Each cycle of LFSR was distinct")
|
|
else:
|
|
raise TestFailure("INFO: Each cycle of LFSR was not distinct") |