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 / amd-exec / documented.py

53 lines · 2372 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Run the shell blocks in this directory's Markdown verbatim, from the repo root.
4Caller supplies CPU isolation, PATH, OMEGA_OMC, AMD_WEIGHTS and AMD_DOC_OUT.
5No safe-path flags or substitute interpreter are injected into documented commands.
6"""
7import hashlib
8import json
9import os
10import pathlib
11import re
12import shutil
13import subprocess
14import sys
15
16
17def main():
18 root = pathlib.Path(__file__).resolve().parents[2]
19 out = pathlib.Path(os.environ['AMD_DOC_OUT']).resolve()
20 out.mkdir(parents=True, exist_ok=False)
21 records = []
22 failed = False
23 not_run = False
24 for doc in sorted((root / 'tests/amd-exec').glob('*.md')):
25 text = doc.read_text()
26 blocks = re.findall(r'^```sh\n(.*?)^```', text, re.M | re.S)
27 assert blocks, f'no executable shell block: {doc}'
28 for index, command in enumerate(blocks):
29 assert not re.search(r'\bpython\S*\s+-(?:P|I)\b', command), 'documented safe-path workaround'
30 name = f'{doc.stem}-{index}'
31 log = out / (name + '.log')
32 interpreter = shutil.which(command.split()[0])
33 print(f'DOCUMENTED command={command!r} interpreter={interpreter}', flush=True)
34 with log.open('wb') as f:
35 p = subprocess.run(['sh', '-eu', '-c', command], cwd=root, stdout=f, stderr=subprocess.STDOUT)
36 data = log.read_bytes()
37 missing = b'ModuleNotFoundError:' in data or p.returncode == 127
38 status = 'PASS' if p.returncode == 0 else 'NOT_RUN' if missing else 'FAIL'
39 records.append({'document': str(doc.relative_to(root)), 'command': command,
40 'interpreter': interpreter, 'exit': p.returncode,
41 'status': status, 'log': str(log), 'sha256': hashlib.sha256(data).hexdigest()})
42 (out / 'commands.json').write_text(json.dumps(records, indent=2) + '\n')
43 print('DOCUMENTED ' + json.dumps(records[-1]), flush=True)
44 failed |= status == 'FAIL'
45 not_run |= status == 'NOT_RUN'
46 if p.returncode:
47 # Dependent bundle generation cannot produce evidence after a failed run.
48 break
49 return 1 if failed else 77 if not_run else 0
50
51
52if __name__ == '__main__':
53 sys.exit(main())