45 lines
1.9 KiB
Python
45 lines
1.9 KiB
Python
"""Run against built shared objects on Linux, including abort-on-ABI-change cases.
|
|
|
|
Usage: python3 run_nvfbc_adapter.py /absolute/adapter.so /absolute/stub.so
|
|
"""
|
|
import ctypes
|
|
import os
|
|
from pathlib import Path
|
|
import resource
|
|
import signal
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
if len(sys.argv) > 3:
|
|
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
|
|
library = ctypes.CDLL(sys.argv[2], mode=ctypes.RTLD_GLOBAL)
|
|
library.run_test.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
|
|
library.run_test.restype = ctypes.c_int
|
|
raise SystemExit(library.run_test(*(int(v) for v in sys.argv[3:])))
|
|
|
|
adapter, stub = [str(Path(p).resolve(strict=True)) for p in sys.argv[1:]]
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
for case, leased, headless in [(0, 0, 0), (1, 1, 0), (2, 1, 1),
|
|
(2, 0, 1), (3, 1, 1), (4, 1, 1),
|
|
(5, 1, 1), (6, 1, 1), (7, 1, 1), (8, 1, 1)]:
|
|
env = dict(os.environ, LD_PRELOAD=adapter,
|
|
VDI_CURSOR_RECEIPT=str(Path(directory) / 'receipt'))
|
|
env.pop('VDI_CURSOR_LEASE', None)
|
|
env.pop('VDI_NVFBC_HEADLESS', None)
|
|
if leased:
|
|
env['VDI_CURSOR_LEASE'] = 'c' * 32
|
|
if headless:
|
|
env['VDI_NVFBC_HEADLESS'] = '1'
|
|
result = subprocess.run([sys.executable, __file__, adapter, stub,
|
|
str(case), str(leased), str(headless)], env=env)
|
|
expected = -signal.SIGABRT if case in (7, 8) else 0
|
|
assert result.returncode == expected, (case, leased, headless, result.returncode)
|
|
if leased or headless:
|
|
receipt = (Path(directory) / 'receipt').read_text()
|
|
if case == 6:
|
|
assert receipt == 'nvfbc-ready-v1\n', receipt
|
|
elif case not in (7, 8):
|
|
assert receipt == 'nvfbc-v1\n', receipt
|
|
print('PASS', case, 'lease', leased, 'headless', headless, flush=True)
|