Build opt-in KAR PLE CUDA profile on Gitea

This commit is contained in:
Pavlo Ratushnyi
2026-10-07 16:03:43 +02:00
parent fef5fca6fd
commit 5cc41008eb
11 changed files with 422 additions and 14 deletions
+49
View File
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
"""Package corruption and ABI rejection without Docker or GPU access."""
import importlib.util
import hashlib
import json
from pathlib import Path
import shutil
import tempfile
import unittest
from types import SimpleNamespace
@@ -26,6 +28,13 @@ class PackageTests(unittest.TestCase):
'declared_source_revision': 'a'*40, 'bytes': 3, 'sha256': 'b'*64},
'engine_elf_audit': {'toolkit_shared_libraries': False,
'host_glibc_required': True, 'minimum_glibc': '2.43'}}
features = {'schema_version': 1, 'source_revision': 'a'*40,
'cuda_architectures': '120',
'features': {'cuda': True, 'cuda_static_runtime': True, 'cxx_static_runtime': True,
'kar_ple': False, 'kar_experts': False, 'ple_trace': False}}
canonical = (json.dumps(features, sort_keys=True, indent=2) + '\n').encode()
self.provenance['build_features'] = features
self.provenance['build_features_sha256'] = hashlib.sha256(canonical).hexdigest()
(self.pkg/b.NAME).write_bytes(b'not executable; validator does not execute input')
self.write()
@@ -46,6 +55,46 @@ class PackageTests(unittest.TestCase):
b.check_glibc(p, 'glibc 2.39\n')
with self.assertRaises(ValueError): b.check_glibc(p, 'musl 1.2.5')
def test_static_cuda_feature_receipt_is_preserved_and_digest_checked(self):
features = {'schema_version': 1, 'source_revision': 'a'*40,
'cuda_architectures': '120',
'features': {'cuda': True, 'cuda_static_runtime': True, 'cxx_static_runtime': True, 'kar_ple': True,
'kar_experts': False, 'ple_trace': False}}
canonical = (json.dumps(features, sort_keys=True, indent=2) + '\n').encode()
self.provenance['build_features'] = features
self.provenance['build_features_sha256'] = hashlib.sha256(canonical).hexdigest()
self.write()
p = self.freeze()
self.assertTrue(p['build_features']['features']['kar_ple'])
self.provenance['build_features_sha256'] = '0'*64
self.write()
shutil.rmtree(self.stage)
self.stage.mkdir()
with self.assertRaisesRegex(ValueError, 'digest mismatch'):
self.freeze()
def test_image_receipt_carries_ple_profile_without_gpu_claim(self):
self.provenance['build_features']['features']['kar_ple'] = True
canonical = (json.dumps(self.provenance['build_features'], sort_keys=True, indent=2) + '\n').encode()
self.provenance['build_features_sha256'] = hashlib.sha256(canonical).hexdigest()
self.write()
args = SimpleNamespace(base=b.BASE, package=self.pkg, receipt_sha256=self.sha, cpu_fixture=False)
image = 'sha256:' + 'c'*64
calls = []
def docker(*argv, **kwargs):
calls.append(argv)
if argv[0] == 'build':
Path(argv[argv.index('--iidfile')+1]).write_text(image)
return SimpleNamespace(stdout='')
engine_info = json.dumps(self.provenance['engine'])
with patch.object(b, 'docker', side_effect=docker), \
patch.object(b, 'isolated_run', side_effect=['glibc 2.43', engine_info, 'help']):
result = b.assemble(args)
self.assertEqual(result['build_features']['kar_ple'], True)
self.assertEqual(result['build_features_sha256'], self.provenance['build_features_sha256'])
self.assertFalse(result['gpu_tested'])
self.assertFalse(any('--gpus' in call for call in calls))
def test_pinned_receipt_rejects_replaced_hashes(self):
(self.pkg/'SHA256SUMS').write_text('a'*64 + ' ../outside\n')
with self.assertRaisesRegex(ValueError, 'pinned receipt'): self.freeze()