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 / pathcopy_mutants.py

48 lines · 2066 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2"""Mutate pathcopy.om, regenerate the freestanding binding, and require the differential to die."""
3import os
4from pathlib import Path
5import shlex
6import subprocess
7import sys
8
9root = Path(__file__).resolve().parent.parent
10out = Path(sys.argv[1]).resolve()
11out.mkdir(parents=True, exist_ok=True)
12source = (root / 'om/components/pathcopy.om').read_text()
13mutants = [
14 ('alphabet', 'ge value 97 le value 122', 'ge value 98 le value 122'),
15 ('punctuation', 'eq value 58 eq value 126', 'eq value 59 eq value 126'),
16 ('slash-state', 'if eq state 2\nret 4', 'if eq state 1\nret 4'),
17 ('invalid-byte', 'ret 256\nend\nfn pathstep', 'ret value\nend\nfn pathstep'),
18 ('dotdot', 'eq count 0 eq state 2', 'eq count 0 eq state 1'),
19]
20for name, old, new in mutants:
21 if source.count(old) != 1:
22 raise SystemExit(f'FAIL {name}: mutation site not unique')
23 directory = out / name
24 directory.mkdir(exist_ok=True)
25 unit = directory / 'pathcopy.om'
26 unit.write_text(source.replace(old, new))
27 generated = directory / 'cudapp_freest_pathcopy.c'
28 env = dict(os.environ)
29 env['PATHCOPY_UNIT'] = str(unit)
30 env['PATHCOPY_DEST'] = str(generated)
31 env['PATHCOPY_ARCH'] = 'a64'
32 subprocess.run(['sh', str(root / 'om/native-freest.sh')], env=env, cwd=root, check=True)
33 binary = directory / 'diff'
34 subprocess.run(
35 shlex.split(os.environ.get('CC', 'cc')) + [
36 '-std=gnu11', '-O2', '-Wall', '-Wextra', '-Werror', '-Isrc',
37 'tests/leftovers_test.c', 'src/cudapp_freest_leftovers.c', str(generated),
38 '-o', str(binary),
39 ],
40 cwd=root,
41 check=True,
42 )
43 with (directory / 'run.log').open('w') as stream:
44 result = subprocess.run([str(binary)], stdout=stream, stderr=subprocess.STDOUT)
45 if result.returncode != 1:
46 raise SystemExit(f'FAIL {name}: expected assertion exit 1, got {result.returncode}')
47 print(f'KILLED {name}', flush=True)
48print(f'PATHCOPY MUTANTS PASS killed={len(mutants)}')