aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/seed_growth_test.py
blob: 426c97015f9b4243aa2734554579979e2d322e3e (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
25
#!/usr/bin/env python3
# stage 0 accepts long source streams and grows a tiny initial image reservation.
import pathlib
import subprocess
import tempfile

root = pathlib.Path(__file__).resolve().parents[2]
with tempfile.TemporaryDirectory(prefix='seed-growth-', dir=root / 'build') as directory:
    folder = pathlib.Path(directory)
    subprocess.run(['bin/genmap', '--preset', 'run', '--grow', '--genome', '600000', '--heap', '1048576', '-o', directory], check=True, capture_output=True)
    compiler = folder / 'zc0'
    subprocess.run(['cc', '-O1', '-w', '-fwrapv', '-DMAXW=16', 'src/tools/zc0.c', '-I' + directory, '-Isrc/core', '-o', str(compiler)], check=True)
    source = '/*' + 'x' * (5 << 20) + '*/\n'
    source += (folder / 'rt.zc').read_text() + (root / 'src/runtime/run.zc').read_text()
    source += 'let data[550000]; fn main() { data[549999] = 7; put_n(data[549999]); put_c(32); put_n(4611686018427387904); put_c(10); return 0; }\n'
    with (folder / 'genome.h').open('w') as output:
        subprocess.run([str(compiler)], input=source, text=True, stdout=output, check=True, timeout=30)
    binary = folder / 'vm'
    import shutil
    for path in ['src/micro/micro.c', 'src/micro/micro_port.h', 'src/micro/port_linux.c', 'src/core/fops.h', 'src/core/bops.h', 'src/core/stack.h']:
        shutil.copy(root / path, folder)
    subprocess.run(['cc', '-O2', '-w', '-fwrapv', str(folder / 'micro.c'), str(folder / 'port_linux.c'), '-I' + directory, '-o', str(binary)], check=True)
    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')