Skip to content

Commit 43141dd

Browse files
committed
tools/tinytest-codegen: Take --target= option for test set selection.
Gets passed to run-tests --list-tests to get actual list of tests to use. If --target= is not given, legacy set hardcoded in tinytest-codegen itself is used. Also, get rid of tinytest test groups - they aren't really used for anything, and only complicate processing. Besides, one of the next step is to limit number of tests per a generated file to control the binary size, which also will require "flat" list of tests.
1 parent 334934e commit 43141dd

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tools/tinytest-codegen.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os, sys
44
from glob import glob
55
from re import sub
6+
import argparse
7+
68

79
def escape(s):
810
s = s.decode()
@@ -17,7 +19,7 @@ def escape(s):
1719
return "\"\"\n\"{}\"".format(''.join([lookup[x] if x in lookup else x for x in s]))
1820

1921
def chew_filename(t):
20-
return { 'func': "test_{}_fn".format(sub(r'/|\.|-', '_', t)), 'desc': t.split('/')[1] }
22+
return { 'func': "test_{}_fn".format(sub(r'/|\.|-', '_', t)), 'desc': t }
2123

2224
def script_to_map(test_file):
2325
r = {"name": chew_filename(test_file)["func"]}
@@ -47,7 +49,7 @@ def script_to_map(test_file):
4749
"struct testgroup_t groups[] = {{\n{body}\n END_OF_GROUPS\n}};"
4850
)
4951
testgroup_member = (
50-
" {{ \"{name}/\", {name}_tests }},"
52+
" {{ \"{name}\", {name}_tests }},"
5153
)
5254

5355
## XXX: may be we could have `--without <groups>` argument...
@@ -82,14 +84,24 @@ def script_to_map(test_file):
8284
)
8385

8486
output = []
87+
tests = []
88+
89+
argparser = argparse.ArgumentParser(description='Convert native MicroPython tests to tinytest/upytesthelper C code')
90+
argparser.add_argument('--target', help='the target platform')
91+
args = argparser.parse_args()
92+
93+
if not args.target:
94+
for group in test_dirs:
95+
tests += [test for test in glob('{}/*.py'.format(group)) if test not in exclude_tests]
96+
else:
97+
for l in os.popen("./run-tests --list-tests --target=%s" % args.target, "r"):
98+
tests.append(l.rstrip())
8599

86-
for group in test_dirs:
87-
tests = [test for test in glob('{}/*.py'.format(group)) if test not in exclude_tests]
88-
output.extend([test_function.format(**script_to_map(test)) for test in tests])
89-
testcase_members = [testcase_member.format(**chew_filename(test)) for test in tests]
90-
output.append(testcase_struct.format(name=group, body='\n'.join(testcase_members)))
100+
output.extend([test_function.format(**script_to_map(test)) for test in tests])
101+
testcase_members = [testcase_member.format(**chew_filename(test)) for test in tests]
102+
output.append(testcase_struct.format(name="", body='\n'.join(testcase_members)))
91103

92-
testgroup_members = [testgroup_member.format(name=group) for group in test_dirs]
104+
testgroup_members = [testgroup_member.format(name=group) for group in [""]]
93105

94106
output.append(testgroup_struct.format(body='\n'.join(testgroup_members)))
95107

0 commit comments

Comments
 (0)