Skip to content

Commit b9e9cfc

Browse files
committed
tests: vfs_fat_fileio.py is too big to be parsed in 16K heap, split in 2.
This restores ability to run testsuite with 16K heap.
1 parent 9a97397 commit b9e9cfc

File tree

5 files changed

+137
-86
lines changed

5 files changed

+137
-86
lines changed

tests/extmod/vfs_fat_fileio.py.exp

-24
This file was deleted.

tests/extmod/vfs_fat_fileio1.py

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import sys
2+
import uerrno
3+
try:
4+
import uos_vfs as uos
5+
open = uos.vfs_open
6+
except ImportError:
7+
import uos
8+
try:
9+
uos.VfsFat
10+
except AttributeError:
11+
print("SKIP")
12+
sys.exit()
13+
14+
15+
class RAMFS:
16+
17+
SEC_SIZE = 512
18+
19+
def __init__(self, blocks):
20+
self.data = bytearray(blocks * self.SEC_SIZE)
21+
22+
def readblocks(self, n, buf):
23+
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
24+
for i in range(len(buf)):
25+
buf[i] = self.data[n * self.SEC_SIZE + i]
26+
27+
def writeblocks(self, n, buf):
28+
#print("writeblocks(%s, %x)" % (n, id(buf)))
29+
for i in range(len(buf)):
30+
self.data[n * self.SEC_SIZE + i] = buf[i]
31+
32+
def ioctl(self, op, arg):
33+
#print("ioctl(%d, %r)" % (op, arg))
34+
if op == 4: # BP_IOCTL_SEC_COUNT
35+
return len(self.data) // self.SEC_SIZE
36+
if op == 5: # BP_IOCTL_SEC_SIZE
37+
return self.SEC_SIZE
38+
39+
40+
try:
41+
bdev = RAMFS(50)
42+
except MemoryError:
43+
print("SKIP")
44+
sys.exit()
45+
46+
uos.VfsFat.mkfs(bdev)
47+
vfs = uos.VfsFat(bdev)
48+
uos.mount(vfs, '/ramdisk')
49+
uos.chdir('/ramdisk')
50+
51+
# file IO
52+
f = open("foo_file.txt", "w")
53+
print(str(f)[:17], str(f)[-1:])
54+
f.write("hello!")
55+
f.flush()
56+
f.close()
57+
f.close() # allowed
58+
try:
59+
f.write("world!")
60+
except OSError as e:
61+
print(e.args[0] == uerrno.EINVAL)
62+
63+
try:
64+
f.read()
65+
except OSError as e:
66+
print(e.args[0] == uerrno.EINVAL)
67+
68+
try:
69+
f.flush()
70+
except OSError as e:
71+
print(e.args[0] == uerrno.EINVAL)
72+
73+
try:
74+
open("foo_file.txt", "x")
75+
except OSError as e:
76+
print(e.args[0] == uerrno.EEXIST)
77+
78+
with open("foo_file.txt", "a") as f:
79+
f.write("world!")
80+
81+
with open("foo_file.txt") as f2:
82+
print(f2.read())
83+
print(f2.tell())
84+
85+
f2.seek(0, 0) # SEEK_SET
86+
print(f2.read(1))
87+
88+
f2.seek(0, 1) # SEEK_CUR
89+
print(f2.read(1))
90+
try:
91+
f2.seek(1, 1) # SEEK_END
92+
except OSError as e:
93+
print(e.args[0] == uerrno.EOPNOTSUPP)
94+
95+
f2.seek(-2, 2) # SEEK_END
96+
print(f2.read(1))
97+
98+
# using constructor of FileIO type to open a file
99+
# no longer working with new VFS sub-system
100+
#FileIO = type(f)
101+
#with FileIO("/ramdisk/foo_file.txt") as f:
102+
# print(f.read())
103+
104+
# dirs
105+
vfs.mkdir("foo_dir")
106+
107+
try:
108+
vfs.rmdir("foo_file.txt")
109+
except OSError as e:
110+
print(e.args[0] == 20) # uerrno.ENOTDIR
111+
112+
vfs.remove("foo_file.txt")
113+
print(vfs.listdir())

tests/extmod/vfs_fat_fileio1.py.exp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<io.TextIOWrapper >
2+
True
3+
True
4+
True
5+
True
6+
hello!world!
7+
12
8+
h
9+
e
10+
True
11+
d
12+
True
13+
['foo_dir']

tests/extmod/vfs_fat_fileio.py renamed to tests/extmod/vfs_fat_fileio2.py

-62
Original file line numberDiff line numberDiff line change
@@ -48,67 +48,6 @@ def ioctl(self, op, arg):
4848
uos.mount(vfs, '/ramdisk')
4949
uos.chdir('/ramdisk')
5050

51-
# file IO
52-
f = open("foo_file.txt", "w")
53-
print(str(f)[:17], str(f)[-1:])
54-
f.write("hello!")
55-
f.flush()
56-
f.close()
57-
f.close() # allowed
58-
try:
59-
f.write("world!")
60-
except OSError as e:
61-
print(e.args[0] == uerrno.EINVAL)
62-
63-
try:
64-
f.read()
65-
except OSError as e:
66-
print(e.args[0] == uerrno.EINVAL)
67-
68-
try:
69-
f.flush()
70-
except OSError as e:
71-
print(e.args[0] == uerrno.EINVAL)
72-
73-
try:
74-
open("foo_file.txt", "x")
75-
except OSError as e:
76-
print(e.args[0] == uerrno.EEXIST)
77-
78-
with open("foo_file.txt", "a") as f:
79-
f.write("world!")
80-
81-
with open("foo_file.txt") as f2:
82-
print(f2.read())
83-
print(f2.tell())
84-
85-
f2.seek(0, 0) # SEEK_SET
86-
print(f2.read(1))
87-
88-
f2.seek(0, 1) # SEEK_CUR
89-
print(f2.read(1))
90-
try:
91-
f2.seek(1, 1) # SEEK_END
92-
except OSError as e:
93-
print(e.args[0] == uerrno.EOPNOTSUPP)
94-
95-
f2.seek(-2, 2) # SEEK_END
96-
print(f2.read(1))
97-
98-
# using constructor of FileIO type to open a file
99-
# no longer working with new VFS sub-system
100-
#FileIO = type(f)
101-
#with FileIO("/ramdisk/foo_file.txt") as f:
102-
# print(f.read())
103-
104-
# dirs
105-
vfs.mkdir("foo_dir")
106-
107-
try:
108-
vfs.rmdir("foo_file.txt")
109-
except OSError as e:
110-
print(e.args[0] == 20) # uerrno.ENOTDIR
111-
11251
try:
11352
vfs.mkdir("foo_dir")
11453
except OSError as e:
@@ -162,7 +101,6 @@ def ioctl(self, op, arg):
162101

163102
# valid removes
164103
vfs.remove("foo_dir/sub_file.txt")
165-
vfs.remove("foo_file.txt")
166104
vfs.rmdir("foo_dir")
167105
print(vfs.listdir())
168106

tests/extmod/vfs_fat_fileio2.py.exp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
True
2+
True
3+
True
4+
b'data in file'
5+
True
6+
['sub_file.txt', 'file.txt']
7+
['foo_dir', 'moved-to-root.txt']
8+
['foo_dir', 'moved-to-root.txt']
9+
new text
10+
['moved-to-root.txt']
11+
ENOSPC: True

0 commit comments

Comments
 (0)