From 2fd6dedddb912901076cdb858b56e2c590ea619e Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 14 Jan 2023 00:05:50 -0500 Subject: [PATCH] Fix failing tests due to floating point imprecision get_sim_time can return floating point values. This will cause tests to fail since there is an epsilon of error. Fix this by timing things in steps (which is always an int). Fixes: 0495ae3 ("Add TX MAC (most of it)") Signed-off-by: Sean Anderson --- tb/axis_mii_tx.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tb/axis_mii_tx.py b/tb/axis_mii_tx.py index 342d773..15571cd 100644 --- a/tb/axis_mii_tx.py +++ b/tb/axis_mii_tx.py @@ -10,7 +10,7 @@ from cocotb.binary import BinaryValue from cocotb.clock import Clock from cocotb.regression import TestFactory from cocotb.triggers import ClockCycles, Edge, FallingEdge, First, RisingEdge, Timer -from cocotb.utils import get_sim_time +from cocotb.utils import get_sim_time, get_sim_steps from . import axis_replay_buffer from .pcs_rx import mii_recv_packet @@ -191,12 +191,12 @@ async def test_send(mac, ratio): recv = await cocotb.start(recv_packet(mac)) # Measure the IPG to ensure throughput - start = get_sim_time('ns') + start = get_sim_time('step') while not mac.mii_tx_en.value: await RisingEdge(mac.clk) # The first IPG may not be exact if i: - assert get_sim_time('ns') - start == 12 * 80 - 4 + assert get_sim_time('step') - start == get_sim_steps(12 * 80 - 4, 'ns') compare(await recv.join(), packet) assert await status.join() == Status.OK @@ -254,9 +254,10 @@ async def test_backoff(mac): then = None for n in range(collisions): await restart(mac, 0) - now = get_sim_time('ns') + now = get_sim_time('step') if then is not None: - assert now - then <= (8 + 4 + 12 + 2 ** min(n, 10)) * BYTE_TIME_NS + assert now - then <= \ + get_sim_steps((8 + 4 + 12 + 2 ** min(n, 10)) * BYTE_TIME_NS, 'ns') then = now if collisions == 16: