aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/frame_growth_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/drivers/frame_growth_test.py')
-rw-r--r--tests/drivers/frame_growth_test.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/drivers/frame_growth_test.py b/tests/drivers/frame_growth_test.py
new file mode 100644
index 0000000..74156e3
--- /dev/null
+++ b/tests/drivers/frame_growth_test.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+# growing frames keep pointers into older segments alive through collection.
+import subprocess
+import sys
+
+command = sys.argv[1:]
+source = '''unchecked int descend(int depth, int* root) {
+ [2000]int padding;
+ padding[0] = depth;
+ if (depth == 0) { gc(); return *root; }
+ return descend(depth - 1, root) + padding[0];
+}
+unchecked int oversized(int* root) {
+ [300000]int values;
+ values[0] = *root; values[299999] = 9;
+ gc(); return values[0] + values[299999];
+}
+unchecked fn main() {
+ int value = 7;
+ put_n(descend(300, &value)); put_c(32);
+ put_n(oversized(&value)); put_c(32);
+ gc(); put_n(frame_node == 0); put_c(10);
+ return 0;
+}
+'''
+result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=40)
+assert result.returncode == 0 and result.stdout == '45157 16 1\n', (command, result.returncode, result.stdout, result.stderr)
+print('ok deep and oversized frames preserve borrowed locals through collection: ' + command[0])
+optimized = source.replace('unchecked int descend', 'unchecked o3 int descend').replace('unchecked int oversized', 'unchecked o3 int oversized')
+result = subprocess.run(command, input=optimized, text=True, capture_output=True, timeout=40)
+assert result.returncode == 0 and result.stdout == '45157 16 1\n', (command, result.returncode, result.stdout, result.stderr)
+print('ok optimized recursive calls wait for the matching return depth: ' + command[0])