66 lines
2.8 KiB
Python
66 lines
2.8 KiB
Python
"""Render jitter must not silently lower the requested capture rate."""
|
|
import importlib
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def cadence(monkeypatch):
|
|
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon"))
|
|
return importlib.import_module("scheduling_policy").CaptureCadence
|
|
|
|
|
|
def test_ten_hz_capture_survives_sixteen_hz_render_quantization(cadence):
|
|
clock = cadence(10, 0.)
|
|
admitted = [i/16 for i in range(1, 161) if clock.due(i/16)]
|
|
assert len(admitted) == 100
|
|
assert all(0 <= actual - (i+1)/10 < 1/16 + 1e-9
|
|
for i, actual in enumerate(admitted))
|
|
assert set(round(b-a, 8) for a, b in zip(admitted, admitted[1:], strict=False)) == {.0625, .125}
|
|
|
|
|
|
def test_overload_and_pause_discard_missed_slots_without_a_burst(cadence):
|
|
clock = cadence(10, 100.)
|
|
assert not clock.due(100.05)
|
|
assert clock.due(102.035)
|
|
assert not clock.due(102.035)
|
|
assert not clock.due(102.05)
|
|
assert clock.due(102.1)
|
|
assert not clock.due(102.1)
|
|
# A long operator pause creates no queued frames or catch-up workload.
|
|
assert clock.due(500.07)
|
|
assert not clock.due(500.08)
|
|
assert clock.due(500.11)
|
|
|
|
|
|
def test_invalid_clocks_and_rates_are_rejected(cadence):
|
|
for rate in (0, -1, float("nan"), float("inf"), True):
|
|
with pytest.raises(ValueError):
|
|
cadence(rate, 0.)
|
|
with pytest.raises(ValueError):
|
|
cadence(10, float("nan"))
|
|
with pytest.raises(ValueError):
|
|
cadence(10, 0.).due(float("nan"))
|
|
|
|
|
|
def test_physics_catchup_has_headroom_for_acquisition_without_changing_clocks(monkeypatch):
|
|
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon"))
|
|
build = importlib.import_module("scheduling_policy").build_scheduling_policy
|
|
settings = dict(continuous=True, physics_dt=1/60, capture_hz=10, main_loop_hz=30)
|
|
candidate = build(**settings)
|
|
prior = build(**settings, catch_up_mode="sensor-period-catchup")
|
|
assert candidate["physics_dt_seconds"] == prior["physics_dt_seconds"] == 1/60
|
|
assert candidate["capture_hz"] == prior["capture_hz"] == 10
|
|
assert candidate["freshness_clock"] == prior["freshness_clock"]
|
|
assert candidate["min_simulation_frame_rate_hz"] == 5
|
|
assert candidate["max_physics_steps_per_update"] == 12
|
|
assert candidate["max_integrated_seconds_per_update"] == pytest.approx(.2)
|
|
# A measured ~125ms loop needs 7 or 8 steps. The former six-step
|
|
# clamp discarded time even though there was room to integrate it.
|
|
demanded = [7, 8, 7, 8]
|
|
assert sum(min(n, prior["max_physics_steps_per_update"]) for n in demanded) == 24
|
|
assert sum(min(n, candidate["max_physics_steps_per_update"]) for n in demanded) == 30
|
|
legacy = build(**{**settings, "continuous":False})
|
|
assert legacy["min_simulation_frame_rate_hz"] == 1
|