aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/enhancement_backends_test.py
blob: ddfee1bb45b33706546047369ecf822335023399 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 [['build/bin/zy'], ['build/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 [['build/bin/zy'], ['build/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 [['build/bin/zy'], ['build/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])