#!/usr/bin/env python3 """Exercise ELF dependency gates with CPU fixtures, without a CUDA toolchain.""" import importlib.util from pathlib import Path import shutil import subprocess import sys import tempfile import unittest spec = importlib.util.spec_from_file_location('audit', Path(__file__).with_name('check-static-cuda-elf.py')) audit = importlib.util.module_from_spec(spec) spec.loader.exec_module(audit) @unittest.skipUnless(sys.platform == 'linux' and shutil.which('cc') and shutil.which('readelf'), 'Linux C compiler and readelf required') class ElfGateTests(unittest.TestCase): def test_dependency_closure_and_host_path_rejection(self): with tempfile.TemporaryDirectory(prefix='strata-elf-gate-') as directory: root = Path(directory) source = root / 'fixture.c' source.write_text('#include \nint main(void) { puts("fixture"); return 0; }\n') executable = root / 'fixture' def compile(*extra): subprocess.run(['cc', str(source), '-o', str(executable), *extra], check=True, capture_output=True) compile() self.assertTrue(audit.inspect(executable)['host_glibc_required']) compile('-Wl,-rpath,/private/build/toolkit') with self.assertRaisesRegex(RuntimeError, 'build-host'): audit.inspect(executable) library_source = root / 'library.c' library_source.write_text('void fake_cuda_symbol(void) {}\n') library = root / 'libfixture.so' subprocess.run(['cc', '-shared', '-fPIC', str(library_source), '-Wl,-soname,libcudart.so.13', '-o', str(library)], check=True, capture_output=True) compile('-Wl,--no-as-needed', str(library)) with self.assertRaisesRegex(RuntimeError, 'libcudart.so.13'): audit.inspect(executable) if __name__ == '__main__': unittest.main()