diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extmod/deflate_compress_memory_error.py | 39 | ||||
| -rw-r--r-- | tests/extmod/deflate_compress_memory_error.py.exp | 2 | ||||
| -rwxr-xr-x | tests/run-tests.py | 1 |
3 files changed, 42 insertions, 0 deletions
diff --git a/tests/extmod/deflate_compress_memory_error.py b/tests/extmod/deflate_compress_memory_error.py new file mode 100644 index 000000000..56ce06030 --- /dev/null +++ b/tests/extmod/deflate_compress_memory_error.py @@ -0,0 +1,39 @@ +# Test deflate.DeflateIO compression, with out-of-memory errors. + +try: + # Check if deflate is available. + import deflate + import io +except ImportError: + print("SKIP") + raise SystemExit + +# Check if compression is enabled. +if not hasattr(deflate.DeflateIO, "write"): + print("SKIP") + raise SystemExit + +# Create a compressor object. +b = io.BytesIO() +g = deflate.DeflateIO(b, deflate.RAW, 15) + +# Then, use up most of the heap. +l = [] +while True: + try: + l.append(bytearray(1000)) + except: + break +l.pop() + +# Try to compress. This will try to allocate a large window and fail. +try: + g.write('test') +except MemoryError: + print("MemoryError") + +# Should still be able to close the stream. +g.close() + +# The underlying output stream should be unchanged. +print(b.getvalue()) diff --git a/tests/extmod/deflate_compress_memory_error.py.exp b/tests/extmod/deflate_compress_memory_error.py.exp new file mode 100644 index 000000000..606315c14 --- /dev/null +++ b/tests/extmod/deflate_compress_memory_error.py.exp @@ -0,0 +1,2 @@ +MemoryError +b'' diff --git a/tests/run-tests.py b/tests/run-tests.py index 50adb6b4d..9e7cab468 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -163,6 +163,7 @@ platform_tests_to_skip = { "extmod/asyncio_threadsafeflag.py", "extmod/asyncio_wait_for_fwd.py", "extmod/binascii_a2b_base64.py", + "extmod/deflate_compress_memory_error.py", # tries to allocate unlimited memory "extmod/re_stack_overflow.py", "extmod/time_res.py", "extmod/vfs_posix.py", |
