CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / om / pipeline / seal-reuse-mutants.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | # External source-mutant verification, not a production dependency. |
| 3 | import hashlib,os,subprocess,tempfile |
| 4 | from pathlib import Path |
| 5 | root=Path(__file__).resolve().parents[2] |
| 6 | source=(root/'om/pipeline/seal_reuse.om').read_text() |
| 7 | mutants={ |
| 8 | 'ignore_all_bytes':('same = false','same = same'), |
| 9 | 'ignore_count':('same = and eq get cache 0 1 eq ulong get cache 1 n','same = eq get cache 0 1'), |
| 10 | 'ignore_one_byte':('if ne get b i get cache add 64 i\nsame = false\nend','if ne i 1024\nif ne get b i get cache add 64 i\nsame = false\nend\nend'), |
| 11 | 'wrong_normalization':('and ge i 48 lt i 52','and ge i 49 lt i 52'), |
| 12 | 'dirty_refusal':('mc_clear edit out\nif or eq n 0','if or eq n 0'), |
| 13 | } |
| 14 | ident=(root/'src/cudapp_om_closure_reseal.ident').read_text().strip() |
| 15 | pins=dict(part.split('=',1) for part in ident.split() if '=' in part) |
| 16 | assert hashlib.sha256(Path(os.environ['OMEGA_OMC']).read_bytes()).hexdigest()==pins['omc'] |
| 17 | paths=ident.split(' path=',1)[1].split('=',1)[1].split(',') |
| 18 | assert paths[-1]=='om/pipeline/seal_reuse.om' |
| 19 | prefix='\n'.join((root/p).read_text() for p in paths[:-1])+'\n' |
| 20 | env=dict(os.environ,OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC']) |
| 21 | bridge=Path(os.environ['OMEGA_BRIDGE'])/'tools/bridge-seeded' |
| 22 | assert hashlib.sha256(bridge.read_bytes()).hexdigest()==pins['frontend'] |
| 23 | assert hashlib.sha256((bridge.parent.parent/'src/toc.om').read_bytes()).hexdigest()==pins['converter'] |
| 24 | with tempfile.TemporaryDirectory(prefix='seal-reuse-mutants-') as t: |
| 25 | t=Path(t) |
| 26 | for name,(old,new) in mutants.items(): |
| 27 | assert source.count(old)==1,(name,source.count(old)) |
| 28 | om=t/(name+'.om');om.write_text(prefix+source.replace(old,new)) |
| 29 | c=t/(name+'.c');so=t/(name+'.so') |
| 30 | with c.open('w') as f:subprocess.run(['sh',str(bridge),'c',str(om)],env=env,stdout=f,check=True) |
| 31 | subprocess.run([os.environ.get('CC','cc'),os.environ.get('CUDAPP_SEAL_OPT','-O3'),'-shared','-fPIC',str(c),'-o',str(so)],check=True) |
| 32 | p=subprocess.run(['python3',str(root/'om/pipeline/seal-reuse-check.py'),str(so)],capture_output=True,text=True) |
| 33 | assert p.returncode!=0,name+' escaped oracle' |
| 34 | assert 'AssertionError' in p.stderr,(name,p.stderr) |
| 35 | print(name+': caught',flush=True) |