Files
mandy/tests/test_x64_recomp_qemu_runner.py

45 lines
1.7 KiB
Python

"""Every x64_recomp execution test suite's QEMU fallback runner must call xr.run_result, not xr.run_kernel."""
import importlib.util
import os
import sys
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
TESTS_DIR = ROOT / "tests"
class X64RecompQemuRunnerTests(unittest.TestCase):
def test_qemu_fallback_calls_run_result(self):
suites = sorted(
p for p in TESTS_DIR.glob("test_x64_recomp_*.py")
if p.name != Path(__file__).name
)
self.assertGreaterEqual(len(suites), 14)
checked = 0
for path in suites:
spec = importlib.util.spec_from_file_location(path.stem, path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
factory = getattr(mod, "_find_runner", None) or getattr(mod, "_runner", None)
if factory is None:
continue
checked += 1
with self.subTest(suite=path.name):
with mock.patch.dict(os.environ, {"QEMU_AARCH64": sys.executable}):
runner = factory()
self.assertIsNotNone(runner)
xr = mod.xr
sentinel = (42, "fake_tr")
with mock.patch.object(xr, "run_result", return_value=sentinel) as m_res, \
mock.patch.object(xr, "run_kernel", side_effect=AssertionError("called run_kernel instead of run_result")):
got = runner(b"\x90")
self.assertEqual(got, sentinel)
m_res.assert_called_once()
self.assertGreaterEqual(checked, 14)
if __name__ == "__main__":
unittest.main()