File size: 1,538 Bytes
f5b159e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """Architecture routing and artifact-integrity checks; no framework or GPU."""
import hashlib
import json
from pathlib import Path
import tempfile
import unittest
from qwen_image21.decoder import select_decoder
class DecoderSelection(unittest.TestCase):
def fixture(self,root):
data=b'allowlisted library bytes';(root/'decoder.so').write_bytes(data)
(root/'manifest.json').write_text(json.dumps(dict(file='decoder.so',architecture='gfx1201',abi_version=1,sha256=hashlib.sha256(data).hexdigest())))
def test_mi355_auto_does_not_need_or_load_rdna4_artifact(self):
path,reason=select_decoder('gfx950:sramecc+:xnack-','auto','/does/not/exist')
self.assertIsNone(path);self.assertIn('gfx950',reason)
def test_explicit_native_rejects_other_architecture(self):
with self.assertRaisesRegex(ValueError,'gfx1201 only'):
select_decoder('gfx950','native','/does/not/exist')
def test_rdna4_auto_verifies_artifact_and_detects_corruption(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);self.fixture(root)
path,_=select_decoder('gfx1201','auto',root);self.assertEqual(path,root/'decoder.so')
(root/'decoder.so').write_bytes(b'corrupt')
with self.assertRaisesRegex(ValueError,'SHA-256 mismatch'):
select_decoder('gfx1201','auto',root)
def test_framework_override_does_not_require_native_library(self):
self.assertIsNone(select_decoder('gfx1201','framework','/does/not/exist')[0])
|