Skip to content

Commit 21bc5ba

Browse files
committed
test/test_xgmii_phy: Update/Cleanup.
1 parent 77c9fec commit 21bc5ba

File tree

2 files changed

+41
-39
lines changed

2 files changed

+41
-39
lines changed

test/test_crc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from litex.gen.sim import *
1616

17-
from .test_stream import *
17+
from .test_stream import mask_last_be, StreamPacket, stream_inserter, stream_collector, compare_packets
1818

1919
# Layout -------------------------------------------------------------------------------------------
2020

test/test_xgmii_phy.py

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
from litex.soc.interconnect.stream import *
1515
from liteeth.phy.xgmii import LiteEthPHYXGMII, LiteEthPHYXGMIIRX
1616

17-
from .test_stream import StreamPacket, stream_inserter, stream_collector, \
18-
compare_packets
17+
from .test_stream import StreamPacket, stream_inserter, stream_collector, compare_packets
18+
19+
# Helper -------------------------------------------------------------------------------------------
1920

2021
def mask_last_be(dw, data, last_be):
2122
"""Mark some data by a last_be data qualifier. The rest of the data
@@ -30,9 +31,10 @@ def mask_last_be(dw, data, last_be):
3031

3132
return masked_data
3233

34+
# XGMII Collector ----------------------------------------------------------------------------------
35+
3336
class XGMIICollector:
34-
def __init__(self, min_interframegap=12, tolerate_dic=True,
35-
debug_print=False):
37+
def __init__(self, min_interframegap=12, tolerate_dic=True, debug_print=False):
3638
# Minimum IFG legal to be accepted on the XGMII interface (excluding
3739
# DIC, if tolerated). On the receiving send, when accounting for
3840
# potential IFG shrinkage and allowing the minimum receive IFG as
@@ -230,6 +232,8 @@ def collect(self, xgmii_interface, tap_signals="tx", stop_cond=None):
230232

231233
self.collecting = False
232234

235+
# XGMII 64b CSV Reader -----------------------------------------------------------------------------
236+
233237
class XGMII64bCSVReader:
234238
def __init__(self, filename, extract_signals_pattern="rx",
235239
complete_trailing_transaction=True):
@@ -380,10 +384,11 @@ def inject(self, xgmii_interface, stop_cond=None):
380384
yield xgmii_interface.rx_data.eq(0x0707070707070707)
381385
yield
382386

387+
# Test XGMII PHY -----------------------------------------------------------------------------------
383388

384389
class TestXGMIIPHY(unittest.TestCase):
385390
def test_xgmii_rx(self):
386-
# Read XGMII data from the CSV file
391+
# Read XGMII data from the CSV file.
387392
csv_file = Path(__file__).parent / "assets" / "xgmii_bus_capture.csv"
388393
xgmii_injector = XGMII64bCSVReader(
389394
csv_file.resolve(),
@@ -393,16 +398,16 @@ def test_xgmii_rx(self):
393398
# Collect the XGMII transactions from the reader with a minimum
394399
# inter-frame gap of 5 (accounted for potential IFG shrinkage).
395400
xgmii_collector = XGMIICollector(
396-
min_interframegap=5,
397-
tolerate_dic=False,
398-
debug_print=True,
401+
min_interframegap = 5,
402+
tolerate_dic = False,
403+
debug_print = True,
399404
)
400405

401-
# XGMII interface
406+
# XGMII interface.
402407
xgmii_interface = Record([
403-
("rx_ctl", 8),
408+
("rx_ctl", 8),
404409
("rx_data", 64),
405-
("tx_ctl", 8),
410+
("tx_ctl", 8),
406411
("tx_data", 64),
407412
])
408413

@@ -414,27 +419,26 @@ def test_xgmii_rx(self):
414419

415420
recvd_packets = []
416421
run_simulation(
417-
dut,
418-
[
422+
dut, [
419423
xgmii_injector.inject(
420424
xgmii_interface,
421425
),
422426
xgmii_collector.collect(
423427
xgmii_interface,
424-
tap_signals="rx",
425-
stop_cond=lambda: xgmii_injector.done() \
428+
tap_signals = "rx",
429+
stop_cond = lambda: xgmii_injector.done() \
426430
and xgmii_collector.current_packet is None,
427431
),
428432
stream_collector(
429433
dut.source,
430-
dest=recvd_packets,
431-
stop_cond=xgmii_injector.done,
432-
seed=42,
433-
debug_print=True,
434+
dest = recvd_packets,
435+
stop_cond = xgmii_injector.done,
436+
seed = 42,
437+
debug_print = True,
434438
# The XGMII PHY RX part deliberately does not support a
435439
# deasserted ready signal. The sink is assumed to be always
436440
# ready.
437-
ready_rand=0,
441+
ready_rand = 0,
438442
),
439443
],
440444
)
@@ -471,36 +475,35 @@ def test_xgmii_stream_loopback(self):
471475
# Collect the XGMII transactions from the CSV reader with a minimum
472476
# inter-frame gap of 5 (accounted for potential IFG shrinkage).
473477
xgmii_rx_collector = XGMIICollector(
474-
min_interframegap=5,
475-
tolerate_dic=False,
476-
477-
debug_print=True
478+
min_interframegap = 5,
479+
tolerate_dic = False,
480+
debug_print = True
478481
)
479482

480483
# Collect the XGMII transactions from the TX PHY with a minimum
481484
# inter-frame gap of 5. As a dumb loopback (akin to the behavior of a
482485
# repeater) this is the smallest IPG value which may be put on the wire
483486
# again.
484487
xgmii_tx_collector = XGMIICollector(
485-
min_interframegap=12,
486-
tolerate_dic=True,
487-
debug_print=True
488+
min_interframegap = 12,
489+
tolerate_dic = True,
490+
debug_print = True
488491
)
489492

490493
class DUT(Module):
491494
def __init__(self):
492495
# XGMII signals
493496
self.xgmii_interface = Record([
494-
("rx_ctl", 8),
497+
("rx_ctl", 8),
495498
("rx_data", 64),
496-
("tx_ctl", 8),
499+
("tx_ctl", 8),
497500
("tx_data", 64),
498501
])
499502

500503
# PHY with TX and RX side
501504
self.submodules.ethphy = ClockDomainsRenamer({
502-
"eth_tx": "sys",
503-
"eth_rx": "sys",
505+
"eth_tx" : "sys",
506+
"eth_rx" : "sys",
504507
})(LiteEthPHYXGMII(
505508
Record([("rx", 1), ("tx", 1)]),
506509
self.xgmii_interface,
@@ -524,25 +527,24 @@ def __init__(self):
524527

525528
dut = DUT()
526529
run_simulation(
527-
dut,
528-
[
530+
dut, [
529531
xgmii_rx_collector.collect(
530532
dut.xgmii_interface,
531-
tap_signals="rx",
532-
stop_cond=lambda: xgmii_injector.done() \
533+
tap_signals = "rx",
534+
stop_cond = lambda: xgmii_injector.done() \
533535
and xgmii_rx_collector.current_packet is None,
534536
),
535537
xgmii_tx_collector.collect(
536538
dut.xgmii_interface,
537-
tap_signals="tx",
538-
stop_cond=lambda: xgmii_injector.done() \
539+
tap_signals = "tx",
540+
stop_cond = lambda: xgmii_injector.done() \
539541
and xgmii_tx_collector.current_packet is None \
540542
and len(xgmii_tx_collector.packets) \
541543
>= len(xgmii_rx_collector.packets),
542544
),
543545
xgmii_injector.inject(
544546
dut.xgmii_interface,
545-
stop_cond=lambda: not xgmii_rx_collector.collecting \
547+
stop_cond = lambda: not xgmii_rx_collector.collecting \
546548
and not xgmii_tx_collector.collecting,
547549
),
548550
],

0 commit comments

Comments
 (0)