From 02ce168c637906790a481a472887d4ac754c8d08 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Mon, 24 Jul 2023 01:01:54 -0700 Subject: [PATCH] Improve PTP-related tests Signed-off-by: Alex Forencich --- tb/axis_baser_rx_64/test_axis_baser_rx_64.py | 1 + tb/axis_baser_tx_64/test_axis_baser_tx_64.py | 2 ++ tb/axis_gmii_rx/test_axis_gmii_rx.py | 1 + tb/axis_gmii_tx/test_axis_gmii_tx.py | 1 + tb/axis_xgmii_rx_32/test_axis_xgmii_rx_32.py | 1 + tb/axis_xgmii_rx_64/test_axis_xgmii_rx_64.py | 1 + tb/axis_xgmii_tx_32/test_axis_xgmii_tx_32.py | 2 ++ tb/axis_xgmii_tx_64/test_axis_xgmii_tx_64.py | 2 ++ tb/eth_mac_10g/test_eth_mac_10g.py | 16 +++++++++++++++ tb/eth_mac_10g_fifo/test_eth_mac_10g_fifo.py | 20 +++++++++++++++++++ tb/eth_mac_1g/test_eth_mac_1g.py | 2 ++ tb/eth_mac_phy_10g/test_eth_mac_phy_10g.py | 16 +++++++++++++++ .../test_eth_mac_phy_10g_fifo.py | 20 +++++++++++++++++++ 13 files changed, 85 insertions(+) diff --git a/tb/axis_baser_rx_64/test_axis_baser_rx_64.py b/tb/axis_baser_rx_64/test_axis_baser_rx_64.py index da1fa16a9..38a2e29c3 100644 --- a/tb/axis_baser_rx_64/test_axis_baser_rx_64.py +++ b/tb/axis_baser_rx_64/test_axis_baser_rx_64.py @@ -107,6 +107,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 diff --git a/tb/axis_baser_tx_64/test_axis_baser_tx_64.py b/tb/axis_baser_tx_64/test_axis_baser_tx_64.py index 8a746b98d..7888712a5 100644 --- a/tb/axis_baser_tx_64/test_axis_baser_tx_64.py +++ b/tb/axis_baser_tx_64/test_axis_baser_tx_64.py @@ -114,6 +114,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() @@ -163,6 +164,7 @@ async def run_test_alignment(dut, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() diff --git a/tb/axis_gmii_rx/test_axis_gmii_rx.py b/tb/axis_gmii_rx/test_axis_gmii_rx.py index 19c5fbc65..07605cf7e 100644 --- a/tb/axis_gmii_rx/test_axis_gmii_rx.py +++ b/tb/axis_gmii_rx/test_axis_gmii_rx.py @@ -121,6 +121,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12, enable_ tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 diff --git a/tb/axis_gmii_tx/test_axis_gmii_tx.py b/tb/axis_gmii_tx/test_axis_gmii_tx.py index 75cd31bc0..93fad4bd9 100644 --- a/tb/axis_gmii_tx/test_axis_gmii_tx.py +++ b/tb/axis_gmii_tx/test_axis_gmii_tx.py @@ -126,6 +126,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12, enable_ tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() diff --git a/tb/axis_xgmii_rx_32/test_axis_xgmii_rx_32.py b/tb/axis_xgmii_rx_32/test_axis_xgmii_rx_32.py index 753920696..d77a31310 100644 --- a/tb/axis_xgmii_rx_32/test_axis_xgmii_rx_32.py +++ b/tb/axis_xgmii_rx_32/test_axis_xgmii_rx_32.py @@ -92,6 +92,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 diff --git a/tb/axis_xgmii_rx_64/test_axis_xgmii_rx_64.py b/tb/axis_xgmii_rx_64/test_axis_xgmii_rx_64.py index 804c13325..0bd4cf6b9 100644 --- a/tb/axis_xgmii_rx_64/test_axis_xgmii_rx_64.py +++ b/tb/axis_xgmii_rx_64/test_axis_xgmii_rx_64.py @@ -96,6 +96,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 diff --git a/tb/axis_xgmii_tx_32/test_axis_xgmii_tx_32.py b/tb/axis_xgmii_tx_32/test_axis_xgmii_tx_32.py index 458c24f8b..da8c52f3d 100644 --- a/tb/axis_xgmii_tx_32/test_axis_xgmii_tx_32.py +++ b/tb/axis_xgmii_tx_32/test_axis_xgmii_tx_32.py @@ -99,6 +99,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() @@ -144,6 +145,7 @@ async def run_test_alignment(dut, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() diff --git a/tb/axis_xgmii_tx_64/test_axis_xgmii_tx_64.py b/tb/axis_xgmii_tx_64/test_axis_xgmii_tx_64.py index f80623a4e..29189b382 100644 --- a/tb/axis_xgmii_tx_64/test_axis_xgmii_tx_64.py +++ b/tb/axis_xgmii_tx_64/test_axis_xgmii_tx_64.py @@ -103,6 +103,7 @@ async def run_test(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() @@ -152,6 +153,7 @@ async def run_test_alignment(dut, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() diff --git a/tb/eth_mac_10g/test_eth_mac_10g.py b/tb/eth_mac_10g/test_eth_mac_10g.py index 85b794dd3..c4363d464 100644 --- a/tb/eth_mac_10g/test_eth_mac_10g.py +++ b/tb/eth_mac_10g/test_eth_mac_10g.py @@ -168,6 +168,7 @@ async def run_test_rx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 @@ -207,6 +208,7 @@ async def run_test_tx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() @@ -245,10 +247,24 @@ async def run_test_tx_alignment(dut, payload_data=None, ifg=12): for test_data in test_frames: rx_frame = await tb.xgmii_sink.recv() + ptp_ts = await tb.tx_ptp_ts_sink.recv() + + ptp_ts_ns = int(ptp_ts.ts) / 2**16 + + rx_frame_sfd_ns = get_time_from_sim_steps(rx_frame.sim_time_sfd, "ns") + + if rx_frame.start_lane == 4: + # start in lane 4 reports 1 full cycle delay, so subtract half clock period + rx_frame_sfd_ns -= 3.2 + + tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) + tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() assert rx_frame.ctrl is None + assert abs(rx_frame_sfd_ns - ptp_ts_ns - tb.clk_period) < 0.01 start_lane.append(rx_frame.start_lane) diff --git a/tb/eth_mac_10g_fifo/test_eth_mac_10g_fifo.py b/tb/eth_mac_10g_fifo/test_eth_mac_10g_fifo.py index 5d71bcce1..eadfe14fa 100644 --- a/tb/eth_mac_10g_fifo/test_eth_mac_10g_fifo.py +++ b/tb/eth_mac_10g_fifo/test_eth_mac_10g_fifo.py @@ -129,6 +129,7 @@ async def run_test_rx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 @@ -172,6 +173,7 @@ async def run_test_tx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() @@ -197,6 +199,10 @@ async def run_test_tx_alignment(dut, payload_data=None, ifg=12): await tb.reset() + tb.log.info("Wait for PTP CDC lock") + while not dut.tx_ptp.tx_ptp_cdc.locked.value.integer: + await RisingEdge(dut.tx_clk) + for length in range(60, 92): for k in range(10): @@ -210,10 +216,24 @@ async def run_test_tx_alignment(dut, payload_data=None, ifg=12): for test_data in test_frames: rx_frame = await tb.xgmii_sink.recv() + ptp_ts = await tb.tx_ptp_ts_sink.recv() + + ptp_ts_ns = int(ptp_ts.ts_96) / 2**16 + + rx_frame_sfd_ns = get_time_from_sim_steps(rx_frame.sim_time_sfd, "ns") + + if rx_frame.start_lane == 4: + # start in lane 4 reports 1 full cycle delay, so subtract half clock period + rx_frame_sfd_ns -= 3.2 + + tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) + tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() assert rx_frame.ctrl is None + assert abs(rx_frame_sfd_ns - ptp_ts_ns - tb.clk_period) < tb.clk_period start_lane.append(rx_frame.start_lane) diff --git a/tb/eth_mac_1g/test_eth_mac_1g.py b/tb/eth_mac_1g/test_eth_mac_1g.py index 63ca1f32e..ab0a48919 100644 --- a/tb/eth_mac_1g/test_eth_mac_1g.py +++ b/tb/eth_mac_1g/test_eth_mac_1g.py @@ -213,6 +213,7 @@ async def run_test_rx(dut, payload_lengths=None, payload_data=None, ifg=12, enab tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 @@ -254,6 +255,7 @@ async def run_test_tx(dut, payload_lengths=None, payload_data=None, ifg=12, enab tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() diff --git a/tb/eth_mac_phy_10g/test_eth_mac_phy_10g.py b/tb/eth_mac_phy_10g/test_eth_mac_phy_10g.py index 15a7ed501..bda5fec48 100644 --- a/tb/eth_mac_phy_10g/test_eth_mac_phy_10g.py +++ b/tb/eth_mac_phy_10g/test_eth_mac_phy_10g.py @@ -142,6 +142,7 @@ async def run_test_rx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 @@ -181,6 +182,7 @@ async def run_test_tx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() @@ -219,10 +221,24 @@ async def run_test_tx_alignment(dut, payload_data=None, ifg=12): for test_data in test_frames: rx_frame = await tb.serdes_sink.recv() + ptp_ts = await tb.tx_ptp_ts_sink.recv() + + ptp_ts_ns = int(ptp_ts.ts) / 2**16 + + rx_frame_sfd_ns = get_time_from_sim_steps(rx_frame.sim_time_sfd, "ns") + + if rx_frame.start_lane == 4: + # start in lane 4 reports 1 full cycle delay, so subtract half clock period + rx_frame_sfd_ns -= 3.2 + + tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) + tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() assert rx_frame.ctrl is None + assert abs(rx_frame_sfd_ns - ptp_ts_ns - tb.clk_period*5) < 0.01 start_lane.append(rx_frame.start_lane) diff --git a/tb/eth_mac_phy_10g_fifo/test_eth_mac_phy_10g_fifo.py b/tb/eth_mac_phy_10g_fifo/test_eth_mac_phy_10g_fifo.py index 7c85a624a..70abb425b 100644 --- a/tb/eth_mac_phy_10g_fifo/test_eth_mac_phy_10g_fifo.py +++ b/tb/eth_mac_phy_10g_fifo/test_eth_mac_phy_10g_fifo.py @@ -150,6 +150,7 @@ async def run_test_rx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("RX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("TX frame SFD sim time: %f ns", tx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(ptp_ts_ns - tx_frame_sfd_ns)) assert rx_frame.tdata == test_data assert frame_error == 0 @@ -193,6 +194,7 @@ async def run_test_tx(dut, payload_lengths=None, payload_data=None, ifg=12): tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() @@ -218,6 +220,10 @@ async def run_test_tx_alignment(dut, payload_data=None, ifg=12): await tb.reset() + tb.log.info("Wait for PTP CDC lock") + while not dut.tx_ptp.tx_ptp_cdc.locked.value.integer: + await RisingEdge(dut.tx_clk) + for length in range(60, 92): for k in range(10): @@ -231,10 +237,24 @@ async def run_test_tx_alignment(dut, payload_data=None, ifg=12): for test_data in test_frames: rx_frame = await tb.serdes_sink.recv() + ptp_ts = await tb.tx_ptp_ts_sink.recv() + + ptp_ts_ns = int(ptp_ts.ts_96) / 2**16 + + rx_frame_sfd_ns = get_time_from_sim_steps(rx_frame.sim_time_sfd, "ns") + + if rx_frame.start_lane == 4: + # start in lane 4 reports 1 full cycle delay, so subtract half clock period + rx_frame_sfd_ns -= 3.2 + + tb.log.info("TX frame PTP TS: %f ns", ptp_ts_ns) + tb.log.info("RX frame SFD sim time: %f ns", rx_frame_sfd_ns) + tb.log.info("Difference: %f ns", abs(rx_frame_sfd_ns - ptp_ts_ns)) assert rx_frame.get_payload() == test_data assert rx_frame.check_fcs() assert rx_frame.ctrl is None + assert abs(rx_frame_sfd_ns - ptp_ts_ns - tb.clk_period*5) < tb.clk_period start_lane.append(rx_frame.start_lane)