Emula;tor bench mimicing
This commit is contained in:
54
tests/test_bench_connect_lcd.py
Normal file
54
tests/test_bench_connect_lcd.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import unittest
|
||||
|
||||
from h8536.bench_connect_lcd import (
|
||||
CONNECT_LCD_SEQUENCE,
|
||||
FrameDetector,
|
||||
format_frame,
|
||||
frame_checksum,
|
||||
frame_checksum_ok,
|
||||
label_frame,
|
||||
parse_frame,
|
||||
)
|
||||
|
||||
|
||||
class BenchConnectLcdTest(unittest.TestCase):
|
||||
def test_connect_sequence_matches_emulator_preset(self):
|
||||
self.assertEqual(
|
||||
[format_frame(frame) for frame in CONNECT_LCD_SEQUENCE],
|
||||
[
|
||||
"04 00 00 40 00 1E",
|
||||
"04 00 00 80 00 DE",
|
||||
"04 00 00 C0 00 9E",
|
||||
],
|
||||
)
|
||||
|
||||
def test_parse_frame_appends_xor_checksum(self):
|
||||
frame = parse_frame("04 00 00 80 00")
|
||||
|
||||
self.assertEqual(frame, bytes.fromhex("0400008000DE"))
|
||||
self.assertEqual(frame_checksum(frame), 0xDE)
|
||||
self.assertTrue(frame_checksum_ok(frame))
|
||||
|
||||
def test_detector_recombines_split_rx_chunks(self):
|
||||
detector = FrameDetector()
|
||||
|
||||
self.assertEqual(detector.feed(bytes.fromhex("000000")), [])
|
||||
detected = detector.feed(bytes.fromhex("0080DA02000200005A"))
|
||||
|
||||
self.assertEqual(
|
||||
[(format_frame(frame), label) for frame, label in detected],
|
||||
[
|
||||
("00 00 00 00 80 DA", "heartbeat"),
|
||||
("02 00 02 00 00 5A", "connect_ok_path_response_candidate"),
|
||||
],
|
||||
)
|
||||
|
||||
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_real_bench_c0_6020_response(self):
|
||||
self.assertEqual(label_frame(bytes.fromhex("0780C060205D")), "visible_C0_6020_family_candidate")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
62
tests/test_emulator_bench_replay.py
Normal file
62
tests/test_emulator_bench_replay.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import unittest
|
||||
|
||||
from h8536.emulator.bench_replay import (
|
||||
BENCH_VISIBLE_C0_6020,
|
||||
CONNECT_OK_RESPONSE,
|
||||
assess_bench_parity,
|
||||
parse_bench_replay_log_text,
|
||||
)
|
||||
|
||||
|
||||
SAMPLE_LOG = """\
|
||||
CONNECT LCD bench sequence
|
||||
21:44:28.062 TX 006 bytes 04 00 00 40 00 1E
|
||||
21:44:28.215 TX 006 bytes 04 00 00 80 00 DE
|
||||
21:44:28.218 RX 001 bytes 07
|
||||
21:44:28.218 RX 002 bytes 80 C0
|
||||
21:44:28.233 RX 001 bytes 60
|
||||
21:44:28.234 RX 002 bytes 20 5D
|
||||
21:44:29.149 RX 006 bytes 00 00 00 00 80 DA
|
||||
21:44:36.078 SCREEN LCD after CONNECT sequence: CONNECT NOT ACT
|
||||
"""
|
||||
|
||||
|
||||
class EmulatorBenchReplayTest(unittest.TestCase):
|
||||
def test_parse_bench_log_extracts_tx_and_recombined_rx_frames(self):
|
||||
log = parse_bench_replay_log_text(SAMPLE_LOG)
|
||||
|
||||
self.assertEqual([frame.frame.hex().upper() for frame in log.tx_frames], ["04000040001E", "0400008000DE"])
|
||||
self.assertEqual(log.rx_frames[0].frame, BENCH_VISIBLE_C0_6020)
|
||||
self.assertEqual(log.rx_frames[0].label, "visible_C0_6020_family_candidate")
|
||||
self.assertEqual(log.screen_notes[-1].note, "CONNECT NOT ACT")
|
||||
|
||||
def test_parity_flags_emulator_connect_ok_when_bench_stayed_not_active(self):
|
||||
log = parse_bench_replay_log_text(SAMPLE_LOG)
|
||||
|
||||
parity = assess_bench_parity(
|
||||
log,
|
||||
emulator_tx_frames=[CONNECT_OK_RESPONSE],
|
||||
emulator_lcd_display=" CONNECT: OK | | | ",
|
||||
emulator_lcd_line_buffer=" CONNECT: OK ",
|
||||
)
|
||||
|
||||
self.assertFalse(parity["matched"])
|
||||
self.assertIn("lcd_connect_state", parity["mismatch_reasons"])
|
||||
self.assertIn("missing_visible_C0_6020_response", parity["mismatch_reasons"])
|
||||
self.assertIn("emulator_emitted_connect_ok_response", parity["mismatch_reasons"])
|
||||
|
||||
def test_parity_passes_for_matching_not_active_visible_response(self):
|
||||
log = parse_bench_replay_log_text(SAMPLE_LOG)
|
||||
|
||||
parity = assess_bench_parity(
|
||||
log,
|
||||
emulator_tx_frames=[BENCH_VISIBLE_C0_6020],
|
||||
emulator_lcd_display=" CONNECT:NOT ACT | | | ",
|
||||
emulator_lcd_line_buffer=" CONNECT:NOT ACT",
|
||||
)
|
||||
|
||||
self.assertTrue(parity["matched"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user