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 / tests / dis_words_run.py

59 lines · 2982 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2"""Host-only word-policy differential, link refusal and source mutants."""
3import os
4from pathlib import Path
5import subprocess
6import sys
7root = Path(__file__).resolve().parents[1]
8os.chdir(root)
9out = Path(sys.argv[1] if len(sys.argv) > 1 else 'build/dis-words').resolve()
10out.mkdir(parents=True, exist_ok=True)
11base = ['gcc','-std=gnu11','-O0','--coverage','-Wall','-Wextra','-Werror','-Isrc',
12 'tests/dis_words_test.c','tests/dis_words_oracle.c','src/omega_sm121_disasm.c','src/cudapp_om_sm121_dis.c']
13def build(where, binding):
14 where.mkdir(parents=True, exist_ok=True)
15 subprocess.run(base + binding + ['-o',str(where/'check')],check=True)
16def run(where, args=(), good=True):
17 p = subprocess.run([str(where/'check'),*args],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
18 (where/('red.log' if args else 'run.log')).write_text(p.stdout)
19 if (p.returncode == 0) != good:
20 raise RuntimeError(p.stdout)
21 return p.stdout.strip()
22build(out,['src/cudapp_om_words.c'])
23print(run(out))
24run(out,['--plant'],False)
25print('RED planted difference rejected')
26p = subprocess.run(base+['-o',str(out/'missing')],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
27(out/'link-negative.log').write_text(p.stdout)
28assert p.returncode != 0 and 'omega_dis_words' in p.stdout
29print('STRONG LINK missing Omega refused')
30cli = ['gcc','-O2','-Isrc','tools/sm121dis/sm121dis.c','src/omega_sm121_disasm.c','src/cudapp_om_sm121_dis.c']
31subprocess.run(cli+['src/cudapp_om_words.c','-o',str(out/'pairs-om')],check=True)
32subprocess.run(cli+['-DCUDAPP_MIGRATION_PENDING_C_DISASM_WORDS=1','-o',str(out/'pairs-c')],check=True)
33fixture = bytes(range(64))
34(out/'words.bin').write_bytes(fixture)
35for option in ([],['--pairs']):
36 a = subprocess.run([str(out/'pairs-om'),*option,str(out/'words.bin')],capture_output=True)
37 c = subprocess.run([str(out/'pairs-c'),*option,str(out/'words.bin')],capture_output=True)
38 assert (a.returncode,a.stdout,a.stderr) == (c.returncode,c.stdout,c.stderr)
39print('CLI listing and --pairs byte assembly differential PASS')
40src = (root/'om/disasm/words.om').read_text()
41mutants = [
42 ('byte-shift','mul i 8','mul i 7'),
43 ('opcode','and v 4095 2381','and v 4095 2380'),
44 ('mask','and v 4095 2381','and v 4094 2381'),
45 ('end','ret add at 16','ret add at 15'),
46 ('retain','ret prev','ret 0'),
47]
48for name,old,new in mutants:
49 assert src.count(old) == 1
50 d = out/name
51 d.mkdir(exist_ok=True)
52 (d/'words.om').write_text(src.replace(old,new))
53 env = dict(os.environ,OMEGA_UNITS=str(d/'words.om'),OMEGA_UNITS_DEST=str(d))
54 subprocess.run(['sh','om/units.sh'],env=env,check=True,stdout=subprocess.DEVNULL)
55 build(d,[str(d/'cudapp_om_words.c')])
56 run(d,good=False)
57 print('KILLED '+name)
58subprocess.run(['gcov','-b','-c','-o',str(out),str(out/'check-dis_words_oracle.gcno')],check=True,cwd=out)
59print('DISASM WORDS DIFFERENTIAL RED LINK MUTANTS PASS')