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 / tests / dis_words_run.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | """Host-only word-policy differential, link refusal and source mutants.""" |
| 3 | import os |
| 4 | from pathlib import Path |
| 5 | import subprocess |
| 6 | import sys |
| 7 | root = Path(__file__).resolve().parents[1] |
| 8 | os.chdir(root) |
| 9 | out = Path(sys.argv[1] if len(sys.argv) > 1 else 'build/dis-words').resolve() |
| 10 | out.mkdir(parents=True, exist_ok=True) |
| 11 | base = ['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'] |
| 13 | def build(where, binding): |
| 14 | where.mkdir(parents=True, exist_ok=True) |
| 15 | subprocess.run(base + binding + ['-o',str(where/'check')],check=True) |
| 16 | def 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() |
| 22 | build(out,['src/cudapp_om_words.c']) |
| 23 | print(run(out)) |
| 24 | run(out,['--plant'],False) |
| 25 | print('RED planted difference rejected') |
| 26 | p = subprocess.run(base+['-o',str(out/'missing')],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True) |
| 27 | (out/'link-negative.log').write_text(p.stdout) |
| 28 | assert p.returncode != 0 and 'omega_dis_words' in p.stdout |
| 29 | print('STRONG LINK missing Omega refused') |
| 30 | cli = ['gcc','-O2','-Isrc','tools/sm121dis/sm121dis.c','src/omega_sm121_disasm.c','src/cudapp_om_sm121_dis.c'] |
| 31 | subprocess.run(cli+['src/cudapp_om_words.c','-o',str(out/'pairs-om')],check=True) |
| 32 | subprocess.run(cli+['-DCUDAPP_MIGRATION_PENDING_C_DISASM_WORDS=1','-o',str(out/'pairs-c')],check=True) |
| 33 | fixture = bytes(range(64)) |
| 34 | (out/'words.bin').write_bytes(fixture) |
| 35 | for 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) |
| 39 | print('CLI listing and --pairs byte assembly differential PASS') |
| 40 | src = (root/'om/disasm/words.om').read_text() |
| 41 | mutants = [ |
| 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 | ] |
| 48 | for 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) |
| 58 | subprocess.run(['gcov','-b','-c','-o',str(out),str(out/'check-dis_words_oracle.gcno')],check=True,cwd=out) |
| 59 | print('DISASM WORDS DIFFERENTIAL RED LINK MUTANTS PASS') |