aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/stack_growth_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/drivers/stack_growth_test.py')
-rw-r--r--tests/drivers/stack_growth_test.py56
1 files changed, 32 insertions, 24 deletions
diff --git a/tests/drivers/stack_growth_test.py b/tests/drivers/stack_growth_test.py
index d4abe81..3c90305 100644
--- a/tests/drivers/stack_growth_test.py
+++ b/tests/drivers/stack_growth_test.py
@@ -4,6 +4,8 @@ import subprocess
import sys
import tempfile
from pathlib import Path
+sys.dont_write_bytecode = True # importing imagekit must not leave __pycache__ in the tree
+from imagekit import compiler
command = sys.argv[1:]
@@ -12,47 +14,53 @@ def run(source, expected, compile_image=False):
if compile_image and command[0] == 'node':
# compile the execution stress cases once with stage 0, so a javascript
# compiler's speed does not determine the execution-test timeout.
+ Path('build').mkdir(exist_ok=True)
with tempfile.TemporaryDirectory(prefix='stack-image-', dir='build') as directory:
target = Path(directory)
- subprocess.run(['bin/genmap', '--preset', 'run', '--grow', '--heap', '1048576', '--genome', '131072', '--frame', '4096', '--return', '256', '--data', '3072', '-o', directory], check=True, capture_output=True)
- compiler = target / 'zc0'
- subprocess.run(['cc', '-O1', '-w', '-fwrapv', 'src/tools/zc0.c', '-I' + directory, '-Isrc/core', '-o', str(compiler)], check=True, capture_output=True)
- full_source = (target / 'rt.zc').read_text() + Path('src/runtime/run.zc').read_text() + source
- image = subprocess.run([str(compiler)], input=full_source, text=True, capture_output=True, check=True)
- header = target / 'genome.h'
- header.write_text(image.stdout)
- result = subprocess.run(['node', 'tests/drivers/image_run.js', str(header), str(target / 'memmap.h')], text=True, capture_output=True, timeout=45)
+ subprocess.run(['build/bin/genmap', '--preset', 'run', '--grow', '--heap', '1048576', '--genome', '131072', '--frame', '4096', '--return', '256', '--data', '3072', '-o', directory], check=True, capture_output=True)
+ zc0 = target / 'zc0'
+ subprocess.run([compiler(), '-O1', '-w', '-fwrapv', 'src/tools/zc0.c', '-I' + directory, '-Isrc/core', '-o', str(zc0)], check=True, capture_output=True)
+ full_source = (target / 'rt.zc').read_text() + Path('src/core/core.zc').read_text() + Path('src/runtime/run.zc').read_text() + source
+ image = subprocess.run([str(zc0)], input=full_source.encode(), capture_output=True, check=True)
+ (target / 'genome.bin').write_bytes(image.stdout)
+ result = subprocess.run(['node', 'tests/drivers/image_run.js', str(target / 'genome.bin'), str(target / 'memmap.h')], text=True, capture_output=True, timeout=45)
else:
result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=45)
assert result.returncode == 0 and result.stdout == expected, (command, result.returncode, result.stdout, result.stderr)
-run('''fn main() {
- int old_data = data_top - data_low, old_return = return_top - return_low;
- put_n(reserve_data(old_data + 1) > old_data); put_c(32);
- put_n(reserve_returns(old_return + 1) > old_return); put_c(32);
- gc(); put_n(data_node != 0 && return_node != 0); put_c(10); return 0;
+run('''namespace;
+include rt;
+fn main() {
+ int old_data = rt.data_top - rt.data_low, old_return = rt.return_top - rt.return_low;
+ rt.put_n(rt.reserve_data(old_data + 1) > old_data); rt.put_c(32);
+ rt.put_n(rt.reserve_returns(old_return + 1) > old_return); rt.put_c(32);
+ rt.gc(); rt.put_n(rt.data_node != 0 && rt.return_node != 0); rt.put_c(10); return 0;
}
''', '1 1 1\n')
-run('''fn main() {
- put_n(reserve_data(-1) == -1); put_c(32); put_n(reserve_returns(-1) == -1); put_c(32);
- put_n(syscall(9, 6, 0, 0) == -1); put_c(32);
- int current = syscall(9, 0, 0, 0); syscall(9, 5, current, 0);
- put_n(reserve_data(0x10000000) == -1); put_c(32); gc(); put_n(7); put_c(10); return 0;
+run('''namespace;
+include rt;
+fn main() {
+ rt.put_n(rt.reserve_data(-1) == -1); rt.put_c(32); rt.put_n(rt.reserve_returns(-1) == -1); rt.put_c(32);
+ rt.put_n(rt.syscall(9, 6, 0, 0) == -1); rt.put_c(32);
+ int current = rt.syscall(9, 0, 0, 0); rt.syscall(9, 5, current, 0);
+ rt.put_n(rt.reserve_data(0x10000000) == -1); rt.put_c(32); rt.gc(); rt.put_n(7); rt.put_c(10); return 0;
}
''', '1 1 1 1 7\n')
count = 40000
-source = 'fn main() { int total = asm { ' + ' '.join(str(i + 1) for i in range(count))
-source += ' + ' * (count - 1) + ' }; gc(); put_n(total); put_c(32); '
-source += 'put_n(data_node != 0); put_c(10); return 0; }\n'
+source = 'namespace; include rt; fn main() { int total = asm { ' + ' '.join(str(i + 1) for i in range(count))
+source += ' + ' * (count - 1) + ' }; rt.gc(); rt.put_n(total); rt.put_c(32); '
+source += 'rt.put_n(rt.data_node != 0); rt.put_c(10); return 0; }\n'
run(source, '800020000 1\n', compile_image=True)
-run('''unchecked int descend(int n) {
- if (!n) { gc(); return 7; }
+run('''namespace;
+include rt;
+unchecked int descend(int n) {
+ if (!n) { rt.gc(); return 7; }
return descend(n - 1) + 1;
}
-fn main() { put_n(descend(70000)); put_c(32); put_n(return_node != 0); put_c(10); return 0; }
+fn main() { rt.put_n(descend(70000)); rt.put_c(32); rt.put_n(rt.return_node != 0); rt.put_c(10); return 0; }
''', '70007 1\n', compile_image=True)
print('ok explicit reservation, 40000 operands, and 70000 return addresses: ' + command[0])