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 / amd-exec / stdlib-shadow.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Reject stdlib-named sibling modules before instrument imports.""" |
| 4 | import pathlib |
| 5 | import subprocess |
| 6 | import sys |
| 7 | import tempfile |
| 8 | |
| 9 | |
| 10 | def check(directory): |
| 11 | found = sorted(p.stem for p in pathlib.Path(directory).glob('*.py') |
| 12 | if p.stem in sys.stdlib_module_names) |
| 13 | if found: |
| 14 | print(f'STDLIB-SHADOW FAIL directory={directory} names={found}') |
| 15 | return 1 |
| 16 | print(f'STDLIB-SHADOW PASS directory={directory}') |
| 17 | return 0 |
| 18 | |
| 19 | |
| 20 | if __name__ == '__main__': |
| 21 | if sys.argv[1] == 'test': |
| 22 | with tempfile.TemporaryDirectory(prefix='stdlib-shadow.') as tmp: |
| 23 | path = pathlib.Path(tmp) / 'token.py' |
| 24 | path.write_text('raise RuntimeError("shadow must never be imported")\n') |
| 25 | cmd = [sys.executable, '-I', __file__, tmp] |
| 26 | p = subprocess.run(cmd, capture_output=True, text=True) |
| 27 | print(f'command={cmd!r} exit={p.returncode}\n{p.stdout}{p.stderr}') |
| 28 | assert p.returncode == 1 and "names=['token']" in p.stdout, 'INVALID or missed shadow control' |
| 29 | print('CONTROL restored-token.py CAUGHT exit=1 before import') |
| 30 | sys.exit(check(sys.argv[2])) |
| 31 | sys.exit(check(sys.argv[1])) |