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/uvme_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 / uvme_check.py` 398 lines ยท 19119 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Independent fake-kernel CUSE byte oracle; real processes, sockets and eventfd. 4 No NVIDIA, VFIO, /dev/cuse, privileged ioctl, or device word is executed. 5 """ 6 import argparse 7 import hashlib 8 import multiprocessing as mp 9 import os 10 from pathlib import Path 11 import selectors 12 import signal 13 import socket 14 import struct 15 import subprocess 16 import sys 17 import tempfile 18 import time 19 import traceback 20 sys.dont_write_bytecode = True 21 import uvms_check as service 22 23 ROOT = Path(__file__).resolve().parents[1] 24 PREFIX = ['taskset', '-c', '10-14', 'nice', '-n', '10'] 25 OMC = ROOT.parent/'omega-mv-vfioirq/seed/out/omc' 26 PIN = '`78122a72a7bb7129271088b30093e8b3b9b52f8d`' 27 SHA = '`734bf4f3f858d56288902700cf581cdbaa4a24d1b3254a2beea014aaccf0fa38`' 28 QUEUE = '`b06b3f9a3dd1e74a3099350760cb3d26a3f33577`' 29 SIZES = {`805306369`:16,37:40,38:20,23:16,33:9264,34:24,25:32,39:8} 30 MUTANTS = { 31 'endpoint': [ 32 ('if ne size add need 72', 'if lt size add need 72'), 33 ('i = epfind epget 40 8\nif eq i 8\nepbegin -9 0\nret\nend\nif ne epget 48', 'i = ulong 0\nif eq i 8\nepbegin -9 0\nret\nend\nif ne epget 48'), 34 ('put epclnt base 0', 'put epclnt base get epclnt base'), 35 ('r = fclose get epdevice 0', 'r = long 0'), 36 ('r = send fd epwire add off pos sub n pos 0', 'r = write fd epwire add off pos sub n pos'), 37 ], 38 'notify': [('put unbytes 0 1', 'put unbytes 0 2'), ('put unlive 0 2', 'put unlive 0 0')], 39 } 40 41 def compile_omega(tmp, target='endpoint', mutation=None): 42 if hashlib.sha256(OMC.read_bytes()).hexdigest() != SHA: 43 raise AssertionError('compiler binary pin mismatch') 44 actual = subprocess.check_output(['git','-C',str(OMC.parents[2]),'rev-parse','HEAD'],text=True).strip() 45 if actual != PIN: 46 raise AssertionError('compiler source pin mismatch') 47 def dep(path): 48 return subprocess.check_output(['git','-C',str(ROOT.parent/'DriverOmega'),'show',QUEUE+':'+path],text=True) 49 queue = dep('gsp/irqqueue.om') 50 queue = queue[queue.index('note Explicit model-only UVM command queue'):] 51 units = ['fmt','pt','fault'] 52 parts = ['om2', 'abstract unirq ulong'] + [(ROOT/'uvm'/f'{u}.om').read_text() for u in units] 53 parts += [queue, dep('gsp/irqcmd.om')] 54 for u in service.UNITS + ['notify'] + (['endpoint'] if target == 'endpoint' else []): 55 text = (ROOT/'uvm'/f'{u}.om').read_text() 56 if u == 'notify': 57 text = text.replace('abstract unirq ulong\n', '') 58 if mutation and u == mutation[0]: 59 if text.count(mutation[1]) != 1: 60 raise AssertionError(f'mutant site count {u}: {text.count(mutation[1])}') 61 text = text.replace(mutation[1],mutation[2]) 62 parts.append(text) 63 if target == 'notify': 64 parts.append((ROOT/'tests/uvme_notify.om').read_text()) 65 src = '\n'.join(parts) 66 out = tmp/(target+('-mutant' if mutation else '')) 67 p = subprocess.run(PREFIX+[str(OMC)],input=src.encode(),capture_output=True,timeout=120) 68 if p.returncode: 69 import re 70 m = re.search(r'line (\d+)',p.stderr.decode()) 71 context = '' 72 if m: 73 n = int(m[1]); context = '\n'.join(f'{i+1}: {x}' for i,x in enumerate(src.splitlines()) if n-5 <= i <= n+2) 74 raise AssertionError(f'compile rc={p.returncode}: {p.stderr.decode()}\n{context}') 75 out.write_bytes(p.stdout); out.chmod(0o755) 76 if not mutation: 77 print(f'{target} SOURCE sha256={hashlib.sha256(src.encode()).hexdigest()} BINARY sha256={hashlib.sha256(p.stdout).hexdigest()}',flush=True) 78 return out 79 80 def abi(tmp): 81 out = tmp/'offsets' 82 subprocess.run(PREFIX+['cc','-std=c11','-Wall','-Wextra','-Werror',str(ROOT/'tests/uvme_offsets.c'),'-o',str(out)],check=True) 83 p = subprocess.run(PREFIX+[str(out)],capture_output=True,text=True,check=True) 84 expected = '''fuse_in_header 40 85 fuse_in_header.unique 8 86 fuse_in_header.pid 32 87 fuse_in_header.total_extlen 36 88 fuse_out_header 16 89 fuse_out_header.error 4 90 fuse_out_header.unique 8 91 cuse_init_in 16 92 cuse_init_out 72 93 cuse_init_out.flags 12 94 cuse_init_out.max_read 16 95 cuse_init_out.spare 32 96 fuse_open_in 8 97 fuse_open_out 16 98 fuse_open_out.open_flags 8 99 fuse_release_in 24 100 fuse_flush_in 24 101 fuse_ioctl_in 32 102 fuse_ioctl_in.flags 8 103 fuse_ioctl_in.cmd 12 104 fuse_ioctl_in.arg 16 105 fuse_ioctl_in.in_size 24 106 fuse_ioctl_in.out_size 28 107 fuse_ioctl_out 16 108 fuse_ioctl_out.flags 4 109 fuse_ioctl_out.in_iovs 8 110 fuse_ioctl_out.out_iovs 12 111 fuse_ioctl_iovec 16 112 fuse_ioctl_iovec.len 8 113 flags 1 2 4 33 114 ''' 115 assert p.stdout == expected, (p.stdout,expected) 116 print('CUSE ABI PASS sizeof/offsetof measured by host cc; header-sha256='+hashlib.sha256(Path('/usr/include/linux/fuse.h').read_bytes()).hexdigest(),flush=True) 117 118 def packet(op, seq, body=b'', pid=None, ext=0): 119 return struct.pack('deadline: raise AssertionError('concurrent clients timed out') 273 for key,_ in mux.select(1): 274 conn=key.data; op,data=conn.recv() 275 if op=='frame': conn.send(s.raw(data)) 276 elif op=='done': 277 done.append(data); mux.unregister(conn.fileno()) 278 else: raise AssertionError(data) 279 for p,conn in workers: 280 p.join(5); assert p.exitcode==0, p.exitcode 281 assert len({x[0] for x in done})==2 282 assert not s.children(), s.children() 283 return done 284 finally: 285 mux.close() 286 for p,conn in workers: 287 conn.close() 288 if p.is_alive(): p.terminate(); p.join(5) 289 290 291 def endpoint_suite(binary, quiet=False): 292 s=Server(binary) 293 try: 294 s.init() 295 done=concurrent_clients(s) 296 a=s.opened(); apid=s.children()[0]; b=s.opened() 297 assert a not in [x[0] for x in done] and b>a 298 # This deliberately exceeds the in-flight frame deadline, with no partial request. 299 time.sleep(5.1) 300 s.descriptors() 301 # Kernel may abandon a copyin attempt; no global pending retry state is held. 302 for fh in (a,b): 303 s.call(39,ioctl_body(fh,39),output=struct.pack('<4i',0,4,1,1)+struct.pack('<4Q',65536,8,65536,8)) 304 for flags in (0,1,3,4,8,16,32): 305 s.call(39,ioctl_body(a,39,flags=flags),error=-22) 306 for cmd in (0,999,`4294967295`): s.call(39,ioctl_body(a,cmd),error=-22) 307 for cmd,size in SIZES.items(): 308 for data in (bytes(1),bytes(size+1)): 309 s.call(39,ioctl_body(a,cmd,data),error=-22) 310 s.call(39,ioctl_body(a,cmd,bytes(size),outs=size+1),error=-22) 311 s.call(39,ioctl_body(a,cmd,bytes(size))+b'x',error=-22) 312 for addr in (0,`281474976710656`,`18446744073709551615`,`281474976710655`): 313 s.call(39,ioctl_body(a,39,arg=addr),error=-14) 314 s.call(39,ioctl_body(a,39)+b'x',error=-22) 315 s.call(39,bytes(31),error=-22) 316 s.call(14,bytes(8),error=-71,ext=1) 317 s.call(25,struct.pack('