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
This commit is contained in:
Damien George 2016-09-20 12:19:35 +10:00
parent bb954d80a4
commit 3f5fe6269e
1 changed files with 24 additions and 5 deletions

View File

@ -18,6 +18,9 @@ else:
CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3')
MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../unix/micropython')
# mpy-cross is only needed if --via-mpy command-line arg is passed
MPYCROSS = os.getenv('MICROPY_MPYCROSS', '../mpy-cross/mpy-cross')
# Set PYTHONIOENCODING so that CPython will use utf-8 on systems which set another encoding in the locale
os.environ['PYTHONIOENCODING'] = 'utf-8'
os.environ['MICROPYPATH'] = ''
@ -105,15 +108,30 @@ def run_micropython(pyb, args, test_file):
return b'CRASH'
else:
# a standard test
try:
cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit]
if args.heapsize is not None:
cmdlist.extend(['-X', 'heapsize=' + args.heapsize])
# a standard test run on PC
# create system command
cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit]
if args.heapsize is not None:
cmdlist.extend(['-X', 'heapsize=' + args.heapsize])
# if running via .mpy, first compile the .py file
if args.via_mpy:
subprocess.check_output([MPYCROSS, '-mcache-lookup-bc', '-o', 'mpytest.mpy', test_file])
cmdlist.extend(['-m', 'mpytest'])
else:
cmdlist.append(test_file)
# run the actual test
try:
output_mupy = subprocess.check_output(cmdlist)
except subprocess.CalledProcessError:
output_mupy = b'CRASH'
# clean up if we had an intermediate .mpy file
if args.via_mpy:
rm_f('mpytest.mpy')
else:
# run on pyboard
import pyboard
@ -360,6 +378,7 @@ def main():
cmd_parser.add_argument('--write-exp', action='store_true', help='save .exp files to run tests w/o CPython')
cmd_parser.add_argument('--emit', default='bytecode', help='MicroPython emitter to use (bytecode or native)')
cmd_parser.add_argument('--heapsize', help='heapsize to use (use default if not specified)')
cmd_parser.add_argument('--via-mpy', action='store_true', help='compile .py files to .mpy first')
cmd_parser.add_argument('files', nargs='*', help='input test files')
args = cmd_parser.parse_args()