Files
nvdriver/reports/checkpoints/timer-init-35ddcd8b4a9e/tools/check_system_time_source.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
2.5 KiB
Python

#!/usr/bin/env python3
"""Compare unchanged shipped OS time conversion with the Linux adapter body."""
import hashlib,json,subprocess
from pathlib import Path
R=Path(__file__).resolve().parents[1]
original=Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/os-interface.c')
replacement=R/'kernel-open/nvidia/clock_adapter.c'
def body(text,signature):
start=text.index(signature);pos=text.index('{',start);depth=0
for end in range(pos,len(text)):
depth+=(text[end]=='{')-(text[end]=='}')
if depth==0:return text[start:end+1]
raise ValueError(signature)
prologue='''#include <stdint.h>
#include <stdio.h>
#include <assert.h>
typedef uint32_t u32;
typedef uint32_t NvU32;
typedef uint32_t NV_STATUS;
#define NV_API_CALL
#define NV_OK 0
#define NSEC_PER_USEC 1000
struct timespec64 { int64_t tv_sec; long tv_nsec; };
static struct timespec64 clock_value;
static void ktime_get_real_ts64(struct timespec64 *out) { *out=clock_value; }
'''
epilogue='''
int main(void) {
int64_t seconds[]={0,1,-1,INT32_MAX,UINT32_MAX,INT64_C(4294967296),INT64_MAX};
long nanoseconds[]={0,1,999,1000,999999999};
unsigned count=0;
for(unsigned s=0;s<sizeof(seconds)/sizeof(seconds[0]);s++) {
for(unsigned n=0;n<sizeof(nanoseconds)/sizeof(nanoseconds[0]);n++) {
uint32_t old_s=0,old_u=0,new_s=0,new_u=0;
clock_value=(struct timespec64){seconds[s],nanoseconds[n]};
assert(os_get_system_time(&old_s,&old_u)==0);
nv_rs_clock_system_time(&new_s,&new_u);
assert(old_s==new_s && old_u==new_u);
count++;
}
}
printf("%u\\n",count);
}
'''
out=R/'target/system-time-source';out.mkdir(parents=True,exist_ok=True)
c=out/'original-and-replacement.c';exe=out/'comparison'
c.write_text(prologue+body(original.read_text(),'NV_STATUS NV_API_CALL os_get_system_time(')+'\n'+body(replacement.read_text(),'void nv_rs_clock_system_time(')+epilogue)
subprocess.run(['cc','-std=c11','-Wall','-Wextra','-Werror',str(c),'-o',str(exe)],check=True)
cases=int(subprocess.check_output([str(exe)],text=True));assert cases==35
report={'passed':True,'cases':cases,'source_sha256':{str(p):hashlib.sha256(p.read_bytes()).hexdigest() for p in [original,replacement]},'scope':'Unchanged original and adapter conversion bodies compiled with the same scripted ktime_get_real_ts64. Includes negative/wrapping seconds and microsecond truncation. Does not compare simultaneous live wall-clock samples.'}
(R/'reports/system-time-source.json').write_text(json.dumps(report,indent=2)+'\n');print(cases,'original/adapter system-time conversion cases')