forked from f4pga/f4pga-arch-defs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from elmsfu/cocotb_tests
Add Cocotb test framework for testing sim.v files
- Loading branch information
Showing
8 changed files
with
168 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
include $(TOP_DIR)/make/inc/env.mk | ||
|
||
VERILOG_SOURCES = $(CURDIR)/../alut.sim.v | ||
TOPLEVEL := ALUT | ||
MODULE := test_alut | ||
COMPILE_ARGS += -PALUT.INIT=64\'b0101010101010101010101010101010101010101010101010101010101010101 | ||
|
||
include $(COCOTB)/makefiles/Makefile.inc | ||
|
||
PYTHONPATH := $(CURDIR):$(PYTHONPATH):$(PYTHON_DYNLIBDIR) | ||
|
||
include $(COCOTB)/makefiles/Makefile.sim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Test alut to cover all Nlut | ||
""" | ||
|
||
import cocotb | ||
from cocotb.binary import BinaryValue | ||
from cocotb.regression import TestFactory | ||
from cocotb.result import TestFailure | ||
from cocotb.triggers import Timer | ||
|
||
|
||
class LutModel(object): | ||
""" | ||
Model for LUT | ||
""" | ||
def __init__(self, init, inputs): | ||
self.init = init | ||
self.inputs = BinaryValue(inputs) | ||
|
||
@property | ||
def O5(self): | ||
return eval(self.init.binstr[-1-self.inputs.integer]) | ||
|
||
@property | ||
def O6(self): | ||
return eval(self.init.binstr[-1-self.inputs.integer]) | ||
|
||
@cocotb.coroutine | ||
def lut_basic_test(dut, inputs): | ||
"""Test for LUT options""" | ||
|
||
yield Timer(1) | ||
|
||
for i in range(6): | ||
setattr(dut, 'A%d'%(i + 1), inputs & (1 << i)) | ||
yield Timer(1) | ||
model = LutModel(dut.INIT.value, inputs) | ||
|
||
if dut.O5 != model.O5 or dut.O6 != model.O6: | ||
raise TestFailure('No match (dut:model) O5(%d:%d) O6(%d:%d)' % \ | ||
(dut.O5, model.O5, dut.O6, model.O6)) | ||
else: | ||
dut._log.info('Match') | ||
|
||
|
||
factory = TestFactory(lut_basic_test) | ||
input_permutations = range(2**6) | ||
factory.add_option("inputs", input_permutations) | ||
factory.generate_tests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[MESSAGES CONTROL] | ||
enable=bad-indentation,eval-used,invalid-name,missing-docstring,old-style-class,protected-access,unused-import | ||
|
||
[REPORTS] | ||
output-format=colorized | ||
reports=no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
include $(TOP_DIR)/make/inc/env.mk | ||
|
||
VERILOG_SOURCES = $(CURDIR)/../mux2.sim.v | ||
TOPLEVEL := MUX2 | ||
MODULE := test_mux2 | ||
|
||
include $(COCOTB)/makefiles/Makefile.inc | ||
|
||
PYTHONPATH := $(CURDIR):$(PYTHONPATH):$(PYTHON_DYNLIBDIR) | ||
|
||
include $(COCOTB)/makefiles/Makefile.sim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Test mux2 correctness | ||
""" | ||
|
||
import cocotb | ||
from cocotb.regression import TestFactory | ||
from cocotb.result import TestFailure | ||
from cocotb.triggers import Timer | ||
|
||
|
||
@cocotb.coroutine | ||
def mux2_basic_test(dut, inputs=(1, 0, 0)): | ||
"""Test for MUX2 options.""" | ||
|
||
yield Timer(2) | ||
I0, I1, S0 = inputs | ||
dut.I0 = I0 | ||
dut.I1 = I1 | ||
dut.S0 = S0 | ||
if S0: | ||
expected = I1 | ||
else: | ||
expected = I0 | ||
yield Timer(2) | ||
|
||
if dut.O != expected: | ||
raise TestFailure( | ||
'Result is incorrect for I0(%d) I1(%d) S0(%d): %s(O) != %s (expected)'\ | ||
% (I0, I1, S0, dut.O, expected)) | ||
else: | ||
dut._log.info('I0(%d) I1(%d) S0(%d) output(%d) Ok!'%(I0, I1, S0, dut.O)) | ||
|
||
|
||
factory = TestFactory(mux2_basic_test) | ||
input_permutations = [(x, y, z) for x in [0, 1] for y in [0, 1] for z in [0, 1]] | ||
factory.add_option("inputs", input_permutations) | ||
factory.generate_tests() |