mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
Test modules passed dir= the repository's tmp/ or a hard-coded tmp/tests by hand, and seven modules kept their own _tempdir copy. Under run_tests.py the literal tmp/tests did not exist in a fresh clone (FileNotFoundError in test_core_probe and scratch_checkout), and dir=tmp/ wrote beside the per-module scratch folders. Every temporary directory now lands in the folder tests/__init__ sets, and scratch_dir() replaces the copies. The X socket binds by a relative name, since a scratch path can exceed the 108-byte AF_UNIX limit. The journeys keep the short tmp/ root: their word budgets count the printed card path.
90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
"""A digest frontend withholds a file only when ITS digest disagrees.
|
|
|
|
RomM's list declares md5, sha1 and crc32 per file and RomM accepts any of
|
|
them. The resolver calls a file `hash_mismatch` when any declared hash
|
|
disagrees, so a mistyped crc32 beside the right md5 dropped the file from
|
|
the pack and the manifest while verify, comparing md5, called it OK.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tests
|
|
|
|
import hashlib
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
from model.platforms import load_platform_config
|
|
from packs.manifest import generate_manifest
|
|
from packs.platformpack import generate_pack
|
|
from packs.coverage import verify_platform
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class FrontendDigestDecides(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
root = Path(self.tmp.name)
|
|
self.bios = root / "bios"
|
|
self.bios.mkdir()
|
|
payload = b"psx bios " * 64
|
|
held = self.bios / "scph5501.bin"
|
|
held.write_bytes(payload)
|
|
md5 = hashlib.md5(payload).hexdigest()
|
|
sha1 = hashlib.sha1(payload).hexdigest()
|
|
self.platforms = root / "platforms"
|
|
self.platforms.mkdir()
|
|
(root / "emulators").mkdir()
|
|
self.emulators = root / "emulators"
|
|
(self.platforms / "_registry.yml").write_text(
|
|
yaml.safe_dump({"platforms": {"digestplat": {"config": "digestplat.yml"}}})
|
|
)
|
|
(self.platforms / "digestplat.yml").write_text(yaml.safe_dump({
|
|
"platform": "DigestPlat",
|
|
"version": "2.1",
|
|
"verification_mode": "md5",
|
|
"base_destination": "bios",
|
|
"systems": {"psx": {"files": [{
|
|
"name": "scph5501.bin", "destination": "scph5501.bin",
|
|
"md5": md5, "crc32": "00000000", "required": True,
|
|
}]}},
|
|
}))
|
|
self.db = {
|
|
"files": {sha1: {"path": str(held), "name": "scph5501.bin", "size": len(payload),
|
|
"sha1": sha1, "md5": md5, "crc32": "deadbeef"}},
|
|
"indexes": {"by_md5": {md5: sha1}, "by_name": {"scph5501.bin": [sha1]},
|
|
"by_crc32": {}, "by_path_suffix": {}},
|
|
}
|
|
self.root = root
|
|
|
|
def test_pack_manifest_and_verify_agree(self):
|
|
os.chdir(self.root)
|
|
self.addCleanup(os.chdir, REPO_ROOT)
|
|
zip_path = generate_pack(
|
|
"digestplat", str(self.platforms), self.db, str(self.bios),
|
|
str(self.root / "out"), emulators_dir=str(self.emulators),
|
|
emu_profiles={}, offline=True,
|
|
)
|
|
with zipfile.ZipFile(zip_path) as zf:
|
|
self.assertIn("scph5501.bin", {Path(n).name for n in zf.namelist()})
|
|
manifest = generate_manifest(
|
|
"digestplat", str(self.platforms), self.db, str(self.bios),
|
|
str(self.platforms / "_registry.yml"), emulators_dir=str(self.emulators),
|
|
emu_profiles={}, offline=True,
|
|
)
|
|
self.assertEqual([f["dest"] for f in manifest["files"]], ["scph5501.bin"])
|
|
config = load_platform_config("digestplat", str(self.platforms))
|
|
result = verify_platform(config, self.db, str(self.emulators), emu_profiles={})
|
|
self.assertEqual(result["details"][0]["status"], "ok")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|