From a604451566ca415cc6ab6f9cce40c19045cb8e16 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 26 Feb 2018 13:36:13 +1100 Subject: [PATCH] tests/extmod/vfs_fat_fileio1: Add test for failing alloc with finaliser. --- tests/extmod/vfs_fat_fileio1.py | 12 ++++++++++++ tests/extmod/vfs_fat_fileio1.py.exp | 1 + 2 files changed, 13 insertions(+) diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index 8b9ff92eb8..8c8ec57472 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -113,3 +113,15 @@ except OSError as e: vfs.remove("foo_file.txt") print(list(vfs.ilistdir())) + +# Here we test that opening a file with the heap locked fails correctly. This +# is a special case because file objects use a finaliser and allocating with a +# finaliser is a different path to normal allocation. It would be better to +# test this in the core tests but there are no core objects that use finaliser. +import micropython +micropython.heap_lock() +try: + vfs.open('x', 'r') +except MemoryError: + print('MemoryError') +micropython.heap_unlock() diff --git a/tests/extmod/vfs_fat_fileio1.py.exp b/tests/extmod/vfs_fat_fileio1.py.exp index a66f07605c..a304c75d96 100644 --- a/tests/extmod/vfs_fat_fileio1.py.exp +++ b/tests/extmod/vfs_fat_fileio1.py.exp @@ -11,3 +11,4 @@ o d True [('foo_dir', 16384, 0)] +MemoryError