Files
HaloKeymind/tools/hil/test_profile_switch_sf_limits.py
T
mikecarper 091c8d8324 Preserve radio lab experiments and reuse unchanged SX1262 modulation
Skip redundant modulation writes during owned fast RX retunes when the last
acknowledged SF/BW/CR/LDRO tuple matches. Invalidate that cache after ordinary
setters, failed writes, and lifecycle changes.

Include the remaining scan, preamble, settling, and memory-soak experiments,
their collectors, validation notes, and original capture records. Preserve
capture bytes across checkouts and keep private soak credentials local.

Run lab collector and compiled contract tests in CI. Update the expectation,
profile mapping, and result-buffer tests for the extended lab tools, and make
the private WiFi override header optional for ordinary soak diagnostics.

Validation: 145 host tests passed from the staged source snapshot. Clean
heltec_v4_repeater and Xiao_S3_WIO_companion_radio_usb builds passed their
RAM/flash gates. All 229 staged capture files retain their original bytes;
all 75 local documentation links resolve in the clean snapshot.
2026-09-14 22:34:17 -07:00

54 lines
2.3 KiB
Python

import unittest
from profile_switch_sf_limits import sf_limits, SF_ORDER
from profile_switch_settling import settling_plan
def capture(sf, stopped="first_failure_above_pass"):
return dict(complete=True, stopped=stopped, sf=sf, bw_khz=125, find_upper_limit=True,
plan=settling_plan(sf=sf), first_perfect_settle_us=0,
last_perfect_settle_us=100, first_failed_above_pass_us=200, levels=[])
class SfLimitsTests(unittest.TestCase):
def test_first_pass_stops_entire_sweep_without_lower_sf(self):
seen=[]
def run(sf):
seen.append(sf)
reply=capture(sf, "first_400_of_400_pass" if sf==9 else "nominal_timing_limit_with_misses")
reply["find_upper_limit"]=False
if sf==10:
reply["first_perfect_settle_us"]=reply["last_perfect_settle_us"]=None
return reply
result=sf_limits(run,lambda _:None,stop_on_first_pass=True)
self.assertEqual(seen,[10,9])
self.assertEqual(result["stopped"],"first_400_of_400_pass")
self.assertEqual(result["first_perfect_sf"],9)
self.assertTrue(result["complete"])
def test_first_pass_mode_rejects_upper_limit_child(self):
with self.assertRaises(RuntimeError):
sf_limits(lambda sf:capture(sf),lambda _:None,stop_on_first_pass=True)
def test_descends_through_every_sf_even_when_one_has_no_pass(self):
seen=[]
result=sf_limits(lambda sf: seen.append(sf) or capture(sf,"nominal_timing_limit_with_misses"
if sf==8 else "first_failure_above_pass"),
lambda _:None)
self.assertEqual(seen,[10,9,8,7,6,5])
self.assertTrue(result["complete"])
def test_fixture_error_never_advances_to_next_sf(self):
seen=[]
with self.assertRaises(RuntimeError):
sf_limits(lambda sf: seen.append(sf) or dict(complete=False),lambda _:None)
self.assertEqual(seen,[10])
def test_wrong_sf_and_first_pass_only_results_rejected(self):
for reply in (capture(9),capture(10,"first_400_of_400_pass")):
with self.assertRaises(RuntimeError):
sf_limits(lambda _:reply,lambda _:None)
if __name__ == "__main__":
unittest.main()