"""Tests for lat/probe/lat_probe.py — validated against a captured real frame.""" import os import sys import unittest HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import lat_probe as lp # noqa: E402 # LAT payload of vt-session.pcap frame 15 (terminal -> host): flags=0x02 (Master, # type=Run), nbr_slots=1, dst_cir=0x0001, src_cir=0x5460, seq=5, ack=6, # slot: dst=1 src=1 byte_count=1 credits=0 type=Data_a data='a' CAPTURED_PAYLOAD = bytes.fromhex("02010100605 405060101010061".replace(" ", "")) class BuildTest(unittest.TestCase): def test_matches_the_captured_frame(self): f = lp.build_run(lp.VT1200_MAC, "2c:16:db:a0:e7:b1", 1, [(1, 1, 1, 0, 0, b"\x61")], dst_cir=1, src_cir=0x5460, seq=5, ack=6) self.assertEqual(len(f), 60) self.assertEqual(f[14:14 + len(CAPTURED_PAYLOAD)], CAPTURED_PAYLOAD) def test_parse_roundtrip(self): f = lp.build_run(lp.VT1200_MAC, "2c:16:db:a0:e7:b1", 255, [(1, 1, 4, 0, 0, b"AAAA")]) p = lp.parse_frame(f) self.assertEqual(p["nbr_slots"], 255) self.assertEqual(p["type"], 0) self.assertTrue(p["master"]) self.assertEqual(p["slots"][0][5], b"AAAA") def test_malformed_count_is_written_verbatim(self): # the whole point: claim 255 slots while carrying one f = lp.build_run(lp.VT1200_MAC, "2c:16:db:a0:e7:b1", 255, [(1, 1, 1, 0, 0, b"z")]) self.assertEqual(f[15], 255) # LAT+1 if __name__ == "__main__": unittest.main()