Skip to content

Commit f493075

Browse files
committed
tests/run-tests.py: Automatically include float tests when possible.
This simplifies the code by removing the explicit addition of the "float/" test directory for certain targets. It also means the tests won't be added incorrectly, eg on a unix build without float. Signed-off-by: Damien George <damien@micropython.org>
1 parent 744270a commit f493075

File tree

4 files changed

+28
-36
lines changed

4 files changed

+28
-36
lines changed

tests/feature_check/float.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/feature_check/float.py.exp

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/feature_check/target_info.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,15 @@
2222
][sys_mpy >> 10]
2323
thread = getattr(sys.implementation, "_thread", None)
2424

25-
print(platform, arch, thread)
25+
# Detect how many bits of precision the floating point implementation has.
26+
try:
27+
if float("1.0000001") == float("1.0"):
28+
float_prec = 30
29+
elif float("1e300") == float("inf"):
30+
float_prec = 32
31+
else:
32+
float_prec = 64
33+
except NameError:
34+
float_prec = 0
35+
36+
print(platform, arch, thread, float_prec)

tests/run-tests.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,21 @@ def detect_test_platform(pyb, args):
292292
output = run_feature_check(pyb, args, "target_info.py")
293293
if output.endswith(b"CRASH"):
294294
raise ValueError("cannot detect platform: {}".format(output))
295-
platform, arch, thread = str(output, "ascii").strip().split()
295+
platform, arch, thread, float_prec = str(output, "ascii").strip().split()
296296
if arch == "None":
297297
arch = None
298298
inlineasm_arch = detect_inline_asm_arch(pyb, args)
299299
if thread == "None":
300300
thread = None
301+
float_prec = int(float_prec)
301302

302303
args.platform = platform
303304
args.arch = arch
304305
if arch and not args.mpy_cross_flags:
305306
args.mpy_cross_flags = "-march=" + arch
306307
args.inlineasm_arch = inlineasm_arch
307308
args.thread = thread
309+
args.float_prec = float_prec
308310

309311
print("platform={}".format(platform), end="")
310312
if arch:
@@ -313,6 +315,8 @@ def detect_test_platform(pyb, args):
313315
print(" inlineasm={}".format(inlineasm_arch), end="")
314316
if thread:
315317
print(" thread={}".format(thread), end="")
318+
if float_prec:
319+
print(" float={}-bit".format(float_prec), end="")
316320
print()
317321

318322

@@ -685,8 +689,6 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
685689
has_complex = True
686690
has_coverage = False
687691

688-
upy_float_precision = 32
689-
690692
if True:
691693
# Even if we run completely different tests in a different directory,
692694
# we need to access feature_checks from the same directory as the
@@ -774,11 +776,6 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
774776
skip_tests.add("cmdline/repl_words_move.py")
775777

776778
upy_byteorder = run_feature_check(pyb, args, "byteorder.py")
777-
upy_float_precision = run_feature_check(pyb, args, "float.py")
778-
try:
779-
upy_float_precision = int(upy_float_precision)
780-
except ValueError:
781-
upy_float_precision = 0
782779
has_complex = run_feature_check(pyb, args, "complex.py") == b"complex\n"
783780
has_coverage = run_feature_check(pyb, args, "coverage.py") == b"coverage\n"
784781
cpy_byteorder = subprocess.check_output(
@@ -814,15 +811,15 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
814811
# fails with stack overflow on Debug builds
815812
skip_tests.add("misc/sys_settrace_features.py")
816813

817-
if upy_float_precision == 0:
814+
if args.float_prec == 0:
818815
skip_tests.add("extmod/uctypes_le_float.py")
819816
skip_tests.add("extmod/uctypes_native_float.py")
820817
skip_tests.add("extmod/uctypes_sizeof_float.py")
821818
skip_tests.add("extmod/json_dumps_float.py")
822819
skip_tests.add("extmod/json_loads_float.py")
823820
skip_tests.add("extmod/random_extra_float.py")
824821
skip_tests.add("misc/rge_sm.py")
825-
if upy_float_precision < 32:
822+
if args.float_prec < 32:
826823
skip_tests.add(
827824
"float/float2int_intbig.py"
828825
) # requires fp32, there's float2int_fp30_intbig.py instead
@@ -832,7 +829,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
832829
skip_tests.add("float/bytes_construct.py") # requires fp32
833830
skip_tests.add("float/bytearray_construct.py") # requires fp32
834831
skip_tests.add("float/float_format_ints_power10.py") # requires fp32
835-
if upy_float_precision < 64:
832+
if args.float_prec < 64:
836833
skip_tests.add("float/float_divmod.py") # tested by float/float_divmod_relaxed.py instead
837834
skip_tests.add("float/float2int_doubleprec_intbig.py")
838835
skip_tests.add("float/float_struct_e_doubleprec.py")
@@ -1348,26 +1345,25 @@ def main():
13481345
test_dirs += ("inlineasm/{}".format(args.inlineasm_arch),)
13491346
if args.thread is not None:
13501347
test_dirs += ("thread",)
1348+
if args.float_prec > 0:
1349+
test_dirs += ("float",)
13511350
if args.platform == "pyboard":
13521351
# run pyboard tests
1353-
test_dirs += ("float", "stress", "ports/stm32")
1352+
test_dirs += ("stress", "ports/stm32")
13541353
elif args.platform == "mimxrt":
1355-
test_dirs += ("float", "stress")
1354+
test_dirs += ("stress",)
13561355
elif args.platform == "renesas-ra":
1357-
test_dirs += ("float", "ports/renesas-ra")
1356+
test_dirs += ("ports/renesas-ra")
13581357
elif args.platform == "rp2":
1359-
test_dirs += ("float", "stress", "ports/rp2")
1358+
test_dirs += ("stress", "ports/rp2")
13601359
elif args.platform == "esp32":
1361-
test_dirs += ("float", "stress")
1362-
elif args.platform in ("esp8266", "minimal", "samd", "nrf"):
1363-
test_dirs += ("float",)
1360+
test_dirs += ("stress",)
13641361
elif args.platform == "WiPy":
13651362
# run WiPy tests
13661363
test_dirs += ("ports/cc3200",)
13671364
elif args.platform in PC_PLATFORMS:
13681365
# run PC tests
13691366
test_dirs += (
1370-
"float",
13711367
"import",
13721368
"io",
13731369
"stress",
@@ -1377,11 +1373,10 @@ def main():
13771373
)
13781374
elif args.platform == "qemu":
13791375
test_dirs += (
1380-
"float",
13811376
"ports/qemu",
13821377
)
13831378
elif args.platform == "webassembly":
1384-
test_dirs += ("float", "ports/webassembly")
1379+
test_dirs += ("ports/webassembly",)
13851380
else:
13861381
# run tests from these directories
13871382
test_dirs = args.test_dirs

0 commit comments

Comments
 (0)