Skip to content

Commit 2ea21ab

Browse files
committed
tests/extmod/vfs_fat_finaliser.py: Make finalisation more robust.
Signed-off-by: Damien George <[email protected]>
1 parent f46a714 commit 2ea21ab

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tests/extmod/vfs_fat_finaliser.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,26 @@ def ioctl(self, op, arg):
5656
# Here we test that the finaliser is actually called during a garbage collection.
5757
import gc
5858

59+
# Preallocate global variables, and list of filenames for the test (which may
60+
# in turn allocate new qstrs and/or a new qstr pool).
61+
f = None
62+
n = None
63+
names = ["x%d" % i for i in range(4)]
64+
5965
# Do a large number of single-block allocations to move the GC head forwards,
6066
# ensuring that the files are allocated from never-before-used blocks and
6167
# therefore couldn't possibly have any references to them left behind on
6268
# the stack.
6369
for i in range(1024):
6470
[]
6571

66-
N = 4
67-
for i in range(N):
68-
n = "x%d" % i
72+
# Run the test: create files without closing them, run GC, then read back files.
73+
for n in names:
6974
f = vfs.open(n, "w")
7075
f.write(n)
7176
f = None # release f without closing
72-
[0, 1, 2, 3] # use up Python stack so f is really gone
77+
sorted([0, 1, 2, 3], key=lambda x: x) # use up Python and C stack so f is really gone
7378
gc.collect() # should finalise all N files by closing them
74-
for i in range(N):
75-
with vfs.open("x%d" % i, "r") as f:
79+
for n in names:
80+
with vfs.open(n, "r") as f:
7681
print(f.read())

0 commit comments

Comments
 (0)