tests/extmod/vfs_fat_finaliser.py: Make finalisation more robust.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
f46a7140f5
commit
2ea21abae0
@ -56,6 +56,12 @@ micropython.heap_unlock()
|
|||||||
# Here we test that the finaliser is actually called during a garbage collection.
|
# Here we test that the finaliser is actually called during a garbage collection.
|
||||||
import gc
|
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,
|
# 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
|
# ensuring that the files are allocated from never-before-used blocks and
|
||||||
# therefore couldn't possibly have any references to them left behind on
|
# therefore couldn't possibly have any references to them left behind on
|
||||||
@ -63,14 +69,13 @@ import gc
|
|||||||
for i in range(1024):
|
for i in range(1024):
|
||||||
[]
|
[]
|
||||||
|
|
||||||
N = 4
|
# Run the test: create files without closing them, run GC, then read back files.
|
||||||
for i in range(N):
|
for n in names:
|
||||||
n = "x%d" % i
|
|
||||||
f = vfs.open(n, "w")
|
f = vfs.open(n, "w")
|
||||||
f.write(n)
|
f.write(n)
|
||||||
f = None # release f without closing
|
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
|
gc.collect() # should finalise all N files by closing them
|
||||||
for i in range(N):
|
for n in names:
|
||||||
with vfs.open("x%d" % i, "r") as f:
|
with vfs.open(n, "r") as f:
|
||||||
print(f.read())
|
print(f.read())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user