Files
nvdriver/tools/generate_trace_fixtures.py
LIghtJUNction 32c8728037 Migrate the workspace and kernel crates to Rust edition 2024
Mechanical, behavior-neutral: edition/resolver keys, unsafe extern blocks,
unsafe(no_mangle)/unsafe(export_name), unsafe blocks inside unsafe fn,
r#gen renames, --edition flags in Makefiles/tools, rustfmt style_edition
pinned to 2021 so formatting stays edition-independent, and clippy
collapsible_if allowed workspace-wide (let-chain churn).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-12-02 01:52:38 +08:00

19 lines
2.5 KiB
Python

#!/usr/bin/env python3
from pathlib import Path
import json,hashlib
root=Path(__file__).resolve().parents[1];analysis=Path('/home/geodd/nvidia-driver/analysis-580.178.04/reports');p=analysis/'cuda-compute-exact-allocation-ioctl-payloads.jsonl';rows=[json.loads(x)for x in p.read_text().splitlines()]
def arr(h):return '['+','.join('0x'+h[i:i+2]for i in range(0,len(h),2))+']'
code=['// Generated immutable actual V100 trace fixtures. See reports/trace-fixture-provenance.json.','use nv_rs_abi::{RmAlloc,RmControl,Wire,NvStatus};','use nv_rs_core::{resources,controls};','#[test] fn recorded_allocation_wrappers_and_nested_lengths() {','let cases: &[([u8;48],[u8;48],usize,usize)] = &[']
aa=[x for x in rows if int(x['request'],16)&65535==0x462b]
for x in aa:code.append('('+arr(x['before'])+','+arr(x['after'])+','+str(len(bytes.fromhex(x['params_before'])))+','+str(len(bytes.fromhex(x['params_after'])))+'),')
code+= ['];let mut nonnull=0; for(before,after,nb,na) in cases { let b=RmAlloc::decode(before).unwrap();let a=RmAlloc::decode(after).unwrap(); assert_eq!(b.params_size,0);assert_eq!(a.status,0);let n=resources::parameter_size(b.class,b.params!=0).unwrap() as usize;assert_eq!(n,*nb);assert_eq!(n,*na); if b.params!=0 {nonnull+=1;} }assert_eq!(cases.len(),221);assert_eq!(nonnull,203);}','#[test] fn recorded_policy_queries() {']
cc=[]
for x in rows:
if int(x['request'],16)&65535!=0x462a:continue
if int.from_bytes(bytes.fromhex(x['before'])[8:12],'little')!=0x20808159:continue
cc.append(x);code+=['{let wrapper=RmControl::decode(&'+arr(x['after'])+').unwrap();assert_eq!(wrapper.params_size,332);assert_eq!(wrapper.status,0);let mut payload='+arr(x['params_before'])+';let expected='+arr(x['params_after'])+';assert_eq!(controls::fill_policy_query(&mut payload,&[controls::TriState::Zero;41]),NvStatus::OK);assert_eq!(payload,expected);}']
code+=['}'];assert len(cc)==8;(root/'src/nvidia/tests/recorded_trace.rs').write_text('\n'.join(code)+'\n');(root/'reports/trace-fixture-provenance.json').write_text(json.dumps({'source':str(p),'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'scope':'Actual bounded GPU7 CUDA41->42trace.221allocation wrappers,203nested length observations,8actual policy query inputs/outputs. Test uses zero state only for observed selectors12/37; does not establish zero policy globally or execute driver.','allocation_cases':len(aa),'policy_cases':len(cc)},indent=2)+'\n')
import subprocess
subprocess.run([str(Path.home()/".cargo/bin/rustfmt"),"--edition","2024",str(Path(__file__).resolve().parents[1]/"src/nvidia/tests/recorded_trace.rs")],check=True)