Verify and publish documentation / test (macos-latest) (push) Canceled after 0s
Verify and publish documentation / test (ubuntu-latest) (push) Canceled after 0s
Verify and publish documentation / docs (push) Canceled after 0s
Verify and publish documentation / deploy (push) Canceled after 0s
Validate physical cards and CLI arguments, guard live DO cells, and share word encoding and checked numeric conversion. Preserve media on failed runs and bound notebook input, output, execution time and process cleanup. Clarify fixed-form editor support and compatibility evidence, add executable quick-start examples, and gate GitHub Pages on Linux/macOS and strict docs CI.
470 lines
22 KiB
Python
470 lines
22 KiB
Python
"""Behavioural tests for read-only stops, portable media and BASIC exchange."""
|
|
import os
|
|
import errno
|
|
from pathlib import Path
|
|
import re
|
|
import resource
|
|
import signal
|
|
import struct
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
import unittest
|
|
import zlib
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
BIN = os.environ.get("F704_BINARY", str(ROOT / "fortran704"))
|
|
if "/" in BIN:
|
|
BIN = str(Path(BIN).resolve())
|
|
|
|
WRITER = """ A=1.25
|
|
B=-2.5
|
|
N=7
|
|
WRITE TAPE 2,A,B,N
|
|
END FILE 2
|
|
BACKSPACE 2
|
|
WRITE DRUM 1,2047,A,B
|
|
WRITE OUTPUT TAPE 1,100
|
|
WRITE OUTPUT TAPE 1,101
|
|
END FILE 1
|
|
STOP
|
|
100 FORMAT(5HHELLO)
|
|
101 FORMAT(9HFORTRAN 7)
|
|
END
|
|
"""
|
|
|
|
|
|
class DebugMedia(unittest.TestCase):
|
|
def setUp(self):
|
|
temp = tempfile.TemporaryDirectory(prefix="f704-debug-")
|
|
self.addCleanup(temp.cleanup)
|
|
self.work = Path(temp.name)
|
|
self.serial = 0
|
|
|
|
def run_f(self, source, *options, commands=None, data=b""):
|
|
self.serial += 1
|
|
src = self.work / f"p{self.serial}.f"
|
|
src.write_text(source)
|
|
args = [BIN, *map(str, options)]
|
|
log = None
|
|
if commands is not None:
|
|
script = self.work / f"c{self.serial}"
|
|
script.write_text(commands)
|
|
log = self.work / f"d{self.serial}"
|
|
args += ["--debug-script", str(script), "--debug-output", str(log)]
|
|
p = subprocess.run(args+[str(src)], input=data, capture_output=True, cwd=self.work, timeout=15)
|
|
return p, log.read_text() if log and log.exists() else ""
|
|
|
|
def ok(self, result):
|
|
self.assertEqual(result.returncode, 0, result.stderr.decode())
|
|
|
|
def test_steps_calls_aliases_and_repeatable_checkpoints(self):
|
|
source = """ EQUIVALENCE (A,B)
|
|
A=1.0
|
|
DO 10 I=1,2
|
|
CALL BUMP(A)
|
|
10 CONTINUE
|
|
PRINT 20,A,B
|
|
STOP
|
|
20 FORMAT(1H ,2F6.1)
|
|
END
|
|
SUBROUTINE BUMP(X)
|
|
X=X+1.0
|
|
RETURN
|
|
END
|
|
"""
|
|
commands = "capabilities\nwatch A\nwatch B\ninspect card\ninspect flags\ncheckpoint start\n" + "step\n"*3 + "inspect X\ncheckpoint call\n" + "step\n"*12
|
|
normal, _ = self.run_f(source)
|
|
debug, log = self.run_f(source, commands=commands)
|
|
self.ok(debug)
|
|
self.assertEqual((debug.stdout, debug.stderr), (normal.stdout, normal.stderr))
|
|
self.assertIn("undefined", log)
|
|
self.assertIn("unit=BUMP line=11", log)
|
|
self.assertIn("checkpoint call", log)
|
|
addresses = re.findall(r"value [ABX] address=([0-7]+)", log)
|
|
self.assertTrue(addresses)
|
|
self.assertEqual(len(set(addresses)), 1)
|
|
again, log2 = self.run_f(source, commands=commands)
|
|
self.ok(again)
|
|
self.assertEqual(log, log2)
|
|
|
|
def test_pure_watches_input_and_array_bounds(self):
|
|
source = """ DIMENSION A(2,2)
|
|
READ 10,I
|
|
A(2,2)=I
|
|
PRINT 10,I
|
|
STOP
|
|
10 FORMAT(I4)
|
|
END
|
|
"""
|
|
normal, _ = self.run_f(source, data=b" 9\n")
|
|
debug, log = self.run_f(source, data=b" 9\n", commands=
|
|
"watch I\nwatch A(2,2)\ninspect A(3,1)\ninspect SINF(1)\ninspect A(I)\nstep\nstep\ncheckpoint read\ncontinue\n")
|
|
self.ok(debug)
|
|
self.assertEqual(debug.stdout, normal.stdout)
|
|
self.assertIn("integer=9", log)
|
|
self.assertIn("error bounds", log)
|
|
self.assertIn("error invalid-reference", log)
|
|
self.assertIn("real=9", log)
|
|
|
|
def test_break_continue_and_eof(self):
|
|
p, log = self.run_f(" I=1\n I=2\n STOP\n END\n",
|
|
commands="break 3\ncontinue\ncheckpoint end\n")
|
|
self.ok(p)
|
|
self.assertEqual(re.findall(r"stop \d+ unit=MAIN line=(\d+)", log), ["1", "3"])
|
|
self.assertIn("resume eof", log)
|
|
|
|
def test_media_roundtrip_words_marks_cursor_and_debug_purity(self):
|
|
image = self.work / "one.img"
|
|
debug_image = self.work / "debug.img"
|
|
p, _ = self.run_f(WRITER, "--save-media", image)
|
|
self.ok(p)
|
|
p, log = self.run_f(WRITER, "--save-media", debug_image, commands=
|
|
"break 11\ncontinue\ninspect tape 2 0\ninspect tape 2 1\ninspect drum 1 2047 1\ninspect drum 1 0 2\ninspect drum 1 2047 2\ncheckpoint saved\ncontinue\n")
|
|
self.ok(p)
|
|
self.assertEqual(image.read_bytes(), debug_image.read_bytes())
|
|
self.assertIn("kind=BIN length=3 cursor=1", log)
|
|
self.assertIn("kind=MARK", log)
|
|
self.assertIn("error media-request", log)
|
|
second = self.work / "two.img"
|
|
p, _ = self.run_f(" STOP\n END\n", "--load-media", image, "--save-media", second)
|
|
self.ok(p)
|
|
self.assertEqual(image.read_bytes(), second.read_bytes())
|
|
p, _ = self.run_f(""" BACKSPACE 2
|
|
READ TAPE 2,A,B,N
|
|
READ DRUM 1,2047,X,Y
|
|
PRINT 10,A,B,N,X,Y
|
|
STOP
|
|
10 FORMAT(1H ,2F7.2,I4,2F7.2)
|
|
END
|
|
""", "--load-media", image)
|
|
self.ok(p)
|
|
self.assertEqual(p.stdout.split(), [b"1.25", b"-2.50", b"7", b"1.25", b"-2.50"])
|
|
|
|
def test_independent_wire_image_and_empty_records(self):
|
|
# Construct the documented wire format without the production writer.
|
|
payload = bytearray(b"F704M01\n")
|
|
payload += struct.pack(">II", 3, 1)
|
|
payload += struct.pack(">BI", 1, 0) # empty BCD, distinct from a mark
|
|
payload += struct.pack(">BI", 2, 0) # empty binary
|
|
payload += struct.pack(">BI", 3, 0)
|
|
payload += bytes(9*8)
|
|
payload += (7 << 18).to_bytes(5, "big") + bytes((8*2048-1)*5)
|
|
wire = payload + struct.pack(">I", zlib.crc32(payload))
|
|
image = self.work / "independent.img"
|
|
image.write_bytes(wire)
|
|
saved = self.work / "copy.img"
|
|
p, log = self.run_f(" STOP\n END\n", "--load-media", image, "--save-media", saved,
|
|
commands="inspect tape 1 0\ninspect tape 1 1\ninspect tape 1 2\ninspect drum 1 0 1\ncontinue\n")
|
|
self.ok(p)
|
|
self.assertEqual(saved.read_bytes(), wire)
|
|
self.assertIn("kind=BCD length=0 cursor=1", log)
|
|
self.assertIn("kind=BIN length=0", log)
|
|
self.assertIn("raw=000007000000", log)
|
|
|
|
def test_corruption_rejected_without_replacing_saved_file(self):
|
|
original = self.work / "original.img"
|
|
self.ok(self.run_f(WRITER, "--save-media", original)[0])
|
|
raw = original.read_bytes()
|
|
mutations = [raw[:n] for n in (0, 7, 12, 20, len(raw)-1)]
|
|
mutations += [raw[:40] + bytes([raw[40] ^ 1]) + raw[41:]]
|
|
# Valid checksums do not excuse invalid cursor, kind, length or high bits.
|
|
for at, replacement in [(12, b"\xff"*4), (16, b"\x09"), (17, b"\xff"*4), (len(raw)-9, b"\xf0")]:
|
|
altered = bytearray(raw[:-4]); altered[at:at+len(replacement)] = replacement
|
|
mutations.append(bytes(altered)+struct.pack(">I", zlib.crc32(altered)))
|
|
for data in mutations:
|
|
with self.subTest(size=len(data), prefix=data[:20]):
|
|
bad = self.work / "bad.img"; bad.write_bytes(data)
|
|
dest = self.work / "preserve.img"; dest.write_bytes(b"KEEP")
|
|
p, _ = self.run_f(" STOP\n END\n", "--load-media", bad, "--save-media", dest)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertEqual(dest.read_bytes(), b"KEEP")
|
|
self.assertFalse(list(self.work.glob("*.tmp.*")))
|
|
|
|
def test_printer_failure_does_not_save(self):
|
|
source = self.work / "printer.f"
|
|
source.write_text(" PRINT 10\n STOP\n 10 FORMAT(5HHELLO)\n END\n")
|
|
image = self.work / "saved.img"
|
|
image.write_bytes(b"KEEP")
|
|
# A read-only descriptor gives a portable EBADF without /dev/full.
|
|
with open(os.devnull, "rb") as sink:
|
|
p = subprocess.run([BIN, "--save-media", str(image), str(source)],
|
|
stdout=sink, stderr=subprocess.PIPE, timeout=15)
|
|
self.assertEqual(p.returncode, 1)
|
|
self.assertIn(b"printer output failure", p.stderr)
|
|
self.assertEqual(image.read_bytes(), b"KEEP")
|
|
|
|
def test_missing_input_debug_collisions_create_nothing(self):
|
|
source = self.work / "source.f"
|
|
source.write_text(" STOP\n END\n")
|
|
script = self.work / "commands"
|
|
script.write_text("continue\n")
|
|
for kind in ("source", "bss", "script"):
|
|
with self.subTest(kind=kind):
|
|
missing = self.work / (kind + ".missing")
|
|
args = [BIN, "--debug-script", str(missing if kind == "script" else script),
|
|
"--debug-output", str(missing)]
|
|
if kind == "bss": args += ["--bss", str(missing)]
|
|
args += [str(missing if kind == "source" else source)]
|
|
p = subprocess.run(args, capture_output=True, timeout=15)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertIn(b"conflict", p.stderr)
|
|
self.assertFalse(missing.exists())
|
|
|
|
def test_failed_run_does_not_save(self):
|
|
image = self.work / "saved.img"; image.write_bytes(b"KEEP")
|
|
p, _ = self.run_f(" PRINT 1,X\n STOP\n 1 FORMAT(F8.1)\n END\n", "--save-media", image)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertEqual(image.read_bytes(), b"KEEP")
|
|
|
|
def test_text_export_rejects_binary_and_multiple_files(self):
|
|
for unit in (1, 2):
|
|
source = WRITER if unit == 2 else WRITER.replace(" STOP", " WRITE OUTPUT TAPE 1,100\n STOP")
|
|
dest = self.work / "text.txt"; dest.write_bytes(b"KEEP")
|
|
p, _ = self.run_f(source, "--export-text", str(unit), dest)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertEqual(dest.read_bytes(), b"KEEP")
|
|
|
|
def test_basic_line_input_interchange(self):
|
|
basic = Path(os.environ.get("GWBASIC_BINARY", str(ROOT.parent / "gw-basic-2026/build/gwbasic"))).resolve()
|
|
if not basic.exists(): self.skipTest("set GWBASIC_BINARY to exercise the other interpreter")
|
|
text = self.work / "exchange.txt"
|
|
self.ok(self.run_f(WRITER, "--export-text", "1", text)[0])
|
|
self.assertEqual(text.read_bytes(), b"HELLO\nFORTRAN 7\n")
|
|
reader = self.work / "reader.bas"
|
|
reader.write_text('10 OPEN "exchange.txt" FOR INPUT AS #1\n20 LINE INPUT #1,A$\n30 LINE INPUT #1,B$\n40 PRINT A$:PRINT B$\n50 CLOSE #1\n60 SYSTEM\n')
|
|
env = dict(os.environ, PULSE_SERVER="unix:/tmp/gwbasic-no-audio-server")
|
|
p = subprocess.run([str(basic), str(reader)], input=b"", capture_output=True, cwd=self.work, env=env, timeout=15)
|
|
self.assertEqual(p.returncode, 0, p.stderr)
|
|
self.assertEqual(p.stdout.replace(b"\r", b""), b"HELLO\nFORTRAN 7\n")
|
|
|
|
def test_output_file_protection(self):
|
|
script = self.work / "cmd"; script.write_text("continue\n")
|
|
output = self.work / "out"; output.write_text("KEEP")
|
|
p, _ = self.run_f(" STOP\n END\n", "--debug-script", script, "--debug-output", output)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertEqual(output.read_text(), "KEEP")
|
|
|
|
def test_existing_log_rejected_before_waiting_for_command_fifo(self):
|
|
source = self.work / 'source.f'; source.write_text(' STOP\n END\n')
|
|
fifo = self.work / 'commands'; os.mkfifo(fifo)
|
|
log = self.work / 'log'; log.write_bytes(b'KEEP')
|
|
p = subprocess.run([BIN, '--debug-script', str(fifo), '--debug-output',
|
|
str(log), str(source)], capture_output=True, timeout=5)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertIn(b'must be a new file', p.stderr)
|
|
self.assertEqual(log.read_bytes(), b'KEEP')
|
|
|
|
def test_dangling_source_link_cannot_alias_debug_output(self):
|
|
script = self.work / 'cmd'; script.write_text('continue\n')
|
|
source = self.work / 'source.f'; source.symlink_to('log')
|
|
log = self.work / 'log'
|
|
p = subprocess.run([BIN, '--debug-script', str(script), '--debug-output',
|
|
str(log), str(source)], capture_output=True, timeout=10)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertIn(b'conflict', p.stderr)
|
|
self.assertFalse(log.exists())
|
|
self.assertTrue(source.is_symlink())
|
|
|
|
def test_filesystem_case_aliases_are_rejected(self):
|
|
script = self.work / 'cmd'; script.write_text('continue\n')
|
|
checked = 0
|
|
for first, second in [('trace', 'TRACE'), ('\u00e9', '\u00c9')]:
|
|
a, b = self.work / first, self.work / second
|
|
a.touch(); folds = b.exists(); a.unlink()
|
|
if not folds:
|
|
continue
|
|
checked += 1
|
|
p, _ = self.run_f(' STOP\n END\n', '--debug-script', script,
|
|
'--debug-output', a, '--save-media', b)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertIn(b'conflict', p.stderr)
|
|
self.assertFalse(a.exists())
|
|
if not checked:
|
|
self.skipTest('case-sensitive filesystem')
|
|
|
|
def test_closed_diagnostic_pipe_keeps_successful_media(self):
|
|
source = self.work / 'writer.f'; source.write_text(WRITER)
|
|
dest = self.work / 'state'
|
|
reader, writer = os.pipe()
|
|
os.close(reader)
|
|
with os.fdopen(writer, 'wb') as diagnostic:
|
|
p = subprocess.run([BIN, '--save-media', str(dest), str(source)],
|
|
stdout=subprocess.PIPE, stderr=diagnostic, timeout=10)
|
|
self.assertEqual(p.returncode, 0)
|
|
self.assertTrue(dest.read_bytes().startswith(b'F704M01\n'))
|
|
|
|
def test_closed_printer_pipe_ends_loop_without_saving(self):
|
|
source = self.work / 'loop.f'
|
|
source.write_text(' 1 PRINT 2\n GO TO 1\n'
|
|
' 2 FORMAT(5HHELLO)\n END\n')
|
|
dest = self.work / 'state'; dest.write_bytes(b'KEEP')
|
|
reader, writer = os.pipe()
|
|
os.close(reader)
|
|
with os.fdopen(writer, 'wb') as printer:
|
|
p = subprocess.run([BIN, '--save-media', str(dest), str(source)],
|
|
stdout=printer, stderr=subprocess.PIPE, timeout=5)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertEqual(dest.read_bytes(), b'KEEP')
|
|
|
|
def test_bundle_commit_failure_can_follow_text_commit(self):
|
|
text = self.work / 'text'; text.write_bytes(b'OLD')
|
|
bundle = self.work / 'bundle'; bundle.mkdir()
|
|
p, _ = self.run_f(WRITER, '--export-text', '1', text, '--save-media', bundle)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertEqual(text.read_bytes(), b'HELLO\nFORTRAN 7\n')
|
|
self.assertTrue(bundle.is_dir())
|
|
self.assertFalse(list(self.work.glob('*.tmp.*')))
|
|
|
|
def test_sense_switches_are_validated_before_log_creation(self):
|
|
script = self.work / 'cmd'; script.write_text('continue\n')
|
|
log = self.work / 'log'
|
|
p, _ = self.run_f(' STOP\n END\n', '--ss=XYZ',
|
|
'--debug-script', script, '--debug-output', log)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertIn(b'--ss needs six', p.stderr)
|
|
self.assertFalse(log.exists())
|
|
|
|
def test_media_prefixes_remain_variable_names(self):
|
|
p, log = self.run_f(' TAPES=2.0\n DRUMS=3.0\n STOP\n END\n',
|
|
commands='step\nstep\ninspect tapes\ninspect drums\ncontinue\n')
|
|
self.ok(p)
|
|
self.assertNotIn('error', log)
|
|
self.assertIn('real=2', log)
|
|
self.assertIn('real=3', log)
|
|
|
|
def test_conflicting_output_paths_are_rejected_before_creation(self):
|
|
script = self.work / "cmd"; script.write_text("continue\n")
|
|
for opt in ("--save-media", "--export-text"):
|
|
args = [opt] + (["1"] if opt == "--export-text" else []) + ["./collision"]
|
|
p, _ = self.run_f(" STOP\n END\n", "--debug-script", script,
|
|
"--debug-output", "collision", *args)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertFalse((self.work / "collision").exists())
|
|
p, _ = self.run_f(" STOP\n END\n", "--debug-script", script,
|
|
"--debug-output", "collision", "--load-media", "collision")
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertFalse((self.work / "collision").exists())
|
|
deck = self.work / "module.cbn"; deck.write_bytes(b"PRESERVE INPUT")
|
|
p, _ = self.run_f(" STOP\n END\n", "--bss", deck, "--save-media", deck)
|
|
self.assertNotEqual(p.returncode, 0)
|
|
self.assertIn(b"conflicts with a BSS input deck", p.stderr)
|
|
self.assertEqual(deck.read_bytes(), b"PRESERVE INPUT")
|
|
|
|
def test_unwatch_is_case_insensitive_and_duplicates_are_idempotent(self):
|
|
p, log = self.run_f(" I=1\n STOP\n END\n",
|
|
commands="watch i\nwatch I\nunwatch i\nstep\ncheckpoint empty\ncontinue\n")
|
|
self.ok(p)
|
|
self.assertNotIn("value I", log.split("stop 2")[1])
|
|
commands = "".join(f"watch I{i}\n" for i in range(16)) + "unwatch I15\nwatch I16\ncontinue\n"
|
|
self.ok(self.run_f(" STOP\n END\n", commands=commands)[0])
|
|
|
|
def test_malformed_commands_are_diagnostics(self):
|
|
p, log = self.run_f(" I=1\n STOP\n END\n",
|
|
commands="capabilities extra\nunwatch\nstep\rjunk\ncontinue\n")
|
|
self.ok(p)
|
|
self.assertIn("error unsupported-command", log)
|
|
self.assertIn("error watch", log)
|
|
self.assertIn("error invalid-command", log)
|
|
self.assertEqual(len(re.findall(r"^stop ", log, re.M)), 1)
|
|
|
|
def test_debug_io_failure_never_saves_media(self):
|
|
dest = self.work / "state"; dest.write_bytes(b"KEEP")
|
|
p, _ = self.run_f(" STOP\n END\n", "--debug-script", self.work,
|
|
"--debug-output", self.work / "log", "--save-media", dest)
|
|
self.assertEqual(p.returncode, 2)
|
|
self.assertIn(b"debugger I/O failure", p.stderr)
|
|
self.assertEqual(dest.read_bytes(), b"KEEP")
|
|
|
|
source = self.work / "stop.f"; source.write_text(" STOP\n END\n")
|
|
script = self.work / "cmd"; script.write_text("continue\n")
|
|
def limited_file():
|
|
signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
|
|
resource.setrlimit(resource.RLIMIT_FSIZE, (16, 16))
|
|
p = subprocess.run([BIN, "--debug-script", str(script), "--debug-output", str(self.work / "full"),
|
|
"--save-media", str(dest), str(source)], capture_output=True, timeout=15, preexec_fn=limited_file)
|
|
self.assertEqual(p.returncode, 2, p.stderr)
|
|
self.assertIn(b"debugger I/O failure", p.stderr)
|
|
self.assertEqual(dest.read_bytes(), b"KEEP")
|
|
|
|
def test_debug_write_failure_preserves_printed_output(self):
|
|
source = self.work / 'print.f'
|
|
source.write_text(' PRINT 1\n STOP\n 1 FORMAT(8H PRINTED)\n END\n')
|
|
script = self.work / 'cmd'
|
|
script.write_text('step\n' + 'checkpoint fail\n' * 30)
|
|
dest = self.work / 'state'; dest.write_bytes(b'KEEP')
|
|
|
|
def limited_file():
|
|
signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
|
|
resource.setrlimit(resource.RLIMIT_FSIZE, (256, 256))
|
|
|
|
p = subprocess.run([BIN, '--debug-script', str(script), '--debug-output',
|
|
str(self.work / 'log'), '--save-media', str(dest), str(source)],
|
|
capture_output=True, timeout=15, preexec_fn=limited_file)
|
|
self.assertEqual(p.returncode, 2, p.stderr)
|
|
self.assertEqual(p.stdout, b' PRINTED\n')
|
|
self.assertEqual(dest.read_bytes(), b'KEEP')
|
|
|
|
def test_card_view_uses_compiled_source_during_fifo_pause(self):
|
|
source = self.work / "source.f"; source.write_text(" I=1\n STOP\n END\n")
|
|
fifo = self.work / "commands"; os.mkfifo(fifo)
|
|
log = self.work / "log"
|
|
p = subprocess.Popen([BIN, "--debug-script", str(fifo), "--debug-output", str(log), str(source)],
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
try:
|
|
end = time.monotonic() + 10
|
|
while True:
|
|
if time.monotonic() > end or p.poll() is not None:
|
|
self.fail("debugger did not open command FIFO")
|
|
try:
|
|
fd = os.open(fifo, os.O_WRONLY | os.O_NONBLOCK)
|
|
break
|
|
except OSError as error:
|
|
if error.errno != errno.ENXIO: raise
|
|
time.sleep(0.01)
|
|
os.set_blocking(fd, True)
|
|
with os.fdopen(fd, "w") as commands:
|
|
while not log.exists() or "stop 1" not in log.read_text():
|
|
if time.monotonic() > end or p.poll() is not None: self.fail("debugger did not reach first stop")
|
|
time.sleep(0.01)
|
|
source.write_text(" I=999\n STOP\n END\n")
|
|
commands.write("inspect card\ncontinue\n"); commands.flush()
|
|
_, err = p.communicate(input=b"", timeout=10)
|
|
self.assertEqual(p.returncode, 0, err)
|
|
self.assertIn(" I=1\n", log.read_text())
|
|
self.assertNotIn("I=999", log.read_text())
|
|
finally:
|
|
if p.poll() is None: p.kill()
|
|
p.communicate()
|
|
|
|
def test_nul_debug_command_does_not_consume_the_next_line(self):
|
|
p, log = self.run_f(' I=1\n I=2\n STOP\n END\n',
|
|
commands='x\0\nstep\ncontinue\n')
|
|
self.ok(p)
|
|
self.assertEqual(log.count('error invalid-command'), 1)
|
|
self.assertIn('stop 2 unit=MAIN line=2 ', log)
|
|
|
|
def test_empty_text_export(self):
|
|
dest = self.work / "empty.txt"
|
|
p, _ = self.run_f(" STOP\n END\n", "--export-text", "1", dest)
|
|
self.ok(p)
|
|
self.assertEqual(dest.read_bytes(), b"")
|
|
|
|
def test_native_dialects_flags_and_devices_unchanged(self):
|
|
commands = "inspect flags\ninspect media\nstep\n" * 300
|
|
cases = [("tape.f", 2), ("drum.f", 2), ("writer", 1),
|
|
("std0tape.f", 0), ("std0drum.f", 0), ("sense.f", 2), ("arith.f", 2), ("equiv.f", 2)]
|
|
for name, std in cases:
|
|
with self.subTest(name=name, std=std):
|
|
source = WRITER if name == "writer" else (ROOT / "tests" / name).read_text()
|
|
a, b = self.work / "normal.img", self.work / "debug.img"
|
|
normal, _ = self.run_f(source, f"--std={std}", "--save-media", a)
|
|
debug, _ = self.run_f(source, f"--std={std}", "--save-media", b, commands=commands)
|
|
self.ok(normal); self.ok(debug)
|
|
self.assertEqual((debug.stdout, debug.stderr), (normal.stdout, normal.stderr))
|
|
self.assertEqual(a.read_bytes(), b.read_bytes())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|