Files
nvdriver/tools/generate_timeout_oracle.py
nvidia-driver-rs 4526e6a816 Baseline: validated 30/30 tree with passing Level 7 hardware regression
- Updated tools/post_reboot.sh to check kernel oops taint bit and stuck driver tasks instead of <86400s uptime
- Level 7 hardware regression passed on 0000:b3:00.0 (module 37e6fa430835eee2b426019db3ad70eeb7a9e9070c09c84bd9b973cf56cbe529, 107 inventory words, 0 static mismatches, CUDA baseline verified before and after)
- Updated .gitignore to exclude build archives (*.a, *.rlib), __pycache__, and raw trace dumps
2026-11-23 23:48:38 +00:00

52 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""Run unchanged exact-version public C functions against explicit test services."""
from pathlib import Path
import argparse,hashlib,json,subprocess,tempfile
parser=argparse.ArgumentParser();parser.add_argument('--check',action='store_true');args=parser.parse_args()
R=Path(__file__).resolve().parent.parent
source=Path('/home/geodd/nvidia-driver/analysis-580.178.04/reference/open-gpu-kernel-modules-580.178.04/src/nvidia/src/kernel/gpu/gpu_timeout.c')
header=source.parents[3]/'inc/kernel/gpu/gpu_timeout.h'
text=source.read_text();h=header.read_text()
functions='void\n'+text[text.index('timeoutSet\n'):text.index('/*!\n * @brief Wait for a condition')]
defines='\n'.join(line for line in h.splitlines() if line.startswith('#define GPU_TIMEOUT_'))
types=h[h.index('typedef struct\n'):h.index('/*!\n * @brief A prototype')]
harness=r'''
int main(void){
OBJGPU own={0},parent={0};own.parent=&parent;parent.parent=&parent;
own.attached=parent.attached=true;own.full_power=parent.full_power=true;
own.getProperty=parent.getProperty=property;own.timer.now=parent.timer.now=1000;
TIMEOUT_DATA data={0};data.defaultus=17;data.pGpu=&own;
unsigned modes[]={0,8,16,32,128,24,40,160};
for(unsigned m=0;m<8;m++)for(unsigned extra=0;extra<32;extra++)
for(unsigned duration=0;duration<3;duration++)for(unsigned ts=0;ts<3;ts++){
unsigned requested=duration==0?0:(duration==1?1:200);
unsigned flags=modes[m]|((extra&1)?1:0)|((extra&2)?2:0)|((extra&4)?4:0)|((extra&8)?64:0)|((extra&16)?256:0);
data.defaultFlags=8;cpu_now=1000;tick_resolution=100;
thread_status=ts==0?0:(ts==1?0x40:0x65);
RMTIMEOUT timeout;timeoutSet(&data,&timeout,requested,flags);
NvU64 initial=timeout.timeout;unsigned initial_flags=timeout.flags;
unsigned selected=timeout.pTmrGpu==&parent?2:(timeout.pTmrGpu==&own?1:0);
cpu_now=2000;parent.timer.now=own.timer.now=2000;
unsigned status=timeoutCheck(&data,&timeout,0x2a3);
printf("(%u,%u,%u,%llu,%u,%u,%u,%llu,%u),\n",requested,flags,thread_status,(unsigned long long)initial,initial_flags,selected,status,(unsigned long long)timeout.timeout,timeout.flags);
parent.timer.now=own.timer.now=1000;
}
}
'''
with tempfile.TemporaryDirectory(prefix='nv-rs-timeout-') as tmp:
p=Path(tmp);c=p/'oracle.c';binary=p/'oracle'
c.write_text('#include "'+str(R/'tests/oracles/timeout-shim.h')+'"\n'+defines+'\n'+types+'\n'+functions+'\n'+harness)
subprocess.run(['cc','-std=c11','-Werror','-Wno-error=cpp',str(c),'-o',str(binary)],check=True)
output=subprocess.check_output([str(binary)],text=True)
rows=output.splitlines();destination=R/'tests/oracles/timeout-vectors.rs'
generated='// Unchanged exact-version public C policy, mocked service inputs.\n[\n'+output+']\n'
if args.check:
if destination.read_text()!=generated:raise SystemExit('Timeout C oracle vectors differ; regenerate and investigate')
else:destination.write_text(generated)
report={'cases':len(rows),'original_source':str(source),'source_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'header_sha256':hashlib.sha256(header.read_bytes()).hexdigest(),'functions_sha256':hashlib.sha256(functions.encode()).hexdigest(),'vectors_sha256':hashlib.sha256(generated.encode()).hexdigest(),'test_service_sha256':hashlib.sha256((R/'tests/oracles/timeout-shim.h').read_bytes()).hexdigest(),'compiler_version':subprocess.check_output(['cc','--version'],text=True),'compile_flags':['-std=c11','-Werror','-Wno-error=cpp'],'limitations':['Clock/thread services are test inputs, not original RM execution.','Applicable original binary paths were independently inspected through REA.','This oracle compares status/state, not logging or physical GPU timing.']}
report_path=R/'reports/gpu-timeout-oracle.json'
if args.check:
if json.loads(report_path.read_text())!=report:raise SystemExit('Timeout oracle provenance differs')
else:report_path.write_text(json.dumps(report,indent=2)+'\n')
print(json.dumps(report,indent=2))