From 82abde5ba2ba00a494be529de19c96eba5639b73 Mon Sep 17 00:00:00 2001 From: HiFiPHile Date: Tue, 1 Sep 2026 07:18:49 +0200 Subject: tools: make RTT stop files idempotent --- test/hil/test/test_hil_rtt.py | 20 +++++++++++++++++--- tools/rtt.py | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test/hil/test/test_hil_rtt.py b/test/hil/test/test_hil_rtt.py index 94d0c5eec..2f142b418 100644 --- a/test/hil/test/test_hil_rtt.py +++ b/test/hil/test/test_hil_rtt.py @@ -326,7 +326,7 @@ class RttPlatformLifecycle(unittest.TestCase): self.assertEqual(hil_util._rtt._tool_exe('RTT_JLINK_EXE', 'JLinkExe', 'JLink.exe'), 'JLink.exe') - def test_cli_rejects_an_existing_stop_file(self): + def test_cli_accepts_an_existing_stop_file(self): with tempfile.TemporaryDirectory() as temp_dir: stop_file = Path(temp_dir) / 'capture.stop' stop_file.touch() @@ -334,8 +334,22 @@ class RttPlatformLifecycle(unittest.TestCase): [sys.executable, str(CLI), '--backend', 'jlink', '--probe', '000', '--device', 'FAKE', '--stop-file', str(stop_file)], capture_output=True, timeout=20) - self.assertEqual(r.returncode, 2) - self.assertIn(b'already exists', r.stderr) + self.assertEqual(r.returncode, 0, r.stderr) + + def test_cli_accepts_a_stop_file_created_immediately_after_spawn(self): + env = dict(os.environ, RTT_JLINK_EXE='definitely-not-a-jlink-tool') + with tempfile.TemporaryDirectory() as temp_dir: + stop_file = Path(temp_dir) / 'capture.stop' + for _ in range(5): + with contextlib_suppress(FileNotFoundError): + stop_file.unlink() + proc = subprocess.Popen( + [sys.executable, str(CLI), '--backend', 'jlink', '--probe', '000', + '--device', 'FAKE', '--stop-file', str(stop_file)], + env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stop_file.touch() + _, stderr = proc.communicate(timeout=20) + self.assertEqual(proc.returncode, 0, stderr) def test_cli_stop_file_cancels_connection_setup(self): with tempfile.TemporaryDirectory() as temp_dir: diff --git a/tools/rtt.py b/tools/rtt.py index c3ea86093..0ae975fcf 100644 --- a/tools/rtt.py +++ b/tools/rtt.py @@ -690,7 +690,7 @@ def main() -> int: # header and read garbage as a descriptor ap.error(f'--channel must be >= 0, got {args.channel}') if args.stop_file and os.path.exists(args.stop_file): - ap.error(f'--stop-file already exists: {args.stop_file}') + return 0 def stop_requested(): return bool(args.stop_file and os.path.exists(args.stop_file)) -- cgit v1.3.1