Files
courier-emu/tests/test_worker_poll_deadline_cache.py
Cryan209 d138dc27b5 Extend Courier firmware, line transport, and diagnostics
Add captured 3453 flash boot and modem data-path support, a local browser
console, and an Apple USB Modem line backend. Improve I-modem and Quad
firmware timing, UART framing, and SIP/RTP media handling.

Include regression tests, compact hardware evidence, and documentation
for the measured link behavior. Keep pytest discovery scoped to tests/.
2026-11-23 12:17:28 +13:00

25 lines
1.0 KiB
Python

import random
import pytest
from courier_emu.worker_poll import first_instruction_at_tick
@pytest.mark.parametrize('ratio', [1 / 4, 1 / 3, 1 / 2, 0.2964705882352941, 1.0, 1.5])
def test_cached_inverse_is_earliest_exact_float_tick(ratio):
rng = random.Random(21186)
for tick in [0, 1, 2, 3, 100, 2**32, 2**40, *[rng.randrange(10**12) for _ in range(300)]]:
at = first_instruction_at_tick(tick, ratio)
assert int(at * ratio) >= tick
assert at == 0 or int((at - 1) * ratio) < tick
assert first_instruction_at_tick(tick, ratio) == at
def test_clock_discovery_does_not_reuse_old_ratio():
first_instruction_at_tick.cache_clear()
assert first_instruction_at_tick(100, .25) == 400
assert first_instruction_at_tick(100, .5) == 200
assert first_instruction_at_tick(100, .25) == 400
assert first_instruction_at_tick.cache_info().hits == 1
for n in range(1000):
first_instruction_at_tick(n, .25)
assert first_instruction_at_tick.cache_info().currsize == 64