2017-12-11 12:52:06 -05:00
|
|
|
#!/usr/bin/env python3
|
2014-05-05 11:49:52 -04:00
|
|
|
|
|
|
|
import os, sys
|
|
|
|
from glob import glob
|
|
|
|
from re import sub
|
|
|
|
|
|
|
|
def escape(s):
|
2017-12-11 12:52:06 -05:00
|
|
|
s = s.decode()
|
|
|
|
lookup = {
|
|
|
|
'\0': '\\0',
|
|
|
|
'\t': '\\t',
|
|
|
|
'\n': '\\n\"\n\"',
|
|
|
|
'\r': '\\r',
|
|
|
|
'\\': '\\\\',
|
|
|
|
'\"': '\\\"',
|
|
|
|
}
|
|
|
|
return "\"\"\n\"{}\"".format(''.join([lookup[x] if x in lookup else x for x in s]))
|
2014-05-05 11:49:52 -04:00
|
|
|
|
|
|
|
def chew_filename(t):
|
2017-12-11 12:52:06 -05:00
|
|
|
return { 'func': "test_{}_fn".format(sub(r'/|\.|-', '_', t)), 'desc': t.split('/')[1] }
|
2014-05-05 11:49:52 -04:00
|
|
|
|
2017-12-11 12:52:06 -05:00
|
|
|
def script_to_map(test_file):
|
|
|
|
r = {"name": chew_filename(test_file)["func"]}
|
|
|
|
with open(test_file, "rb") as f:
|
|
|
|
r["script"] = escape(f.read())
|
|
|
|
with open(test_file + ".exp", "rb") as f:
|
|
|
|
r["output"] = escape(f.read())
|
|
|
|
return r
|
2014-05-05 11:49:52 -04:00
|
|
|
|
|
|
|
test_function = (
|
|
|
|
"void {name}(void* data) {{\n"
|
2017-12-11 12:52:06 -05:00
|
|
|
" static const char pystr[] = {script};\n"
|
|
|
|
" static const char exp[] = {output};\n"
|
|
|
|
" upytest_set_expected_output(exp, sizeof(exp) - 1);\n"
|
|
|
|
" upytest_execute_test(pystr);\n"
|
2014-05-05 11:49:52 -04:00
|
|
|
"}}"
|
|
|
|
)
|
|
|
|
|
|
|
|
testcase_struct = (
|
|
|
|
"struct testcase_t {name}_tests[] = {{\n{body}\n END_OF_TESTCASES\n}};"
|
|
|
|
)
|
|
|
|
testcase_member = (
|
|
|
|
" {{ \"{desc}\", {func}, TT_ENABLED_, 0, 0 }},"
|
|
|
|
)
|
|
|
|
|
|
|
|
testgroup_struct = (
|
|
|
|
"struct testgroup_t groups[] = {{\n{body}\n END_OF_GROUPS\n}};"
|
|
|
|
)
|
|
|
|
testgroup_member = (
|
|
|
|
" {{ \"{name}/\", {name}_tests }},"
|
|
|
|
)
|
|
|
|
|
|
|
|
## XXX: may be we could have `--without <groups>` argument...
|
2015-01-08 19:03:21 -05:00
|
|
|
# currently these tests are selected because they pass on qemu-arm
|
2016-11-02 21:28:31 -04:00
|
|
|
test_dirs = ('basics', 'micropython', 'float', 'extmod', 'inlineasm') # 'import', 'io', 'misc')
|
2016-10-13 09:08:19 -04:00
|
|
|
exclude_tests = (
|
2017-12-11 12:59:11 -05:00
|
|
|
'extmod/ticks_diff.py',
|
|
|
|
'extmod/time_ms_us.py',
|
|
|
|
'extmod/uheapq_timeq.py',
|
|
|
|
'extmod/vfs_fat_ramdisk.py', 'extmod/vfs_fat_fileio.py',
|
|
|
|
'extmod/vfs_fat_fsusermount.py', 'extmod/vfs_fat_oldproto.py',
|
|
|
|
# requires double precision floating point to work
|
|
|
|
'float/float2int_doubleprec_intbig.py',
|
|
|
|
# inline asm tests
|
|
|
|
'inlineasm/asmfpaddsub.py', 'inlineasm/asmfpcmp.py', 'inlineasm/asmfpldrstr.py',
|
|
|
|
'inlineasm/asmfpmuldiv.py','inlineasm/asmfpsqrt.py',
|
2016-10-13 09:08:19 -04:00
|
|
|
)
|
2014-05-05 11:49:52 -04:00
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
for group in test_dirs:
|
2017-12-11 12:52:06 -05:00
|
|
|
tests = [test for test in glob('{}/*.py'.format(group)) if test not in exclude_tests]
|
|
|
|
output.extend([test_function.format(**script_to_map(test)) for test in tests])
|
|
|
|
testcase_members = [testcase_member.format(**chew_filename(test)) for test in tests]
|
|
|
|
output.append(testcase_struct.format(name=group, body='\n'.join(testcase_members)))
|
2014-05-05 11:49:52 -04:00
|
|
|
|
|
|
|
testgroup_members = [testgroup_member.format(name=group) for group in test_dirs]
|
|
|
|
|
|
|
|
output.append(testgroup_struct.format(body='\n'.join(testgroup_members)))
|
|
|
|
|
|
|
|
## XXX: may be we could have `--output <filename>` argument...
|
|
|
|
print('\n\n'.join(output))
|