Files
leleka/scripts/smoke-gpu-requirement.py
Pavlo Ratushnyi 4013e0c9bd
Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
Import tracked Strata Next source snapshot
2026-10-05 18:15:08 +02:00

122 lines
5.2 KiB
Python

#!/usr/bin/env python3
"""CPU fixtures for explicit CUDA driver policy. Never runs inference or CUDA."""
import json
import os
from pathlib import Path
import socket
import subprocess
import sys
import tempfile
import time
def main():
binary = str(Path(sys.argv[1]).resolve())
if sys.platform == 'linux' and Path('/proc/driver/nvidia/version').exists():
raise SystemExit('Requires an isolated CPU runner without an installed NVIDIA kernel driver')
with tempfile.TemporaryDirectory(prefix='strata-driver-gate-') as tmp:
root = Path(tmp).resolve()
probe = root / 'nvidia-smi'
marker = root / 'probe-called'
worker_marker = root / 'worker-called'
worker = root / 'worker'
worker.write_text(f'#!/bin/sh\n: > "{worker_marker}"\nexit 1\n')
worker.chmod(0o700)
path = root / 'config.json'
env = {'PATH': str(root)}
with socket.socket() as sock:
sock.bind(('127.0.0.1', 0))
port = sock.getsockname()[1]
config = {'bind': f'127.0.0.1:{port}', 'engine': {'executable': str(worker)}}
count = 0
def run(command='provision', ok=False, contains=None, timeout=10):
nonlocal count
path.write_text(json.dumps(config))
started = time.monotonic()
result = subprocess.run([binary, command, '--config', str(path)], env=env,
capture_output=True, text=True, timeout=timeout)
assert (result.returncode == 0) == ok, (result.stdout, result.stderr)
if contains:
assert contains in result.stderr, result.stderr
assert not worker_marker.exists(), 'worker started before policy/asset checks'
assert not (root / 'output').exists()
assert not (root / '.output.strata-stage').exists()
with socket.socket() as sock:
assert sock.connect_ex(('127.0.0.1', port)) != 0, 'listener opened'
count += 1
return result, time.monotonic() - started
def fake(body):
marker.unlink(missing_ok=True)
probe.write_text(f'#!/bin/sh\nprintf called > "{marker}"\n{body}\n')
probe.chmod(0o700)
# CPU profiles do not query the driver. check-config stays read-only.
fake('exit 1')
run(ok=True)
assert not marker.exists()
config['gpu_requirement'] = 'cuda-13.0-linux'
result, _ = run('check-config', ok=True)
report = json.loads(result.stdout)
assert report['gpu_requirement'] == 'cuda-13.0-linux'
assert report['gpu_requirement_checked'] is False
assert not marker.exists()
config['gpu_requirement'] = 'unknown'
run()
config['gpu_requirement'] = 'cuda-13.0-linux'
engine = config.pop('engine')
run(contains='requires an engine executable')
config['engine'] = engine
# An absent manifest proves failure happens before asset acquisition.
config['assets'] = [{'manifest': str(root / 'absent.json'), 'directory': str(root / 'output')}]
if sys.platform != 'linux':
run(contains='requires Linux')
run('serve', contains='requires Linux')
assert not marker.exists()
print(f'{count} driver policy scenarios passed; Linux probe cases require hosted CPU runner')
return
probe.unlink()
run(contains='driver unavailable')
cases = [
("printf '579.99.99\\n'", 'below'),
("printf '580.65.05\\n'", 'below'),
("printf '580.65.06\\n580.1.0\\n'", 'below'),
("printf 'secret malformed output\\n'", 'malformed'),
("printf '580.65.06\\n'; exit 1", 'query failed'),
("printf ''", 'malformed'),
("printf '580.65.06\\nBAD\\n'", 'malformed'),
("i=0; while [ $i -lt 9000 ]; do printf x; i=$((i+1)); done", 'exceeded 8 KiB'),
]
for body, error in cases:
fake(body)
run(contains=error)
run('serve', contains=error)
assert marker.exists()
# Bounded probe is killed/reaped. exec keeps the PID unambiguous.
pid_path = root / 'probe.pid'
fake(f'printf "%s" "$$" > "{pid_path}"\nexec /bin/sleep 60')
_, elapsed = run(contains='timed out after 5 seconds')
assert 4.5 <= elapsed < 9, elapsed
pid = int(pid_path.read_text())
try:
os.kill(pid, 0)
except ProcessLookupError:
pass
else:
raise AssertionError('timed-out probe still alive or unreaped')
# Accepted versions proceed to manifest lookup, and no farther.
for version in ['580.65.06', '580.100.0', '600.1.0']:
fake(f"printf '{version}\\n'")
result, _ = run()
assert 'NVIDIA' not in result.stderr, result.stderr
assert marker.exists()
config.pop('assets')
run(ok=True)
config['assets'] = [{'manifest': str(root / 'absent.json'), 'directory': str(root / 'output')}]
print(f'{count} driver policy scenarios passed; CPU fixtures only, no GPU readiness claim')
if __name__ == '__main__':
main()