summaryrefslogtreecommitdiffstats
path: root/debug/risc-v-gsp-rm-vm/tests/test_bridge.py
diff options
context:
space:
mode:
Diffstat (limited to 'debug/risc-v-gsp-rm-vm/tests/test_bridge.py')
-rw-r--r--debug/risc-v-gsp-rm-vm/tests/test_bridge.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/debug/risc-v-gsp-rm-vm/tests/test_bridge.py b/debug/risc-v-gsp-rm-vm/tests/test_bridge.py
index 7eeb46c..966399a 100644
--- a/debug/risc-v-gsp-rm-vm/tests/test_bridge.py
+++ b/debug/risc-v-gsp-rm-vm/tests/test_bridge.py
@@ -5,6 +5,7 @@ import json
import os
import shutil
import socket
+import time
import unittest
import greeneye as ge
@@ -23,6 +24,36 @@ class GhidraCommandTests(unittest.TestCase):
self.assertIn("MarkGreenEyeHits.java /tmp/hits.tsv", cmd)
+class BridgeLifecycleTests(unittest.TestCase):
+ """No target needed: start/stop/close are transport-level."""
+
+ def test_refuses_non_loopback_bind(self):
+ bridge = GhidraBridge(object(), host="0.0.0.0", port=0)
+ with self.assertRaises(ValueError):
+ bridge.start()
+
+ def test_close_command_takes_down_the_listener(self):
+ bridge = GhidraBridge(object(), port=0)
+ port = bridge.start()
+ with socket.create_connection(("127.0.0.1", port), timeout=10) as sock:
+ stream = sock.makefile("rwb")
+ stream.write((json.dumps({"id": 1, "cmd": "close", "args": {}}) + "\n").encode())
+ stream.flush()
+ response = json.loads(stream.readline())
+ self.assertTrue(response["ok"])
+ self.assertTrue(response["close"])
+ deadline = time.monotonic() + 5.0
+ while True:
+ try:
+ with socket.create_connection(("127.0.0.1", port), timeout=0.5):
+ pass
+ except OSError:
+ break
+ if time.monotonic() > deadline:
+ self.fail("listener still accepting connections after <close>")
+ time.sleep(0.05)
+
+
def qemu_available() -> bool:
return bool(os.environ.get("GREENEYE_QEMU") or shutil.which("qemu-system-riscv64"))