|
18 | 18 | CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3')
|
19 | 19 | MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../unix/micropython')
|
20 | 20 |
|
| 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 | + |
21 | 24 | # Set PYTHONIOENCODING so that CPython will use utf-8 on systems which set another encoding in the locale
|
22 | 25 | os.environ['PYTHONIOENCODING'] = 'utf-8'
|
23 | 26 | os.environ['MICROPYPATH'] = ''
|
@@ -105,15 +108,30 @@ def run_micropython(pyb, args, test_file):
|
105 | 108 | return b'CRASH'
|
106 | 109 |
|
107 | 110 | 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: |
113 | 123 | cmdlist.append(test_file)
|
| 124 | + |
| 125 | + # run the actual test |
| 126 | + try: |
114 | 127 | output_mupy = subprocess.check_output(cmdlist)
|
115 | 128 | except subprocess.CalledProcessError:
|
116 | 129 | 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 | + |
117 | 135 | else:
|
118 | 136 | # run on pyboard
|
119 | 137 | import pyboard
|
@@ -360,6 +378,7 @@ def main():
|
360 | 378 | cmd_parser.add_argument('--write-exp', action='store_true', help='save .exp files to run tests w/o CPython')
|
361 | 379 | cmd_parser.add_argument('--emit', default='bytecode', help='MicroPython emitter to use (bytecode or native)')
|
362 | 380 | 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') |
363 | 382 | cmd_parser.add_argument('files', nargs='*', help='input test files')
|
364 | 383 | args = cmd_parser.parse_args()
|
365 | 384 |
|
|
0 commit comments