From 5a04e2cca8255c2d4a1218d6ac0b38e67306206b Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 5 Oct 2014 22:27:12 +0100 Subject: [PATCH] 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 #861, and partially addresses issue #856. --- tests/micropython/native_check.py | 4 ++ tests/micropython/native_check.py.exp | 0 .../micropython/{native.py => native_misc.py} | 0 .../{native.py.exp => native_misc.py.exp} | 0 tests/micropython/{viper.py => viper_misc.py} | 0 .../{viper.py.exp => viper_misc.py.exp} | 0 tests/run-tests | 39 ++++++++++++------- 7 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 tests/micropython/native_check.py create mode 100644 tests/micropython/native_check.py.exp rename tests/micropython/{native.py => native_misc.py} (100%) rename tests/micropython/{native.py.exp => native_misc.py.exp} (100%) rename tests/micropython/{viper.py => viper_misc.py} (100%) rename tests/micropython/{viper.py.exp => viper_misc.py.exp} (100%) diff --git a/tests/micropython/native_check.py b/tests/micropython/native_check.py new file mode 100644 index 0000000000..3971d1355f --- /dev/null +++ b/tests/micropython/native_check.py @@ -0,0 +1,4 @@ +# this test for the availability of native emitter +@micropython.native +def f(): + pass diff --git a/tests/micropython/native_check.py.exp b/tests/micropython/native_check.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/micropython/native.py b/tests/micropython/native_misc.py similarity index 100% rename from tests/micropython/native.py rename to tests/micropython/native_misc.py diff --git a/tests/micropython/native.py.exp b/tests/micropython/native_misc.py.exp similarity index 100% rename from tests/micropython/native.py.exp rename to tests/micropython/native_misc.py.exp diff --git a/tests/micropython/viper.py b/tests/micropython/viper_misc.py similarity index 100% rename from tests/micropython/viper.py rename to tests/micropython/viper_misc.py diff --git a/tests/micropython/viper.py.exp b/tests/micropython/viper_misc.py.exp similarity index 100% rename from tests/micropython/viper.py.exp rename to tests/micropython/viper_misc.py.exp diff --git a/tests/run-tests b/tests/run-tests index cc1020e60a..ca2c376659 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -21,6 +21,24 @@ def rm_f(fname): if os.path.exists(fname): os.remove(fname) +def run_micropython(pyb, args, test_file): + if pyb is None: + # run on PC + try: + output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=' + args.emit, test_file]) + except subprocess.CalledProcessError: + output_mupy = b'CRASH' + else: + # run on pyboard + import pyboard + pyb.enter_raw_repl() + try: + output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') + except pyboard.PyboardError: + output_mupy = b'CRASH' + + return output_mupy + def run_tests(pyb, tests, args): test_count = 0 testcase_count = 0 @@ -30,6 +48,12 @@ def run_tests(pyb, tests, args): skip_tests = set() + # Check if micropython.native is supported, and skip such tests if it's not + native = run_micropython(pyb, args, 'micropython/native_check.py') + if native == b'CRASH': + skip_tests.update({'micropython/native_%s.py' % t for t in 'check misc'.split()}) + skip_tests.update({'micropython/viper_%s.py' % t for t in 'binop_arith binop_comp cond ptr16_store ptr8_store misc'.split()}) + # Some tests shouldn't be run under Travis CI if os.getenv('TRAVIS') == 'true': skip_tests.add('basics/memoryerror.py') @@ -44,7 +68,6 @@ def run_tests(pyb, tests, args): # Some tests use unsupported features on Windows if os.name == 'nt': - skip_tests.add('extmod\\ujson_loads.py') #works but -2e-3 is printed as -0.002000000000000001 except for mingw-w64 skip_tests.add('import\\import_file.py') #works but CPython prints forward slashes skip_tests.add('unix\\ffi_float.py') @@ -91,19 +114,7 @@ def run_tests(pyb, tests, args): continue # run Micro Python - if pyb is None: - # run on PC - try: - output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=' + args.emit, test_file]) - except subprocess.CalledProcessError: - output_mupy = b'CRASH' - else: - # run on pyboard - pyb.enter_raw_repl() - try: - output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') - except pyboard.PyboardError: - output_mupy = b'CRASH' + output_mupy = run_micropython(pyb, args, test_file) if output_mupy == b'SKIP\n': print("skip ", test_file)