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.
This commit is contained in:
parent
9a973977bb
commit
b9e9cfcfc1
@ -1,24 +0,0 @@
|
||||
<io.TextIOWrapper >
|
||||
True
|
||||
True
|
||||
True
|
||||
True
|
||||
hello!world!
|
||||
12
|
||||
h
|
||||
e
|
||||
True
|
||||
d
|
||||
True
|
||||
True
|
||||
True
|
||||
True
|
||||
True
|
||||
b'data in file'
|
||||
True
|
||||
['sub_file.txt', 'file.txt']
|
||||
['foo_file.txt', 'foo_dir', 'moved-to-root.txt']
|
||||
['foo_file.txt', 'foo_dir', 'moved-to-root.txt']
|
||||
new text
|
||||
['moved-to-root.txt']
|
||||
ENOSPC: True
|
113
tests/extmod/vfs_fat_fileio1.py
Normal file
113
tests/extmod/vfs_fat_fileio1.py
Normal file
@ -0,0 +1,113 @@
|
||||
import sys
|
||||
import uerrno
|
||||
try:
|
||||
import uos_vfs as uos
|
||||
open = uos.vfs_open
|
||||
except ImportError:
|
||||
import uos
|
||||
try:
|
||||
uos.VfsFat
|
||||
except AttributeError:
|
||||
print("SKIP")
|
||||
sys.exit()
|
||||
|
||||
|
||||
class RAMFS:
|
||||
|
||||
SEC_SIZE = 512
|
||||
|
||||
def __init__(self, blocks):
|
||||
self.data = bytearray(blocks * self.SEC_SIZE)
|
||||
|
||||
def readblocks(self, n, buf):
|
||||
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
|
||||
for i in range(len(buf)):
|
||||
buf[i] = self.data[n * self.SEC_SIZE + i]
|
||||
|
||||
def writeblocks(self, n, buf):
|
||||
#print("writeblocks(%s, %x)" % (n, id(buf)))
|
||||
for i in range(len(buf)):
|
||||
self.data[n * self.SEC_SIZE + i] = buf[i]
|
||||
|
||||
def ioctl(self, op, arg):
|
||||
#print("ioctl(%d, %r)" % (op, arg))
|
||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
||||
return len(self.data) // self.SEC_SIZE
|
||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
||||
return self.SEC_SIZE
|
||||
|
||||
|
||||
try:
|
||||
bdev = RAMFS(50)
|
||||
except MemoryError:
|
||||
print("SKIP")
|
||||
sys.exit()
|
||||
|
||||
uos.VfsFat.mkfs(bdev)
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, '/ramdisk')
|
||||
uos.chdir('/ramdisk')
|
||||
|
||||
# file IO
|
||||
f = open("foo_file.txt", "w")
|
||||
print(str(f)[:17], str(f)[-1:])
|
||||
f.write("hello!")
|
||||
f.flush()
|
||||
f.close()
|
||||
f.close() # allowed
|
||||
try:
|
||||
f.write("world!")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.read()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.flush()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
open("foo_file.txt", "x")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EEXIST)
|
||||
|
||||
with open("foo_file.txt", "a") as f:
|
||||
f.write("world!")
|
||||
|
||||
with open("foo_file.txt") as f2:
|
||||
print(f2.read())
|
||||
print(f2.tell())
|
||||
|
||||
f2.seek(0, 0) # SEEK_SET
|
||||
print(f2.read(1))
|
||||
|
||||
f2.seek(0, 1) # SEEK_CUR
|
||||
print(f2.read(1))
|
||||
try:
|
||||
f2.seek(1, 1) # SEEK_END
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EOPNOTSUPP)
|
||||
|
||||
f2.seek(-2, 2) # SEEK_END
|
||||
print(f2.read(1))
|
||||
|
||||
# using constructor of FileIO type to open a file
|
||||
# no longer working with new VFS sub-system
|
||||
#FileIO = type(f)
|
||||
#with FileIO("/ramdisk/foo_file.txt") as f:
|
||||
# print(f.read())
|
||||
|
||||
# dirs
|
||||
vfs.mkdir("foo_dir")
|
||||
|
||||
try:
|
||||
vfs.rmdir("foo_file.txt")
|
||||
except OSError as e:
|
||||
print(e.args[0] == 20) # uerrno.ENOTDIR
|
||||
|
||||
vfs.remove("foo_file.txt")
|
||||
print(vfs.listdir())
|
13
tests/extmod/vfs_fat_fileio1.py.exp
Normal file
13
tests/extmod/vfs_fat_fileio1.py.exp
Normal file
@ -0,0 +1,13 @@
|
||||
<io.TextIOWrapper >
|
||||
True
|
||||
True
|
||||
True
|
||||
True
|
||||
hello!world!
|
||||
12
|
||||
h
|
||||
e
|
||||
True
|
||||
d
|
||||
True
|
||||
['foo_dir']
|
@ -48,67 +48,6 @@ vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, '/ramdisk')
|
||||
uos.chdir('/ramdisk')
|
||||
|
||||
# file IO
|
||||
f = open("foo_file.txt", "w")
|
||||
print(str(f)[:17], str(f)[-1:])
|
||||
f.write("hello!")
|
||||
f.flush()
|
||||
f.close()
|
||||
f.close() # allowed
|
||||
try:
|
||||
f.write("world!")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.read()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.flush()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
open("foo_file.txt", "x")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EEXIST)
|
||||
|
||||
with open("foo_file.txt", "a") as f:
|
||||
f.write("world!")
|
||||
|
||||
with open("foo_file.txt") as f2:
|
||||
print(f2.read())
|
||||
print(f2.tell())
|
||||
|
||||
f2.seek(0, 0) # SEEK_SET
|
||||
print(f2.read(1))
|
||||
|
||||
f2.seek(0, 1) # SEEK_CUR
|
||||
print(f2.read(1))
|
||||
try:
|
||||
f2.seek(1, 1) # SEEK_END
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EOPNOTSUPP)
|
||||
|
||||
f2.seek(-2, 2) # SEEK_END
|
||||
print(f2.read(1))
|
||||
|
||||
# using constructor of FileIO type to open a file
|
||||
# no longer working with new VFS sub-system
|
||||
#FileIO = type(f)
|
||||
#with FileIO("/ramdisk/foo_file.txt") as f:
|
||||
# print(f.read())
|
||||
|
||||
# dirs
|
||||
vfs.mkdir("foo_dir")
|
||||
|
||||
try:
|
||||
vfs.rmdir("foo_file.txt")
|
||||
except OSError as e:
|
||||
print(e.args[0] == 20) # uerrno.ENOTDIR
|
||||
|
||||
try:
|
||||
vfs.mkdir("foo_dir")
|
||||
except OSError as e:
|
||||
@ -162,7 +101,6 @@ with open("moved-to-root.txt") as f:
|
||||
|
||||
# valid removes
|
||||
vfs.remove("foo_dir/sub_file.txt")
|
||||
vfs.remove("foo_file.txt")
|
||||
vfs.rmdir("foo_dir")
|
||||
print(vfs.listdir())
|
||||
|
11
tests/extmod/vfs_fat_fileio2.py.exp
Normal file
11
tests/extmod/vfs_fat_fileio2.py.exp
Normal file
@ -0,0 +1,11 @@
|
||||
True
|
||||
True
|
||||
True
|
||||
b'data in file'
|
||||
True
|
||||
['sub_file.txt', 'file.txt']
|
||||
['foo_dir', 'moved-to-root.txt']
|
||||
['foo_dir', 'moved-to-root.txt']
|
||||
new text
|
||||
['moved-to-root.txt']
|
||||
ENOSPC: True
|
Loading…
Reference in New Issue
Block a user