aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/tools_contract_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/drivers/tools_contract_test.py')
-rw-r--r--tests/drivers/tools_contract_test.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/tests/drivers/tools_contract_test.py b/tests/drivers/tools_contract_test.py
index df02b2b..6a98678 100644
--- a/tests/drivers/tools_contract_test.py
+++ b/tests/drivers/tools_contract_test.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
"""bounded accept/reject tests for standalone build tools and generated images."""
import argparse
-import re
import struct
import subprocess
import tempfile
@@ -17,32 +16,33 @@ def command(argv, data=None):
return r
if args.group == 'image':
- source = Path('src/core/genome.h').read_text()
- body = source.split('{', 1)[1].split('}', 1)[0]
- words = [int(x) for x in re.findall(r'-?\d+', body)]
+ image = Path('build/core/genome.bin').read_bytes()
+ words = list(struct.unpack('<%dq' % (len(image) // 8), image))
pack = lambda xs: b''.join(struct.pack('<q', x) for x in xs)
- good = command(['bin/mkgenome'], pack(words))
- assert good.returncode == 0 and f'#define GLEN {len(words)}'.encode() in good.stdout
- for data in [b'', b'x', pack(words[:6]), pack(words) + b'x']:
- r = command(['bin/mkgenome'], data)
- assert r.returncode != 0 and b'incomplete' in r.stderr
+ good = command(['build/bin/mkgenome'], image)
+ assert good.returncode == 0 and good.stdout == image
+ for data in [b'', b'x', pack(words[:6]), image + b'x']:
+ r = command(['build/bin/mkgenome'], data)
+ assert r.returncode != 0 and b'incomplete' in r.stderr and not r.stdout
for index in range(3):
changed = words[:]; changed[index] ^= 2
- r = command(['bin/mkgenome'], pack(changed))
- assert r.returncode != 0 and b'not a genome' in r.stderr
- print('ok mkgenome roundtrip, truncation, alignment and map-header mutation contracts')
+ r = command(['build/bin/mkgenome'], pack(changed))
+ assert r.returncode != 0 and b'not a genome' in r.stderr and not r.stdout
+ r = command(['build/bin/mkgenome'], b'zc: line 1: something is wrong\nzc: 1 error\n')
+ assert r.returncode != 0 and b'something is wrong' in r.stderr and not r.stdout
+ print('ok mkgenome roundtrip, truncation, alignment, map-header mutation and diagnostic contracts')
elif args.group == 'map':
for preset in ['default', 'small', 'run', 'lsp', 'fixed']:
with tempfile.TemporaryDirectory(prefix='tinyvm preset ') as directory:
- r = command(['bin/genmap', '--preset', preset, '-o', directory])
+ r = command(['build/bin/genmap', '--preset', preset, '-o', directory])
assert r.returncode == 0, (preset, r.stderr)
assert (Path(directory) / 'memmap.h').is_file()
- assert command(['bin/genmap', '--preset', 'default', '--check']).returncode == 0
+ assert command(['build/bin/genmap', '--preset', 'default', '--check']).returncode == 0
for options in [['--words', '-1'], ['--heap', '0'], ['--data', '0'], ['--symbols', '-1'], ['--total', '999999999999999999999'], ['--preset', 'imaginary']]:
- r = command(['bin/genmap', *options, '--check'])
+ r = command(['build/bin/genmap', *options, '--check'])
assert r.returncode != 0, options
with tempfile.TemporaryDirectory(prefix='tinyvm map ') as directory:
- r = command(['bin/genmap', '--preset', 'small', '--locals', '32', '--symbols', '64', '-o', directory])
+ r = command(['build/bin/genmap', '--preset', 'small', '--locals', '32', '--symbols', '64', '-o', directory])
assert r.returncode == 0, r.stderr
for name in ['memmap.h', 'rt.zc', 'compiler.zc', 'map.txt']:
assert (Path(directory) / name).is_file(), name
@@ -50,7 +50,7 @@ elif args.group == 'map':
else:
r = command(['bash', '-n', 'tinyvm.sh'])
assert r.returncode == 0, r.stderr
- for script in ['src/tools/automap.sh', 'src/tools/mklsp.sh', 'src/tools/mklspwasm.sh', 'src/tools/mkvsix.sh', 'src/tools/embed.sh']:
+ for script in ['src/tools/automap.sh', 'src/tools/mklsp.sh', 'src/tools/mklspwasm.sh', 'src/tools/mkvsix.sh', 'src/tools/findcc.sh', 'src/tools/bootstrap-check.sh']:
assert command(['bash', '-n', script]).returncode == 0
assert command(['bash', 'tinyvm.sh', 'imaginary-command']).returncode != 0
assert Path('tinyvm.bat').is_file()