diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-06-20 10:56:05 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-06-20 10:56:05 -0700 |
| commit | 30ee7019ca651bce1fe966c1089fe977d51dc92b (patch) | |
| tree | 0114b6f744dd175b7722dd8edcbe24f4ee84bb45 /tests/float | |
| parent | 97fcdfbd08c922efd7470d6482d7c7c703ffc0ae (diff) | |
| parent | 869cdcfdfc860b1177baf9b0f8818915ba54f3f5 (diff) | |
Merge tag 'v1.9.1'2.0.0-alpha.0
Fixes for stmhal USB mass storage, lwIP bindings and VFS regressions
This release provides an important fix for the USB mass storage device in
the stmhal port by implementing the SCSI SYNCHRONIZE_CACHE command, which
is now require by some Operating Systems. There are also fixes for the
lwIP bindings to improve non-blocking sockets and error codes. The VFS has
some regressions fixed including the ability to statvfs the root.
All changes are listed below.
py core:
- modbuiltins: add core-provided version of input() function
- objstr: catch case of negative "maxsplit" arg to str.rsplit()
- persistentcode: allow to compile with complex numbers disabled
- objstr: allow to compile with obj-repr D, and unicode disabled
- modsys: allow to compile with obj-repr D and PY_ATTRTUPLE disabled
- provide mp_decode_uint_skip() to help reduce stack usage
- makeqstrdefs.py: make script run correctly with Python 2.6
- objstringio: if created from immutable object, follow copy on write policy
extmod:
- modlwip: connect: for non-blocking mode, return EINPROGRESS
- modlwip: fix error codes for duplicate calls to connect()
- modlwip: accept: fix error code for non-blocking mode
- vfs: allow to statvfs the root directory
- vfs: allow "buffering" and "encoding" args to VFS's open()
- modframebuf: fix signed/unsigned comparison pendantic warning
lib:
- libm: use isfinite instead of finitef, for C99 compatibility
- utils/interrupt_char: remove support for KBD_EXCEPTION disabled
tests:
- basics/string_rsplit: add tests for negative "maxsplit" argument
- float: convert "sys.exit()" to "raise SystemExit"
- float/builtin_float_minmax: PEP8 fixes
- basics: convert "sys.exit()" to "raise SystemExit"
- convert remaining "sys.exit()" to "raise SystemExit"
unix port:
- convert to use core-provided version of built-in import()
- Makefile: replace references to make with $(MAKE)
windows port:
- convert to use core-provided version of built-in import()
qemu-arm port:
- Makefile: adjust object-file lists to get correct dependencies
- enable micropython.mem_*() functions to allow more tests
stmhal port:
- boards: enable DAC for NUCLEO_F767ZI board
- add support for NUCLEO_F446RE board
- pass USB handler as parameter to allow more than one USB handler
- usb: use local USB handler variable in Start-of-Frame handler
- usb: make state for USB device private to top-level USB driver
- usbdev: for MSC implement SCSI SYNCHRONIZE_CACHE command
- convert from using stmhal's input() to core provided version
cc3200 port:
- convert from using stmhal's input() to core provided version
teensy port:
- convert from using stmhal's input() to core provided version
esp8266 port:
- Makefile: replace references to make with $(MAKE)
- Makefile: add clean-modules target
- convert from using stmhal's input() to core provided version
zephyr port:
- modusocket: getaddrinfo: Fix mp_obj_len() usage
- define MICROPY_PY_SYS_PLATFORM (to "zephyr")
- machine_pin: use native Zephyr types for Zephyr API calls
docs:
- machine.Pin: remove out_value() method
- machine.Pin: add on() and off() methods
- esp8266: consistently replace Pin.high/low methods with .on/off
- esp8266/quickref: polish Pin.on()/off() examples
- network: move confusingly-named cc3200 Server class to its reference
- uos: deconditionalize, remove minor port-specific details
- uos: move cc3200 port legacy VFS mounting functions to its ref doc
- machine: sort machine classes in logical order, not alphabetically
- network: first step to describe standard network class interface
examples:
- embedding: use core-provided KeyboardInterrupt object
Diffstat (limited to 'tests/float')
25 files changed, 227 insertions, 76 deletions
diff --git a/tests/float/array_construct.py b/tests/float/array_construct.py index a25cc72c8..938675835 100644 --- a/tests/float/array_construct.py +++ b/tests/float/array_construct.py @@ -1,6 +1,10 @@ # test construction of array from array with float type -from array import array +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit print(array('f', array('h', [1, 2]))) print(array('d', array('f', [1, 2]))) diff --git a/tests/float/builtin_float_hash.py b/tests/float/builtin_float_hash.py new file mode 100644 index 000000000..ba6b63907 --- /dev/null +++ b/tests/float/builtin_float_hash.py @@ -0,0 +1,22 @@ +# test builtin hash function with float args + +# these should hash to an integer with a specific value +for val in ( + '0.0', + '1.0', + '2.0', + '-12.0', + '12345.0', + ): + print(val, hash(float(val))) + +# just check that these values are hashable +for val in ( + '0.1', + '-0.1', + '10.3', + 'inf', + '-inf', + 'nan', + ): + print(val, type(hash(float(val)))) diff --git a/tests/float/builtin_float_minmax.py b/tests/float/builtin_float_minmax.py index ce45a768a..266ed133d 100644 --- a/tests/float/builtin_float_minmax.py +++ b/tests/float/builtin_float_minmax.py @@ -1,26 +1,32 @@ # test builtin min and max functions with float args +try: + min + max +except: + print("SKIP") + raise SystemExit -print(min(0,1.0)) -print(min(1.0,0)) -print(min(0,-1.0)) -print(min(-1.0,0)) +print(min(0, 1.0)) +print(min(1.0, 0)) +print(min(0, -1.0)) +print(min(-1.0, 0)) -print(max(0,1.0)) -print(max(1.0,0)) -print(max(0,-1.0)) -print(max(-1.0,0)) +print(max(0, 1.0)) +print(max(1.0, 0)) +print(max(0, -1.0)) +print(max(-1.0, 0)) -print(min(1.5,-1.5)) -print(min(-1.5,1.5)) +print(min(1.5, -1.5)) +print(min(-1.5, 1.5)) -print(max(1.5,-1.5)) -print(max(-1.5,1.5)) +print(max(1.5, -1.5)) +print(max(-1.5, 1.5)) -print(min([1,2.9,4,0,-1,2])) -print(max([1,2.9,4,0,-1,2])) +print(min([1, 2.9, 4, 0, -1, 2])) +print(max([1, 2.9, 4, 0, -1, 2])) -print(min([1,2.9,4,6.5,-1,2])) -print(max([1,2.9,4,6.5,-1,2])) -print(min([1,2.9,4,-6.5,-1,2])) -print(max([1,2.9,4,-6.5,-1,2])) +print(min([1, 2.9, 4, 6.5, -1, 2])) +print(max([1, 2.9, 4, 6.5, -1, 2])) +print(min([1, 2.9, 4, -6.5, -1, 2])) +print(max([1, 2.9, 4, -6.5, -1, 2])) diff --git a/tests/float/builtin_float_round.py b/tests/float/builtin_float_round.py index de72514db..63cb39aa3 100644 --- a/tests/float/builtin_float_round.py +++ b/tests/float/builtin_float_round.py @@ -15,3 +15,10 @@ for i in range(11): # test second arg for i in range(-1, 3): print(round(1.47, i)) + +# test inf and nan +for val in (float('inf'), float('nan')): + try: + round(val) + except (ValueError, OverflowError) as e: + print(type(e)) diff --git a/tests/float/builtin_float_round_intbig.py b/tests/float/builtin_float_round_intbig.py new file mode 100644 index 000000000..2083e3ea3 --- /dev/null +++ b/tests/float/builtin_float_round_intbig.py @@ -0,0 +1,4 @@ +# test round() with floats that return large integers + +for x in (-1e25, 1e25): + print('%.3g' % round(x)) diff --git a/tests/float/bytearray_construct.py b/tests/float/bytearray_construct.py index f72926635..e960d624e 100644 --- a/tests/float/bytearray_construct.py +++ b/tests/float/bytearray_construct.py @@ -1,5 +1,9 @@ # test construction of bytearray from array with float type -from array import array +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit print(bytearray(array('f', [1, 2.3]))) diff --git a/tests/float/bytes_construct.py b/tests/float/bytes_construct.py index 0a57e08a2..0e4482e43 100644 --- a/tests/float/bytes_construct.py +++ b/tests/float/bytes_construct.py @@ -1,5 +1,9 @@ # test construction of bytearray from array with float type -from array import array +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit print(bytes(array('f', [1, 2.3]))) diff --git a/tests/float/cmath_fun.py b/tests/float/cmath_fun.py index 3ebcf5918..ae5921c30 100644 --- a/tests/float/cmath_fun.py +++ b/tests/float/cmath_fun.py @@ -4,8 +4,7 @@ try: from cmath import * except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit # make sure these constants exist in cmath print("%.5g" % e) diff --git a/tests/float/cmath_fun_special.py b/tests/float/cmath_fun_special.py index 422964dd7..471fda8c0 100644 --- a/tests/float/cmath_fun_special.py +++ b/tests/float/cmath_fun_special.py @@ -5,8 +5,7 @@ try: log10 except (ImportError, NameError): print("SKIP") - import sys - sys.exit() + raise SystemExit test_values_non_zero = [] base_values = (0.0, 0.5, 1.2345, 10.) diff --git a/tests/float/complex1.py b/tests/float/complex1.py index 027d12583..a6038de04 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -28,6 +28,7 @@ print(1j / 2) print((1j / 2j).real) print(1j / (1 + 2j)) ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag)) @@ -40,6 +41,10 @@ print(1j == 1j) print(abs(1j)) print("%.5g" % abs(1j + 2)) +# builtin hash +print(hash(1 + 0j)) +print(type(hash(1j))) + # float on lhs should delegate to complex print(1.2 + 3j) @@ -48,8 +53,11 @@ print(float('nan') * 1j) print(float('inf') * (1 + 1j)) print(float('-inf') * (1 + 1j)) -# convert bignum to complex on rhs -ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag)) +# can't assign to attributes +try: + (1j).imag = 0 +except AttributeError: + print('AttributeError') # can't convert rhs to complex try: @@ -89,6 +97,10 @@ except ZeroDivisionError: # zero division via power try: + 0j ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") +try: 0j ** 1j except ZeroDivisionError: print("ZeroDivisionError") diff --git a/tests/float/complex1_intbig.py b/tests/float/complex1_intbig.py new file mode 100644 index 000000000..ed2390bba --- /dev/null +++ b/tests/float/complex1_intbig.py @@ -0,0 +1,4 @@ +# test basic complex number functionality + +# convert bignum to complex on rhs +ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag)) diff --git a/tests/float/float1.py b/tests/float/float1.py index 0e115032b..93f6f014c 100644 --- a/tests/float/float1.py +++ b/tests/float/float1.py @@ -75,6 +75,11 @@ try: except ZeroDivisionError: print("ZeroDivisionError") +try: + 0.0 ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") + # unsupported unary ops try: diff --git a/tests/float/float2int_doubleprec.py b/tests/float/float2int_doubleprec_intbig.py index acdc8c69c..de2137d66 100644 --- a/tests/float/float2int_doubleprec.py +++ b/tests/float/float2int_doubleprec_intbig.py @@ -5,21 +5,29 @@ try: except: import struct +import sys +maxsize_bits = 0 +maxsize = sys.maxsize +while maxsize: + maxsize >>= 1 + maxsize_bits += 1 + # work out configuration values -is_64bit = struct.calcsize("P") == 8 +is_64bit = maxsize_bits > 32 # 0 = none, 1 = long long, 2 = mpz -try: - dummy = 0x7fffffffffffffff - try: - if (0xffffffffffffffff + 1) > 0: - ll_type = 2 - else: - ll_type = 1 - except: - # in case the sum in the if statement above changes to raising an exception on overflow +ll_type = None +if is_64bit: + if maxsize_bits < 63: + ll_type = 0 +else: + if maxsize_bits < 31: + ll_type = 0 +if ll_type is None: + one = 1 + if one << 65 < one << 62: ll_type = 1 -except: - ll_type = 0 + else: + ll_type = 2 # This case occurs with time.time() values if ll_type != 0: diff --git a/tests/float/float2int_fp30.py b/tests/float/float2int_fp30_intbig.py index bad9c31e9..fbb94a4cc 100644 --- a/tests/float/float2int_fp30.py +++ b/tests/float/float2int_fp30_intbig.py @@ -5,21 +5,29 @@ try: except: import struct +import sys +maxsize_bits = 0 +maxsize = sys.maxsize +while maxsize: + maxsize >>= 1 + maxsize_bits += 1 + # work out configuration values -is_64bit = struct.calcsize("P") == 8 +is_64bit = maxsize_bits > 32 # 0 = none, 1 = long long, 2 = mpz -try: - dummy = 0x7fffffffffffffff - try: - if (0xffffffffffffffff + 1) > 0: - ll_type = 2 - else: - ll_type = 1 - except: - # in case the sum in the if statement above changes to raising an exception on overflow +ll_type = None +if is_64bit: + if maxsize_bits < 63: + ll_type = 0 +else: + if maxsize_bits < 31: + ll_type = 0 +if ll_type is None: + one = 1 + if one << 65 < one << 62: ll_type = 1 -except: - ll_type = 0 + else: + ll_type = 2 # basic conversion print(int(14187744.)) diff --git a/tests/float/float2int.py b/tests/float/float2int_intbig.py index da530cee6..3596d2f73 100644 --- a/tests/float/float2int.py +++ b/tests/float/float2int_intbig.py @@ -5,21 +5,31 @@ try: except: import struct +import sys + +maxsize_bits = 0 +maxsize = sys.maxsize +while maxsize: + maxsize >>= 1 + maxsize_bits += 1 + # work out configuration values -is_64bit = struct.calcsize("P") == 8 +is_64bit = maxsize_bits > 32 # 0 = none, 1 = long long, 2 = mpz -try: - dummy = 0x7fffffffffffffff - try: - if (0xffffffffffffffff + 1) > 0: - ll_type = 2 - else: - ll_type = 1 - except: - # in case the sum in the if statement above changes to raising an exception on overflow +ll_type = None +if is_64bit: + if maxsize_bits < 63: + ll_type = 0 +else: + if maxsize_bits < 31: + ll_type = 0 +if ll_type is None: + one = 1 + if one << 65 < one << 62: ll_type = 1 -except: - ll_type = 0 + else: + ll_type = 2 + # basic conversion print(int(14187745.)) diff --git a/tests/float/float_array.py b/tests/float/float_array.py index 033877db3..8c8edcff7 100644 --- a/tests/float/float_array.py +++ b/tests/float/float_array.py @@ -1,4 +1,8 @@ -from array import array +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit def test(a): print(a) diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py index e55890a2c..c4c186b89 100644 --- a/tests/float/float_struct.py +++ b/tests/float/float_struct.py @@ -1,9 +1,12 @@ # test struct package with floats - try: - import ustruct as struct -except: - import struct + try: + import ustruct as struct + except: + import struct +except ImportError: + print("SKIP") + raise SystemExit i = 1. + 1/2 # TODO: it looks like '=' format modifier is not yet supported diff --git a/tests/float/int_divzero.py b/tests/float/int_divzero.py index b037dd8c7..b311a1dbc 100644 --- a/tests/float/int_divzero.py +++ b/tests/float/int_divzero.py @@ -2,3 +2,8 @@ try: 1 / 0 except ZeroDivisionError: print("ZeroDivisionError") + +try: + 0 ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") diff --git a/tests/float/math_fun.py b/tests/float/math_fun.py index d9f179587..80d20bd8a 100644 --- a/tests/float/math_fun.py +++ b/tests/float/math_fun.py @@ -4,8 +4,7 @@ try: from math import * except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.] test_values_small = [-10., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 10.] # so we don't overflow 32-bit precision diff --git a/tests/float/math_fun_bool.py b/tests/float/math_fun_bool.py index 57232857a..30ab14a52 100644 --- a/tests/float/math_fun_bool.py +++ b/tests/float/math_fun_bool.py @@ -4,8 +4,7 @@ try: from math import isfinite, isnan, isinf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), -float('NaN'), -float('Inf')] diff --git a/tests/float/math_fun_int.py b/tests/float/math_fun_int.py new file mode 100644 index 000000000..5cadbb1e5 --- /dev/null +++ b/tests/float/math_fun_int.py @@ -0,0 +1,14 @@ +# test the math functions that return ints + +try: + import math +except ImportError: + print("SKIP") + raise SystemExit + +for fun in (math.ceil, math.floor, math.trunc): + for x in (-1.6, -0.2, 0, 0.6, 1.4, float('inf'), float('nan')): + try: + print(fun(x)) + except (ValueError, OverflowError) as e: + print(type(e)) diff --git a/tests/float/math_fun_intbig.py b/tests/float/math_fun_intbig.py new file mode 100644 index 000000000..697ca7a6d --- /dev/null +++ b/tests/float/math_fun_intbig.py @@ -0,0 +1,11 @@ +# test the math functions that return ints, with very large results + +try: + import math +except ImportError: + print("SKIP") + raise SystemExit + +for fun in (math.ceil, math.floor, math.trunc): + for x in (-1e25, 1e25): + print('%.3g' % fun(x)) diff --git a/tests/float/math_fun_special.py b/tests/float/math_fun_special.py index 32249b423..c3665a7cd 100644 --- a/tests/float/math_fun_special.py +++ b/tests/float/math_fun_special.py @@ -5,8 +5,7 @@ try: erf except (ImportError, NameError): print("SKIP") - import sys - sys.exit() + raise SystemExit test_values = [-8., -2.5, -1, -0.5, 0.0, 0.5, 2.5, 8.,] pos_test_values = [0.001, 0.1, 0.5, 1.0, 1.5, 10.,] diff --git a/tests/float/string_format_modulo2.py b/tests/float/string_format_modulo2.py index d35f2a2c0..f6b1ae537 100644 --- a/tests/float/string_format_modulo2.py +++ b/tests/float/string_format_modulo2.py @@ -18,7 +18,7 @@ def test(num, num_str): # check pure zero test(0.0, '0.0') -# check most powers of 10, making sure to include exponents with 3 digits -for e in range(-101, 102): +# check some powers of 10, making sure to include exponents with 3 digits +for e in range(-8, 8): num = pow(10, e) test(num, '1e%d' % e) diff --git a/tests/float/string_format_modulo2_intbig.py b/tests/float/string_format_modulo2_intbig.py new file mode 100644 index 000000000..9992ba65d --- /dev/null +++ b/tests/float/string_format_modulo2_intbig.py @@ -0,0 +1,21 @@ +# test formatting floats with large precision, that it doesn't overflow the buffer + +def test(num, num_str): + if num == float('inf') or num == 0.0 and num_str != '0.0': + # skip numbers that overflow or underflow the FP precision + return + for kind in ('e', 'f', 'g'): + # check precision either side of the size of the buffer (32 bytes) + for prec in range(23, 36, 2): + fmt = '%.' + '%d' % prec + kind + s = fmt % num + check = abs(float(s) - num) + if num > 1: + check /= num + if check > 1e-6: + print('FAIL', num_str, fmt, s, len(s), check) + +# check most powers of 10, making sure to include exponents with 3 digits +for e in range(-101, 102): + num = pow(10, e) + test(num, '1e%d' % e) |
