1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/env python3
# generated layouts expose initial reservations and reject arithmetic overflow.
import pathlib
import subprocess
import tempfile
root = pathlib.Path(__file__).resolve().parents[2]
tool = root / 'bin/genmap'
result = subprocess.run([tool, '--help'], capture_output=True, text=True)
assert result.returncode == 0 and '--generated-text' in result.stderr
invalid = [
['--symbols', '2147483647'], ['--code', '2147483647'],
['--frame', '2147483647'], ['--return', '2147483647'],
['--asm-labels', '2147483647'], ['--enum-members', '2147483647'],
['--regions', '2147483647'], ['--heap', '7'], ['--hash', '3'],
]
for options in invalid:
result = subprocess.run([tool, '--preset', 'default', *options], capture_output=True, text=True)
assert result.returncode != 0 and result.stderr, options
with tempfile.TemporaryDirectory(dir=root / 'build') as directory:
options = ['--asm-labels', '4', '--asm-refs', '8', '--exit', '32', '--enum-members', '8', '--tagged-enums', '2', '--methods', '2', '--generated-text', '64', '--facts', '2', '--paths', '2', '--regions', '2']
subprocess.run([tool, '--preset', 'default', *options, '-o', directory], check=True, capture_output=True)
source = (pathlib.Path(directory) / 'compiler.zc').read_text()
for name, value in [('ASM_LABELS', '4'), ('ASM_REFS', '8'), ('EXIT_WORDS', '20'), ('ENUM_MEMBERS', '8'), ('TAGGED_ENUMS', '2'), ('STRUCT_METHODS', '2'), ('GENERATED_WORDS', '40'), ('RANGE_FACTS', '2'), ('JOIN_PATHS', '2'), ('O3_REGIONS', '2')]:
assert f'const {name} = 0x{value};' in source, name
print('ok parser layout controls and invalid configuration checks')
|