#!/usr/bin/env python3 """CPU-only original conftest/C vs Rust/config differential; no driver calls.""" import ctypes import hashlib import importlib.util import itertools import json import os from pathlib import Path import re import subprocess import tempfile ROOT = Path(__file__).resolve().parents[1] ARTIFACT = Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel') NAMES = ('VGX_BUILD', 'VGX_KVM_BUILD', 'VGX_DEVICE_VM_BUILD') CASES = ('dom0_kernel_present', 'nvidia_vgpu_kvm_build', 'device_vm_build') DEFINES = ('NV_DOM0_KERNEL_PRESENT', 'NV_VGPU_KVM_BUILD', 'NV_DEVICE_VM_BUILD') CFG = ('nv_rs_vgx_dom0', 'nv_rs_vgx_kvm', 'nv_rs_vgx_device_vm') def run(argv, **kwargs): return subprocess.check_output(argv, text=True, **kwargs).strip() def main(): spec = importlib.util.spec_from_file_location('product', ROOT/'tools/timer-timeout-build-product.py') product = importlib.util.module_from_spec(spec) spec.loader.exec_module(product) source_paths = [ARTIFACT/'conftest.sh', ARTIFACT/'nvidia/os-interface.c', ARTIFACT/'common/inc/nv-linux.h'] conftest, os_source, header = [p.read_text() for p in source_paths] # Execute exact extracted shell branches, not translated Python booleans. branches = [re.search(r'(?m)^\s*'+case+r'\)\n(.*?)^\s*;;', conftest, re.S).group(1) for case in CASES] shell = 'append_conftest() { cat; }; probe() { case "$1" in\n' shell += ''.join(case+')\n'+body+'\n;;\n' for case, body in zip(CASES, branches)) shell += 'esac; }; for probe_case in '+ ' '.join(CASES)+'; do probe "$probe_case"; done' os_function = re.search(r'NvBool NV_API_CALL os_is_vgx_hyper\(void\)\n\{.*?\n\}', os_source, re.S).group() conditional = re.search(r'#if defined\(NV_DOM0_KERNEL_PRESENT\) \|\|.*?\n#define NV_VGX_HYPER', header).group()+'\n#endif\n' values = (None, '', '0', '1', ' ', '\t', "';$(touch NEVER_EXECUTE_VGX);#", 'line1\nline2') cfg_cases = 0 with tempfile.TemporaryDirectory(prefix='nv-vgx-test-') as temp: out = Path(temp) rustc = str(Path.home()/'.cargo/bin/rustc') executables = [] for mask in range(9): binary = out/f'provider-{mask}' args = [rustc, '--edition=2024', '-Dwarnings', str(ROOT/'tests/timer-timeout-vgx/provider.rs'), '-o', str(binary)] if mask != 8: args += ['--cfg=nv_rs_build_product_resolved'] args += ['--cfg='+cfg for bit,cfg in enumerate(CFG) if mask & (1<