diff options
| author | Damien George | 2016-09-20 12:19:35 +1000 |
|---|---|---|
| committer | Damien George | 2016-09-20 12:19:35 +1000 |
| commit | 3f5fe6269eb8ec003c0dee876df0d8cbe3725205 (patch) | |
| tree | eae4e9b70da59f8b6d58995d71a8c879a5d89d7c | |
| parent | bb954d80a4bd467fc321df90cea2b248a90d1570 (diff) | |
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
| -rwxr-xr-x | tests/run-tests | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/tests/run-tests b/tests/run-tests index e69e53723..cb920c094 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -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() |
