aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/enhancement_backends_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/drivers/enhancement_backends_test.py')
-rw-r--r--tests/drivers/enhancement_backends_test.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/drivers/enhancement_backends_test.py b/tests/drivers/enhancement_backends_test.py
new file mode 100644
index 0000000..b7d553b
--- /dev/null
+++ b/tests/drivers/enhancement_backends_test.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# recipes, vm lowering, fallback, and ignored optimizer regions agree across hosts.
+import pathlib
+import subprocess
+
+root = pathlib.Path(__file__).resolve().parents[2]
+source = (root / 'tests/programs/enhance.zc').read_text()
+# keep this focused check short while still exercising signed and unsigned arithmetic.
+source = source.replace('i < 5000', 'i < 200')
+source += '\n'
+reference = None
+for command in [['bin/zy'], ['bin/zym'], ['node', 'src/js/tinyvm.js']]:
+ result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=25)
+ assert result.returncode == 0 and result.stdout and 'zc:' not in result.stdout, (command, result.returncode, result.stdout, result.stderr)
+ if reference is None:
+ reference = result.stdout
+ else:
+ assert result.stdout == reference, (command, reference, result.stdout)
+ print('ok vm recipes, multiple outputs, arithmetic, and fallback: ' + command[0])
+source = '''o3 int increment(int value) { return value + 1; }
+fn main() { put_n(increment(6)); put_c(32); put_n(17 / 5); put_c(32); put_n(17 % 5); put_c(10); return 0; }
+'''
+for command in [['bin/zy'], ['bin/zym'], ['node', 'src/js/tinyvm.js']]:
+ result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=15)
+ assert result.returncode == 0 and result.stdout == '7 3 2\n', (command, result.stdout, result.stderr)
+ print('ok optimizer descriptors preserve portable division slots: ' + command[0])
+
+# slot zero can be replaced, and an unsupported replacement preserves it.
+# real install descriptors are exercised without calling a compiler-specific parser.
+source = '''let descriptor[7], names[2];
+fn main() {
+ names[0] = "a"; names[1] = "b";
+ descriptor[0] = 0; descriptor[1] = 0; descriptor[2] = 2; descriptor[3] = 1;
+ descriptor[4] = "a = add a b"; descriptor[6] = names;
+ int installed = install(descriptor) == 0, first = 17 / 5;
+ descriptor[4] = "a = unknown a b";
+ int rejected = install(descriptor) < 0, second = 17 / 5;
+ descriptor[4] = "a = sdiv a b"; install(descriptor);
+ put_n(installed); put_c(32); put_n(first); put_c(32); put_n(rejected); put_c(32); put_n(second); put_c(10); return 0;
+}
+'''
+for command in [['bin/zy'], ['bin/zym'], ['node', 'src/js/tinyvm.js']]:
+ result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=15)
+ assert result.returncode == 0 and result.stdout == '1 22 1 22\n', (command, result.stdout, result.stderr)
+ print('ok replacing a built-in slot and rejecting a bad recipe: ' + command[0])