interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / om / pipeline / seal-reuse-mutants.py

35 lines · 2198 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2# External source-mutant verification, not a production dependency.
3import hashlib,os,subprocess,tempfile
4from pathlib import Path
5root=Path(__file__).resolve().parents[2]
6source=(root/'om/pipeline/seal_reuse.om').read_text()
7mutants={
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}
14ident=(root/'src/cudapp_om_closure_reseal.ident').read_text().strip()
15pins=dict(part.split('=',1) for part in ident.split() if '=' in part)
16assert hashlib.sha256(Path(os.environ['OMEGA_OMC']).read_bytes()).hexdigest()==pins['omc']
17paths=ident.split(' path=',1)[1].split('=',1)[1].split(',')
18assert paths[-1]=='om/pipeline/seal_reuse.om'
19prefix='\n'.join((root/p).read_text() for p in paths[:-1])+'\n'
20env=dict(os.environ,OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC'])
21bridge=Path(os.environ['OMEGA_BRIDGE'])/'tools/bridge-seeded'
22assert hashlib.sha256(bridge.read_bytes()).hexdigest()==pins['frontend']
23assert hashlib.sha256((bridge.parent.parent/'src/toc.om').read_bytes()).hexdigest()==pins['converter']
24with 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)