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 / dagsim / jstr_check.py

48 lines · 2529 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2import os
3from pathlib import Path
4import subprocess
5
6root = Path.cwd()
7out = root / 'build/dagsim-jstr'
8out.mkdir(parents=True, exist_ok=True)
9cc = os.environ.get('CC', 'cc')
10base = [cc, '-std=gnu11', '-O0', '--coverage', '-ffunction-sections', '-fdata-sections', '-Isrc', '-Itools/dagsim', str(root/'tests/dagsim/jstr_diff.c')]
11def build(dest, binding, defs=()):
12 subprocess.run([*base, *defs, *binding, '-Wl,--gc-sections', '-lm', '-o', str(dest)], check=True)
13def 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
18binding = str(root/'src/cudapp_om_dag_jstr.c')
19build(out/'om', [binding])
20build(out/'c', [binding], ['-DCUDAPP_MIGRATION_PENDING_C_DAGSIM_JSON_ESCAPE=1'])
21print(run([out/'om'], 'diff').decode().strip())
22assert run([out/'om', '--stream'], 'stream-om') == run([out/'c', '--stream'], 'stream-c')
23print('JSON STREAM DIFFERENTIAL PASS empty string and bytes 1..255')
24run([out/'om', '--plant'], 'red', False)
25missing = 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)
27assert missing.returncode and b'omega_dag_jstr' in missing.stderr
28print('RED and strong-link missing-unit controls PASS')
29text = (root/'om/tools/dag_jstr.om').read_text()
30mutants = [('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')]
31for 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)
44cov = 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)
47assert cov.returncode == 0, cov.stderr
48print('JSON DIFFERENTIAL RED LINK FIVE MUTANTS PASS')