Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-gpu-driver/blob/main/tests/rme_check.py # omega-gpu-driver aien-dev/omega-gpu-driver Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-gpu-driver / tests / rme_check.py` 259 lines ยท 14712 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Independent model/vendor oracles and fake CUSE kernel. No device node is opened. 3 Run ONLY inside the repository's device-hiding bwrap safety boundary. 4 """ 5 import argparse, hashlib, os, random, select, signal, socket, struct, subprocess, tempfile 6 from pathlib import Path 7 ROOT=Path(__file__).resolve().parents[1] 8 OMC=Path(os.environ.get('RM_OMC',str(ROOT.parents[1]/'omega-mv/seed/out/omc'))) 9 SHA=dict(line.split('=',1) for line in (ROOT/'rm/omc.pin').read_text().splitlines() if line and not line.startswith('#'))['OMC_SHA256'] 10 OGKM=Path(os.environ.get('OGKM',str(Path.home()/'workspace/_ext/open-gpu-kernel-modules-580.173.02'))) 11 UNITS=['chan/params.om','gsp/rpc.om','rm/ioctl.om','rm/handles.om','rm/memory.om','rm/model.om','rm/uvmclient.om','rm/dispatch.om','rm/import.om','rm/endpoint.om'] 12 SIZES={43:32,42:32,41:16,78:56,79:32,87:64,88:48,74:184,200:4608,201:4,206:16,207:16,210:72} 13 CLASSES={65:0,128:56,8320:4,37105:56,41068:20,36967:12,51567:368,52928:0} 14 PARENTS={128:65,8320:128,37105:128,41068:128,36967:41068,51567:41068,52928:51567} 15 STATUS={0:0,1:31,2:51,3:54,4:52,5:81,6:86} 16 TOKEN=0xc36f0108;SCHED=0xa06c0101 17 18 def build(tmp, mutation=None, trace=False): 19 if hashlib.sha256(OMC.read_bytes()).hexdigest()!=SHA: raise RuntimeError('RM compiler pin mismatch') 20 parts=['om2'] 21 for unit in UNITS: 22 text=(ROOT/unit).read_text() 23 if trace and unit=='rm/endpoint.om':text=text.split('fn main to int\n',1)[0] 24 if mutation and unit==mutation[0]: 25 old,new=mutation[1:] 26 if text.count(old)!=1: raise RuntimeError(f'mutation site {unit}: {text.count(old)}') 27 text=text.replace(old,new) 28 parts.append(text) 29 if trace: parts.append((ROOT/'tests/rme_trace.om').read_text()) 30 src='\n'.join(parts);(tmp/'rme.om').write_text(src) 31 p=subprocess.run([str(OMC)],input=src.encode(),capture_output=True) 32 if p.returncode: 33 import re 34 msg=p.stderr.decode();m=re.search(r'line (\d+)',msg) 35 if m: 36 n=int(m[1]);msg+='\n'+'\n'.join(f'{j+1}: {s}' for j,s in enumerate(src.splitlines()) if n-6<=j<=n+3) 37 raise RuntimeError(msg) 38 binary=tmp/'rme';binary.write_bytes(p.stdout);binary.chmod(0o700) 39 return binary 40 41 def cc(tmp,name): 42 inc=['src/common/sdk/nvidia/inc','kernel-open/common/inc','src/nvidia/arch/nvalloc/unix/include','src/common/inc'] 43 out=tmp/name 44 subprocess.run(['cc','-std=c11','-O1','-Wall','-Wextra','-Werror',*[f'-I{OGKM/p}' for p in inc],str(ROOT/'tests'/f'{name}.c'),'-o',str(out)],check=True) 45 return out 46 47 def layout(tmp): 48 text=subprocess.check_output([str(cc(tmp,'rme_offsets'))],text=True) 49 expected={'alloc':32,'alloc.ptr':16,'alloc.size':24,'alloc.status':28,'control':32,'control.ptr':16,'control.size':24,'control.status':28,'free':16,'free.status':12,'map':56,'map.fd':48,'map.status':40,'unmap':32,'unmap.status':24,'mapdma':64,'mapdma.status':56,'unmapdma':48,'unmapdma.status':40,'heap':184,'heap.status':20,'card':72,'register':4,'event':16,'event.status':12,'version':72,'xfer':16} 50 expected.update({'gr':32,'gr.ptr':8,'classes':16,'gid':268,'idv2':32}) 51 got={line.split()[0]:int(line.split()[1]) for line in text.splitlines() if len(line.split())==2} 52 assert got==expected,(got,expected) 53 assert 'escapes 43 42 41 78 79 87 88 74 200 201 206 210\n' in text 54 assert 'status 31 51 54 52 81 86\n' in text 55 print('RM vendor 580.173.02 layout oracle PASS') 56 57 class Server: 58 def __init__(self,binary): 59 self.sock,child=socket.socketpair(socket.AF_UNIX,socket.SOCK_SEQPACKET);self.sock.settimeout(8) 60 self.proc=subprocess.Popen([str(binary),'--fake','--host-model',str(ROOT/'rm/host-model.fixture')],stdin=child,stdout=child,stderr=subprocess.PIPE,start_new_session=True);child.close();self.seq=0 61 self.frame(4096,struct.pack('=16 65 n,err,seq=struct.unpack_from('