mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-01 00:27:20 -05:00
feat: take the host probe lock per run
core_probe takes probe.lock itself around one execution, load check included, and releases it when the run ends. A campaign pass never holds it between runs, so two passes interleave. RETROBIOS_PROBE_LOCK names another file, RETROBIOS_PROBE_LOCK_HELD says the caller holds it. Tests use their own lock file.
This commit is contained in:
1 parent
b6ed5ba0a1
commit
fabd431adb
6 files changed
+129
-3
No files matched your search
@@ -504,6 +504,32 @@ class FakeCoreTests(unittest.TestCase):
|
||||
sealed = measurement_records.seal({**record, "emulator": "fake", "subject": "s"})
|
||||
self.assertEqual([e.message for e in Draft202012Validator(schema).iter_errors(sealed)], [])
|
||||
|
||||
def test_a_run_waits_for_the_host_lock_and_frees_it(self) -> None:
|
||||
import fcntl
|
||||
import time
|
||||
|
||||
lock = self.tmp / "host.lock"
|
||||
argv = [sys.executable, str(REPO_ROOT / "scripts" / "core_probe.py"), "run", "--core",
|
||||
str(self.core), "--frames", "1", "--no-trace", "--work-dir", str(self.tmp / "work")]
|
||||
env = {**os.environ, "RETROBIOS_PROBE_LOCK": str(lock)}
|
||||
with lock.open("a") as held:
|
||||
fcntl.flock(held, fcntl.LOCK_EX)
|
||||
waiting = subprocess.Popen(argv, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
|
||||
text=True)
|
||||
time.sleep(1.5)
|
||||
self.assertIsNone(waiting.poll(), "the run went ahead while another held the lock")
|
||||
# A caller that holds the lock for this run says so.
|
||||
held_run = subprocess.run(argv, env={**env, "RETROBIOS_PROBE_LOCK_HELD": "1"},
|
||||
capture_output=True, text=True, timeout=60, check=False)
|
||||
self.assertEqual(held_run.returncode, 0, held_run.stderr)
|
||||
fcntl.flock(held, fcntl.LOCK_UN)
|
||||
_, err = waiting.communicate(timeout=60)
|
||||
self.assertEqual(waiting.returncode, 0, err)
|
||||
self.assertIn("another measurement is running", err)
|
||||
# Released at the end of the run: the lock is free again.
|
||||
with lock.open("a") as again:
|
||||
fcntl.flock(again, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
|
||||
def test_second_run_is_appended_beside_the_first(self) -> None:
|
||||
record_dir = checkout(self.tmp / "appended")
|
||||
argv = ["run", "--core", str(self.core), "--frames", "1", "--no-trace", "--max-load", "1000",
|
||||
|
||||
Reference in new issue
Block a user