mirror of
https://github.com/D-Modem/courier-emu.git
synced 2026-11-28 20:38:07 -08:00
--at queues every byte before boot, which answers one command and tells you nothing about a session. --console attaches the launching terminal to the DTE port for as long as the run lasts, and --serial-pty hands the same port out as a device node for screen, minicom, or anything else that drives a modem. Both need the second command line to work, and it never has. The command state machine publishes its state as the callback at 0x02ac: a8d9 collects a line, the terminator advances it to a910, which parses and prints, and the end-of-command path at a8b1 clears the collector and returns to a8d9. Bytes delivered into the a910 window are assembled into a buffer nothing goes on to parse - the firmware's own type-ahead flag at 0x1cf2 would carry a line across, and it is set by the DTE front-end this harness stands in for. So wait for a8d9 before offering the next line, and re-arm the collect flag at 0x1cee bit 0x40 for each line, exactly as the main-loop milestone already does once. ATI3, ATI1 and ATI0 now each answer in one session. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import socket
|
|
import unittest
|
|
|
|
from courier_emu.console import MAX_PENDING_OUTPUT, SerialConsole
|
|
|
|
|
|
class SerialConsoleTests(unittest.TestCase):
|
|
def _pair(self) -> tuple[SerialConsole, socket.socket]:
|
|
worker, terminal = socket.socketpair()
|
|
console = SerialConsole(worker.detach())
|
|
self.addCleanup(terminal.close)
|
|
self.addCleanup(console.close)
|
|
return console, terminal
|
|
|
|
def test_poll_is_empty_until_the_terminal_types(self) -> None:
|
|
console, terminal = self._pair()
|
|
self.assertEqual(console.poll(), b"")
|
|
terminal.sendall(b"ATI3\r")
|
|
self.assertEqual(console.poll(), b"ATI3\r")
|
|
self.assertEqual(console.received, 5)
|
|
|
|
def test_transmitted_bytes_reach_the_terminal(self) -> None:
|
|
console, terminal = self._pair()
|
|
for value in b"OK\r\n":
|
|
console.write(value)
|
|
self.assertEqual(terminal.recv(16), b"OK\r\n")
|
|
self.assertEqual(console.sent, 4)
|
|
|
|
def test_a_closed_terminal_is_reported_once(self) -> None:
|
|
console, terminal = self._pair()
|
|
terminal.close()
|
|
self.assertEqual(console.poll(), b"")
|
|
self.assertTrue(console.closed)
|
|
|
|
def test_output_nobody_reads_is_bounded(self) -> None:
|
|
console, _terminal = self._pair()
|
|
# Fill the socket buffer and then keep transmitting: a terminal that
|
|
# stops reading must not stall the run or grow the queue without end.
|
|
for _ in range(MAX_PENDING_OUTPUT * 2):
|
|
console.write(0x41)
|
|
self.assertLessEqual(len(console._pending), MAX_PENDING_OUTPUT)
|
|
self.assertGreater(console.dropped, 0)
|
|
|
|
def test_summary_reports_both_directions(self) -> None:
|
|
console, terminal = self._pair()
|
|
terminal.sendall(b"AT\r")
|
|
console.poll()
|
|
console.write(0x4F)
|
|
summary = console.summary()
|
|
self.assertEqual(summary["received"], 3)
|
|
self.assertEqual(summary["sent"], 1)
|
|
self.assertFalse(summary["closed"])
|
|
|
|
def test_writing_to_a_closed_descriptor_does_not_raise(self) -> None:
|
|
console, terminal = self._pair()
|
|
terminal.close()
|
|
console.poll()
|
|
console.write(0x41)
|
|
self.assertTrue(console.closed)
|
|
|
|
def test_the_descriptor_is_left_non_blocking(self) -> None:
|
|
console, _terminal = self._pair()
|
|
self.assertFalse(os.get_blocking(console.fd))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|