forked from enjoy-digital/liteeth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_etherbone.py
More file actions
126 lines (104 loc) · 4.64 KB
/
test_etherbone.py
File metadata and controls
126 lines (104 loc) · 4.64 KB
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
125
126
#
# This file is part of LiteEth.
#
# Copyright (c) 2015-2018 Florent Kermarrec <florent@enjoy-digital.fr>
# SPDX-License-Identifier: BSD-2-Clause
import unittest
from migen import *
from litex.soc.interconnect import wishbone
from litex.soc.interconnect.stream_sim import *
from liteeth.common import *
from liteeth.core import LiteEthUDPIPCore
from liteeth.frontend.etherbone import LiteEthEtherbone
from test.model import phy, mac, arp, ip, udp, etherbone
from litex.gen.sim import *
# Constants ----------------------------------------------------------------------------------------
ip_address = 0x12345678
mac_address = 0x12345678abcd
# DUT ----------------------------------------------------------------------------------------------
class DUT(LiteXModule):
def __init__(self, eth_mtu=eth_mtu_default):
self.phy_model = phy.PHY(8, debug=False)
self.mac_model = mac.MAC(self.phy_model, debug=False, loopback=False)
self.arp_model = arp.ARP(self.mac_model, mac_address, ip_address, debug=False)
self.ip_model = ip.IP(self.mac_model, mac_address, ip_address, debug=False, loopback=False)
self.udp_model = udp.UDP(self.ip_model, ip_address, debug=False, loopback=False)
self.etherbone_model = etherbone.Etherbone(self.udp_model, debug=False)
self.core = LiteEthUDPIPCore(self.phy_model, mac_address, ip_address, 100000, eth_mtu=eth_mtu)
self.etherbone = LiteEthEtherbone(self.core.udp, 0x1234)
self.sram = wishbone.SRAM(1024)
self.interconnect = wishbone.InterconnectPointToPoint(self.etherbone.wishbone.bus, self.sram.bus)
# Genrator -----------------------------------------------------------------------------------------
def main_generator(dut):
test_probe = True
test_writes = True
test_reads = True
# test probe
if test_probe:
packet = etherbone.EtherbonePacket()
packet.pf = 1
dut.etherbone_model.send(packet)
yield from dut.etherbone_model.receive()
print("probe: " + str(bool(dut.etherbone_model.rx_packet.pr)))
for i in range(2):
# test writes
if test_writes:
writes_datas = [j for j in range(4)]
writes = etherbone.EtherboneWrites(base_addr=0x1000, datas=writes_datas)
record = etherbone.EtherboneRecord()
record.writes = writes
record.reads = None
record.bca = 0
record.rca = 0
record.rff = 0
record.cyc = 0
record.wca = 0
record.wff = 0
record.byte_enable = 0xf
record.wcount = len(writes_datas)
record.rcount = 0
packet = etherbone.EtherbonePacket()
packet.records = [record]
dut.etherbone_model.send(packet)
for i in range(256):
yield
# test reads
if test_reads:
reads_addrs = [0x1000 + 4*j for j in range(4)]
reads = etherbone.EtherboneReads(base_ret_addr=0x1000, addrs=reads_addrs)
record = etherbone.EtherboneRecord()
record.writes = None
record.reads = reads
record.bca = 0
record.rca = 0
record.rff = 0
record.cyc = 0
record.wca = 0
record.wff = 0
record.byte_enable = 0xf
record.wcount = 0
record.rcount = len(reads_addrs)
packet = etherbone.EtherbonePacket()
packet.records = [record]
dut.etherbone_model.send(packet)
yield from dut.etherbone_model.receive()
loopback_writes_datas = []
loopback_writes_datas = dut.etherbone_model.rx_packet.records.pop().writes.get_datas()
# check resultss
s, l, e = check(writes_datas, loopback_writes_datas)
print("shift " + str(s) + " / length " + str(l) + " / errors " + str(e))
# Test Etherbone -----------------------------------------------------------------------------------
class TestEtherbone(unittest.TestCase):
def test_etherbone(self):
dut = DUT()
generators = {
"sys" : [main_generator(dut)],
"eth_tx" : [dut.phy_model.phy_sink.generator(), dut.phy_model.generator()],
"eth_rx" : [dut.phy_model.phy_source.generator()]
}
clocks = {
"sys": 10,
"eth_rx": 10,
"eth_tx": 10,
}
#run_simulation(dut, generators, clocks, vcd_name="sim.vcd") # FIXME: hanging