Skip to content

Commit 5a04e2c

Browse files
committed
tests: Add check for micropython.native and then skip relevant tests.
If micropython.native decorator doesn't compile, then we skill all native/viper tests. This patch also re-enables the ujson_loads test on NT. Addresses issue adafruit#861, and partially addresses issue adafruit#856.
1 parent 854c8c0 commit 5a04e2c

7 files changed

Lines changed: 29 additions & 14 deletions

File tree

tests/micropython/native_check.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# this test for the availability of native emitter
2+
@micropython.native
3+
def f():
4+
pass

tests/micropython/native_check.py.exp

Whitespace-only changes.

tests/run-tests

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ def rm_f(fname):
2121
if os.path.exists(fname):
2222
os.remove(fname)
2323

24+
def run_micropython(pyb, args, test_file):
25+
if pyb is None:
26+
# run on PC
27+
try:
28+
output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=' + args.emit, test_file])
29+
except subprocess.CalledProcessError:
30+
output_mupy = b'CRASH'
31+
else:
32+
# run on pyboard
33+
import pyboard
34+
pyb.enter_raw_repl()
35+
try:
36+
output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n')
37+
except pyboard.PyboardError:
38+
output_mupy = b'CRASH'
39+
40+
return output_mupy
41+
2442
def run_tests(pyb, tests, args):
2543
test_count = 0
2644
testcase_count = 0
@@ -30,6 +48,12 @@ def run_tests(pyb, tests, args):
3048

3149
skip_tests = set()
3250

51+
# Check if micropython.native is supported, and skip such tests if it's not
52+
native = run_micropython(pyb, args, 'micropython/native_check.py')
53+
if native == b'CRASH':
54+
skip_tests.update({'micropython/native_%s.py' % t for t in 'check misc'.split()})
55+
skip_tests.update({'micropython/viper_%s.py' % t for t in 'binop_arith binop_comp cond ptr16_store ptr8_store misc'.split()})
56+
3357
# Some tests shouldn't be run under Travis CI
3458
if os.getenv('TRAVIS') == 'true':
3559
skip_tests.add('basics/memoryerror.py')
@@ -44,7 +68,6 @@ def run_tests(pyb, tests, args):
4468

4569
# Some tests use unsupported features on Windows
4670
if os.name == 'nt':
47-
skip_tests.add('extmod\\ujson_loads.py') #works but -2e-3 is printed as -0.002000000000000001 except for mingw-w64
4871
skip_tests.add('import\\import_file.py') #works but CPython prints forward slashes
4972
skip_tests.add('unix\\ffi_float.py')
5073

@@ -91,19 +114,7 @@ def run_tests(pyb, tests, args):
91114
continue
92115

93116
# run Micro Python
94-
if pyb is None:
95-
# run on PC
96-
try:
97-
output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=' + args.emit, test_file])
98-
except subprocess.CalledProcessError:
99-
output_mupy = b'CRASH'
100-
else:
101-
# run on pyboard
102-
pyb.enter_raw_repl()
103-
try:
104-
output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n')
105-
except pyboard.PyboardError:
106-
output_mupy = b'CRASH'
117+
output_mupy = run_micropython(pyb, args, test_file)
107118

108119
if output_mupy == b'SKIP\n':
109120
print("skip ", test_file)

0 commit comments

Comments
 (0)