Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/runtime/host_policy_mutants.py # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / runtime / host_policy_mutants.py` 56 lines · 2940 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Compile source mutants, never mutate checked-in generated files.""" 4 import os 5 from pathlib import Path 6 import shlex 7 import subprocess 8 import tempfile 9 10 root = Path(__file__).resolve().parents[2] 11 bridge = Path(os.environ['OMEGA_BRIDGE']) 12 env = dict(os.environ, OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC']) 13 cc = shlex.split(os.environ.get('CC', 'cc')) 14 for name, old, new in ( 15 ('api_policy', 'gt a 8192', 'gt a 8193'), 16 ('artifact_policy', 'art_word q0 12 0', 'art_word q0 13 0'), 17 ('artifact_parse', 'ge get s 0 9', 'ge get s 0 10'), 18 ): 19 source = (root / 'om/components' / (name + '.om')).read_text() 20 assert source.count(old) == 1 21 with tempfile.TemporaryDirectory(prefix='cudapp-host-policy-') as tmp: 22 tmp = Path(tmp) 23 om = tmp / (name + '.om') 24 om.write_text(source.replace(old, new)) 25 generated = tmp / (name + '.c') 26 with generated.open('w') as out: 27 subprocess.run(['sh', str(bridge / 'tools/bridge-seeded'), 'c', str(om)], env=env, stdout=out, check=True) 28 other = 'artifact_policy' if name == 'api_policy' else 'api_policy' 29 test = 'artifact_text_unit.c' if name == 'artifact_parse' else 'host_policy_unit.c' 30 extra = [] if name == 'artifact_parse' else [str(root / 'src' / ('cudapp_om_' + other + '.c'))] 31 exe = tmp / 'mutant' 32 subprocess.run(cc + ['-O2', '-Wall', '-Wextra', '-Werror', '-I' + str(root / 'src'), 33 str(root / 'tests/runtime' / test), str(generated)] + extra + ['-o', str(exe)], check=True) 34 result = subprocess.run([str(exe)], capture_output=True, text=True) 35 marker = 'ARTIFACT TEXT' if name == 'artifact_parse' else 'HOST POLICY' 36 assert result.returncode != 0 and marker + ' differential FAIL' in result.stderr, result 37 print('HOST POLICY mutant caught:', name) 38 print('HOST POLICY mutants PASS') 39 40 source = (root / 'om/components/cm_sort.om').read_text() 41 old = 'if not cms_less get a j get a sub j 1' 42 assert source.count(old) == 1 43 with tempfile.TemporaryDirectory(prefix='cudapp-cm-sort-') as tmp: 44 tmp = Path(tmp) 45 om = tmp / 'cm_sort.om' 46 om.write_text(source.replace(old, 'if cms_less get a j get a sub j 1')) 47 generated = tmp / 'cm_sort.c' 48 with generated.open('w') as out: 49 subprocess.run(['sh', str(bridge / 'tools/bridge-seeded'), 'c', str(om)], env=env, stdout=out, check=True) 50 exe = tmp / 'mutant' 51 subprocess.run(cc + ['-O2', '-Wall', '-Wextra', '-Werror', '-I' + str(root / 'src'), 52 str(root / 'tests/runtime/cm_sort_unit.c'), str(generated), '-o', str(exe)], check=True) 53 result = subprocess.run([str(exe)], capture_output=True, text=True) 54 assert result.returncode != 0 and 'CM SORT differential FAIL' in result.stderr, result 55 print('CM SORT mutant caught: reversed insertion order') 56 print('CM SORT mutants PASS')