summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-02-12 01:03:39 +1100
committerDamien George <damien@micropython.org>2022-02-12 09:45:32 +1100
commit2ea21abae0358a46c0144f014f2e5891afe03dfd (patch)
tree2127a2bb16d0e2c155c955492f43265db838dc66 /tests
parentf46a7140f55a8f6d80f9c2d5f8db7af3de116794 (diff)
tests/extmod/vfs_fat_finaliser.py: Make finalisation more robust.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/extmod/vfs_fat_finaliser.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py
index b67afc2d9..b38e640c7 100644
--- a/tests/extmod/vfs_fat_finaliser.py
+++ b/tests/extmod/vfs_fat_finaliser.py
@@ -56,6 +56,12 @@ micropython.heap_unlock()
# Here we test that the finaliser is actually called during a garbage collection.
import gc
+# Preallocate global variables, and list of filenames for the test (which may
+# in turn allocate new qstrs and/or a new qstr pool).
+f = None
+n = None
+names = ["x%d" % i for i in range(4)]
+
# Do a large number of single-block allocations to move the GC head forwards,
# ensuring that the files are allocated from never-before-used blocks and
# therefore couldn't possibly have any references to them left behind on
@@ -63,14 +69,13 @@ import gc
for i in range(1024):
[]
-N = 4
-for i in range(N):
- n = "x%d" % i
+# Run the test: create files without closing them, run GC, then read back files.
+for n in names:
f = vfs.open(n, "w")
f.write(n)
f = None # release f without closing
- [0, 1, 2, 3] # use up Python stack so f is really gone
+ sorted([0, 1, 2, 3], key=lambda x: x) # use up Python and C stack so f is really gone
gc.collect() # should finalise all N files by closing them
-for i in range(N):
- with vfs.open("x%d" % i, "r") as f:
+for n in names:
+ with vfs.open(n, "r") as f:
print(f.read())