aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/seed_growth_test.py
blob: b94445ecc09511756f360c65bc200e8dbe2250c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
# stage 0 accepts long source streams and grows a tiny initial image reservation.
import sys
import pathlib
import subprocess
import tempfile
sys.dont_write_bytecode = True  # importing imagekit must not leave __pycache__ in the tree
from imagekit import compiler, micro_image

root = pathlib.Path(__file__).resolve().parents[2]
(root / 'build').mkdir(exist_ok=True)
with tempfile.TemporaryDirectory(prefix='seed-growth-', dir=root / 'build') as directory:
    folder = pathlib.Path(directory)
    subprocess.run(['build/bin/genmap', '--preset', 'run', '--grow', '--genome', '600000', '--heap', '1048576', '-o', directory], check=True, capture_output=True)
    zc0 = folder / 'zc0'
    subprocess.run([compiler(), '-O1', '-w', '-fwrapv', '-DMAXW=16', 'src/tools/zc0.c', '-I' + directory, '-Isrc/core', '-o', str(zc0)], check=True)
    source = '/*' + 'x' * (5 << 20) + '*/\n'
    source += (folder / 'rt.zc').read_text() + (root / 'src/core/core.zc').read_text() + (root / 'src/runtime/run.zc').read_text()
    source += 'namespace; include rt; let data[550000]; fn main() { data[549999] = 7; rt.put_n(data[549999]); rt.put_c(32); rt.put_n(4611686018427387904); rt.put_c(10); return 0; }\n'
    image = subprocess.run([str(zc0)], input=source.encode(), capture_output=True, check=True, timeout=30).stdout
    binary = micro_image(folder / 'vm', image, folder / 'memmap.h', threads=False) if (folder / 'vm').mkdir() is None else None
    result = subprocess.run([str(binary)], text=True, capture_output=True, timeout=20)
    assert result.returncode == 0 and result.stdout == '7 4611686018427387904\n', (result.returncode, result.stdout, result.stderr)
print('ok   stage 0 reads beyond four megabytes and grows beyond its initial image capacity')