1
0

bench test updates

This commit is contained in:
Aiden
2026-05-26 00:48:28 +10:00
parent 7c211f8112
commit 443789d6ae
11 changed files with 832 additions and 2 deletions

View File

@@ -43,9 +43,34 @@ class BenchConnectLcdTest(unittest.TestCase):
],
)
def test_detector_resyncs_to_checksum_valid_frame(self):
detector = FrameDetector()
detected = detector.feed(bytes.fromhex("FF0000000080DA"))
self.assertEqual([(format_frame(frame), label) for frame, label in detected], [
("00 00 00 00 80 DA", "heartbeat")
])
self.assertEqual(detector.dropped_bytes, 1)
self.assertEqual(detector.resync_events, 1)
def test_detector_prefers_labeled_heartbeat_over_shifted_valid_window(self):
detector = FrameDetector()
heartbeat = bytes.fromhex("0000000080DA")
detected = detector.feed(heartbeat[1:] + heartbeat)
self.assertEqual([(format_frame(frame), label) for frame, label in detected], [
("00 00 00 00 80 DA", "heartbeat")
])
self.assertEqual(detector.dropped_bytes, 5)
def test_label_frame_marks_unlabeled_checksum_ok_frame(self):
self.assertEqual(label_frame(bytes.fromhex("01000000005B")), "checksum_ok_unlabeled")
def test_label_frame_marks_table_readback_candidate(self):
self.assertEqual(label_frame(bytes.fromhex("04001280804C")), "table_readback_candidate")
def test_label_frame_marks_real_bench_c0_6020_response(self):
self.assertEqual(label_frame(bytes.fromhex("0780C060205D")), "visible_C0_6020_family_candidate")

View File

@@ -0,0 +1,50 @@
import io
import json
import tempfile
import unittest
from pathlib import Path
from h8536.serial_scenario import DEFAULT_ACK_FRAME, DEFAULT_ACK_TARGET, main
class SerialScenarioTest(unittest.TestCase):
def test_dry_run_summarizes_ack_aware_table_sweep(self):
scenario = {
"name": "unit-sweep",
"steps": [
{
"action": "table_sweep",
"start": "0x000",
"count": "0x002",
"gap": 0.75,
"ack_on": {
"frames": ["07 80 40 20 90 2D"],
"ack_frame": "05 00 40 00 00 1F",
"max_acks": 8,
"max_target_hits": 32,
},
}
],
}
with tempfile.TemporaryDirectory() as tmpdir:
path = Path(tmpdir) / "scenario.json"
path.write_text(json.dumps(scenario), encoding="utf-8")
stdout = io.StringIO()
exit_code = main([str(path), "--dry-run"], stdout=stdout)
output = stdout.getvalue()
self.assertEqual(exit_code, 0)
self.assertIn("scenario=unit-sweep", output)
self.assertIn("selectors=2 first=0x000 last=0x001", output)
self.assertIn("ack_target=07 80 40 20 90 2D", output)
self.assertIn("ack_frame=05 00 40 00 00 1F", output)
self.assertIn("max_acks=8 max_target_hits=32", output)
def test_default_ack_frames_match_current_rom_probe_candidate(self):
self.assertEqual(DEFAULT_ACK_TARGET, bytes.fromhex("07804020902D"))
self.assertEqual(DEFAULT_ACK_FRAME, bytes.fromhex("05004000001F"))
if __name__ == "__main__":
unittest.main()