8000 tests/run-tests: Add --via-mpy option to run test from precompiled code. · sparkfun/circuitpython@3f5fe62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f5fe62

Browse files
committed
tests/run-tests: Add --via-mpy option to run test from precompiled code.
With mpy-cross built, tests can now be run by first compiling them to .mpy files, and then executing the .mpy file. Usage: ./run-tests --via-mpy
1 parent bb954d8 commit 3f5fe62

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tests/run-tests

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ else:
1818
CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3')
1919
MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../unix/micropython')
2020

21+
# mpy-cross is only needed if --via-mpy command-line arg is passed
22+
MPYCROSS = os.getenv('MICROPY_MPYCROSS', '../mpy-cross/mpy-cross')
23+
2124
# Set PYTHONIOENCODING so that CPython will use utf-8 on systems which set another encoding in the locale
2225
os.environ['PYTHONIOENCODING'] = 'utf-8'
2326
os.environ['MICROPYPATH'] = ''
@@ -105,15 +108,30 @@ def run_micropython(pyb, args, test_file):
105108
return b'CRASH'
106109

107110
else:
108-
# a standard test
109-
try:
110-
cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit]
111-
if args.heapsize is not None:
112-
cmdlist.extend(['-X', 'heapsize=' + args.heapsize])
111+
# a standard test run on PC
112+
113+
# create system command
114+
cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit]
115+
if args.heapsize is not None:
116+
cmdlist.extend(['-X', 'heapsize=' + args.heapsize])
117+
118+
# if running via .mpy, first compile the .py file
119+
if args.via_mpy:
120+
subprocess.check_output([MPYCROSS, '-mcache-lookup-bc', '-o', 'mpytest.mpy', test_file])
121+
cmdlist.extend(['-m', 'mpytest'])
122+
else:
113123
cmdlist.append(test_file)
124+
125+
# run the actual test
126+
try:
114127
output_mupy = subprocess.check_output(cmdlist)
115128
except subprocess.CalledProcessError:
116129
output_mupy = b'CRASH'
130+
131+
# clean up if we had an intermediate .mpy file
132+
if args.via_mpy:
133+
rm_f('mpytest.mpy')
134+
117135
else:
118136
# run on pyboard
119137
import pyboard
@@ -360,6 +378,7 @@ def main():
360378
cmd_parser.add_argument('--write-exp', action='store_true', help='save .exp files to run tests w/o CPython')
361379
cmd_parser.add_argument('--emit', default='bytecode', help='MicroPython emitter to use (bytecode or native)')
362380
cmd_parser.add_argument('--heapsize', help='heapsize to use (use default if not specified)')
381+
cmd_parser.add_argument('--via-mpy', action='store_true', help='compile .py files to .mpy first')
363382
cmd_parser.add_argument('files', nargs='*', help='input test files')
364383
args = cmd_parser.parse_args()
365384

0 commit comments

Comments
 (0)
0