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 / dagsim / jstr_check.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | import os |
| 3 | from pathlib import Path |
| 4 | import subprocess |
| 5 | |
| 6 | root = Path.cwd() |
| 7 | out = root / 'build/dagsim-jstr' |
| 8 | out.mkdir(parents=True, exist_ok=True) |
| 9 | cc = os.environ.get('CC', 'cc') |
| 10 | base = [cc, '-std=gnu11', '-O0', '--coverage', '-ffunction-sections', '-fdata-sections', '-Isrc', '-Itools/dagsim', str(root/'tests/dagsim/jstr_diff.c')] |
| 11 | def build(dest, binding, defs=()): |
| 12 | subprocess.run([*base, *defs, *binding, '-Wl,--gc-sections', '-lm', '-o', str(dest)], check=True) |
| 13 | def run(cmd, name, good=True): |
| 14 | p = subprocess.run([str(v) for v in cmd], capture_output=True) |
| 15 | (out/(name+'.log')).write_bytes(p.stdout+p.stderr) |
| 16 | assert (p.returncode == 0) == good, (name, p.returncode, p.stderr) |
| 17 | return p.stdout |
| 18 | binding = str(root/'src/cudapp_om_dag_jstr.c') |
| 19 | build(out/'om', [binding]) |
| 20 | build(out/'c', [binding], ['-DCUDAPP_MIGRATION_PENDING_C_DAGSIM_JSON_ESCAPE=1']) |
| 21 | print(run([out/'om'], 'diff').decode().strip()) |
| 22 | assert run([out/'om', '--stream'], 'stream-om') == run([out/'c', '--stream'], 'stream-c') |
| 23 | print('JSON STREAM DIFFERENTIAL PASS empty string and bytes 1..255') |
| 24 | run([out/'om', '--plant'], 'red', False) |
| 25 | missing = subprocess.run([*base, '-Wl,--gc-sections', '-lm', '-o', str(out/'missing')], capture_output=True) |
| 26 | (out/'link-negative.log').write_bytes(missing.stdout+missing.stderr) |
| 27 | assert missing.returncode and b'omega_dag_jstr' in missing.stderr |
| 28 | print('RED and strong-link missing-unit controls PASS') |
| 29 | text = (root/'om/tools/dag_jstr.om').read_text() |
| 30 | mutants = [('quote','eq c 34','eq c 35'), ('slash','eq c 92','eq c 93'), ('control','lt c 32','lt c 31'), ('hex','and uint c 15','and uint c 14'), ('length','ret 6','ret 5')] |
| 31 | for name, old, new in mutants: |
| 32 | assert text.count(old) == 1 |
| 33 | here = out/name |
| 34 | here.mkdir(exist_ok=True) |
| 35 | unit = here/'dag_jstr.om' |
| 36 | unit.write_text(text.replace(old,new)) |
| 37 | env = dict(os.environ, OMEGA_UNITS=str(unit), OMEGA_UNITS_DEST=str(here)) |
| 38 | p = subprocess.run(['sh','om/units.sh'], env=env, capture_output=True) |
| 39 | (here/'compile.log').write_bytes(p.stdout+p.stderr) |
| 40 | assert p.returncode == 0, p.stderr |
| 41 | build(here/'check', [str(here/'cudapp_om_dag_jstr.c')]) |
| 42 | run([here/'check'], name, False) |
| 43 | print('KILLED', name) |
| 44 | cov = subprocess.run(['gcov','-b','-c','-t',str(out/'c-jstr_diff.gcno')],capture_output=True) |
| 45 | (out/'oracle.gcov').write_bytes(cov.stdout) |
| 46 | (out/'coverage.log').write_bytes(cov.stderr) |
| 47 | assert cov.returncode == 0, cov.stderr |
| 48 | print('JSON DIFFERENTIAL RED LINK FIVE MUTANTS PASS') |