-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_axi_adder.py
124 lines (99 loc) · 3.57 KB
/
test_axi_adder.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import json
import logging
import random
from slvcodec import cocotb_wrapper as cocotb
from slvcodec.cocotb_wrapper import triggers, result
from slvcodec import cocotb_dut
from slvcodec import test_utils as slvcodec_test_utils
from slvcodec import config as slvcodec_config
from axilent.examples import axi_adder
from axilent import cocotb_handler, config, test_utils
logger = logging.getLogger(__name__)
testoutput_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'test_outputs'))
fusesoc_config_filename = config.get_fusesoc_config_filename()
def test_axi_adder():
tests = get_tests()
vu = slvcodec_config.setup_vunit(argv=['--dont-catch-exceptions'])
for coretest in tests:
slvcodec_test_utils.register_coretest_with_vunit(
vu, coretest, testoutput_dir, fusesoc_config_filename=fusesoc_config_filename)
all_ok = vu._main(post_run=None)
assert all_ok
@cocotb.coroutine
async def axi_adder_test(handler):
comm = axi_adder.AxiAdderComm(address_offset=0, handler=handler)
n_data = 100
max_int = pow(2, 16)-1
for i in range(n_data):
inta = random.randint(0, max_int)
intb = random.randint(0, max_int)
intc = await comm.add_numbers_async(inta, intb)
assert intc == inta + intb
raise result.TestSuccess()
def make_handler(dut):
axi_handler = cocotb_handler.CocotbHandler(dut.clk, m2s=dut.m2s, s2m=dut.s2m)
axi_handler.start()
return axi_handler
@cocotb.test()
async def axi_adder_test_top(dut):
params_filename = os.environ['test_params_filename']
with open(params_filename) as f:
params = json.load(f)
mapping = params['mapping']
cocotb_dut.apply_mapping(dut, mapping, separator='_')
cocotb.fork(slvcodec_test_utils.clock(dut.clk))
dut.reset <= 0
await triggers.RisingEdge(dut.clk)
dut.reset <= 1
await triggers.RisingEdge(dut.clk)
dut.reset <= 0
await triggers.RisingEdge(dut.clk)
axi_handler = make_handler(dut)
await axi_adder_test(axi_handler)
def make_coro(generics, top_params):
async def coro(dut, resolved):
dut.reset <= 0
await triggers.RisingEdge(dut.clk)
dut.reset <= 1
await triggers.RisingEdge(dut.clk)
dut.reset <= 0
axi_handler = make_handler(dut)
await axi_adder_test(axi_handler)
return coro
def make_ftb_test(generics, top_params, resolved):
axi_test = axi_adder.AxiAdderTest()
test = test_utils.DictAxiTest(axi_test)
return test
def get_tests():
def make_test_params(resolved):
return {}
test = {
'core_name': 'axi_adder',
'entity_name': 'axi_adder',
'generics': {'formal': False},
'top_params': {},
'test_module_name': 'test_axi_adder',
'test_params': make_test_params,
'coro': make_coro,
'generator': make_ftb_test,
}
return [test]
def test_cocotb():
test_output_directory = os.path.abspath('axi_adder_cocotb')
tests = get_tests()
for test in tests:
slvcodec_test_utils.run_coretest_with_cocotb(
test, test_output_directory,
fusesoc_config_filename=config.get_fusesoc_config_filename(),
generate_iteratively=False)
def test_pipes():
test_output_directory = os.path.abspath('axi_adder_pipes')
tests = get_tests()
for test in tests:
slvcodec_test_utils.run_coretest_with_pipes(
test, test_output_directory,
fusesoc_config_filename=config.get_fusesoc_config_filename(),
generate_iteratively=False)
if __name__ == '__main__':
test_cocotb()