#!/usr/bin/env python3 # focused host memory configuration and growth checks. import os import subprocess source = '''fn main() { int initial = syscall(9, 0, 0, 0); put_n(syscall(9, 5, initial, 0) == initial); put_c(32); put_n(syscall(9, 4, initial + 4096, 0) == -1); put_c(32); put_n(syscall(9, 5, initial + 8192, 0) == initial + 8192); put_c(32); put_n(syscall(9, 4, initial + 4096, 0) == initial + 4096); put_c(32); put_n(syscall(9, 5, initial - 1, 0) == -1); put_c(10); return 0; } ''' commands = [['build/bin/zy'], ['build/bin/zym'], ['node', 'src/js/tinyvm.js']] environment = dict(os.environ, TINYVM_MAX_MEMORY_WORDS='16777216') for command in commands: result = subprocess.run(command, input=source, text=True, capture_output=True, env=environment, timeout=15) assert result.returncode == 0 and result.stdout == '1 1 1 1 1\n', (command, result.stdout, result.stderr) invalid = subprocess.run(command, input=source, text=True, capture_output=True, env=dict(environment, TINYVM_MEMORY_WORDS='1'), timeout=15) assert invalid.returncode != 0 and invalid.stderr, (command, invalid.stdout) print('ok runtime memory limits, denied growth, successful growth, and invalid startup: ' + command[0])