tests/extmod/vfs_fat: Update tests to work with new VFS sub-system.
The vfs_fat_fsusermount test is no longer relevant so has been removed.
This commit is contained in:
parent
f9ecd484bb
commit
b9bfaa349a
|
@ -1,6 +1,10 @@
|
|||
import sys
|
||||
import uos
|
||||
import uerrno
|
||||
try:
|
||||
import uos_vfs as uos
|
||||
open = uos.vfs_open
|
||||
except ImportError:
|
||||
import uos
|
||||
try:
|
||||
uos.VfsFat
|
||||
except AttributeError:
|
||||
|
@ -40,10 +44,12 @@ except MemoryError:
|
|||
sys.exit()
|
||||
|
||||
uos.VfsFat.mkfs(bdev)
|
||||
vfs = uos.VfsFat(bdev, "/ramdisk")
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, '/ramdisk')
|
||||
uos.chdir('/ramdisk')
|
||||
|
||||
# file IO
|
||||
f = vfs.open("foo_file.txt", "w")
|
||||
f = open("foo_file.txt", "w")
|
||||
print(str(f)[:17], str(f)[-1:])
|
||||
f.write("hello!")
|
||||
f.flush()
|
||||
|
@ -65,14 +71,14 @@ except OSError as e:
|
|||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
vfs.open("foo_file.txt", "x")
|
||||
open("foo_file.txt", "x")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EEXIST)
|
||||
|
||||
with vfs.open("foo_file.txt", "a") as f:
|
||||
with open("foo_file.txt", "a") as f:
|
||||
f.write("world!")
|
||||
|
||||
with vfs.open("foo_file.txt") as f2:
|
||||
with open("foo_file.txt") as f2:
|
||||
print(f2.read())
|
||||
print(f2.tell())
|
||||
|
||||
|
@ -90,9 +96,10 @@ with vfs.open("foo_file.txt") as f2:
|
|||
print(f2.read(1))
|
||||
|
||||
# using constructor of FileIO type to open a file
|
||||
FileIO = type(f)
|
||||
with FileIO("/ramdisk/foo_file.txt") as f:
|
||||
print(f.read())
|
||||
# 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")
|
||||
|
@ -123,13 +130,13 @@ except OSError as e:
|
|||
print(e.args[0] == uerrno.ENOENT)
|
||||
|
||||
# file in dir
|
||||
with vfs.open("foo_dir/file-in-dir.txt", "w+t") as f:
|
||||
with open("foo_dir/file-in-dir.txt", "w+t") as f:
|
||||
f.write("data in file")
|
||||
|
||||
with vfs.open("foo_dir/file-in-dir.txt", "r+b") as f:
|
||||
with open("foo_dir/file-in-dir.txt", "r+b") as f:
|
||||
print(f.read())
|
||||
|
||||
with vfs.open("foo_dir/sub_file.txt", "w") as f:
|
||||
with open("foo_dir/sub_file.txt", "w") as f:
|
||||
f.write("subdir file")
|
||||
|
||||
# directory not empty
|
||||
|
@ -146,11 +153,11 @@ vfs.rename("foo_dir/file.txt", "moved-to-root.txt")
|
|||
print(vfs.listdir())
|
||||
|
||||
# check that renaming to existing file will overwrite it
|
||||
with vfs.open("temp", "w") as f:
|
||||
with open("temp", "w") as f:
|
||||
f.write("new text")
|
||||
vfs.rename("temp", "moved-to-root.txt")
|
||||
print(vfs.listdir())
|
||||
with vfs.open("moved-to-root.txt") as f:
|
||||
with open("moved-to-root.txt") as f:
|
||||
print(f.read())
|
||||
|
||||
# valid removes
|
||||
|
@ -163,7 +170,7 @@ print(vfs.listdir())
|
|||
try:
|
||||
bsize = vfs.statvfs("/ramdisk")[0]
|
||||
free = vfs.statvfs("/ramdisk")[2] + 1
|
||||
f = vfs.open("large_file.txt", "wb")
|
||||
f = open("large_file.txt", "wb")
|
||||
f.write(bytearray(bsize * free))
|
||||
except OSError as e:
|
||||
print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC
|
||||
|
|
|
@ -9,7 +9,6 @@ h
|
|||
e
|
||||
True
|
||||
d
|
||||
hello!world!
|
||||
True
|
||||
True
|
||||
True
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
import sys
|
||||
import uos
|
||||
import uerrno
|
||||
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()
|
||||
|
||||
# can't mkfs readonly device
|
||||
try:
|
||||
uos.vfs_mkfs(bdev, "/ramdisk", readonly=True)
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
||||
# mount before mkfs
|
||||
try:
|
||||
uos.vfs_mount(bdev, "/ramdisk")
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
||||
# invalid umount
|
||||
try:
|
||||
uos.vfs_umount("/ramdisk")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
uos.vfs_mount(None, "/ramdisk")
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
||||
try:
|
||||
uos.vfs_mkfs(None, "/ramdisk")
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
||||
# valid mkfs/mount
|
||||
uos.vfs_mkfs(bdev, "/ramdisk")
|
||||
uos.vfs_mount(bdev, "/ramdisk")
|
||||
|
||||
# umount by path
|
||||
uos.vfs_umount("/ramdisk")
|
||||
|
||||
# readonly mount
|
||||
# note: this test doesn't work correctly with new OO FatFs
|
||||
uos.vfs_mount(bdev, "/ramdisk", readonly=True)
|
||||
vfs = uos.VfsFat(bdev, "/ramdisk")
|
||||
try:
|
||||
f = vfs.open("file.txt", "w")
|
||||
except OSError as e:
|
||||
print("EROFS:", e.args[0] == 30) # uerrno.EROFS
|
||||
|
||||
# device is None == umount
|
||||
uos.vfs_mount(None, "/ramdisk")
|
||||
|
||||
# max mounted devices
|
||||
dev = []
|
||||
try:
|
||||
for i in range(0,4):
|
||||
dev.append(RAMFS(50))
|
||||
uos.vfs_mkfs(dev[i], "/ramdisk" + str(i))
|
||||
uos.vfs_mount(dev[i], "/ramdisk" + str(i))
|
||||
except OSError as e:
|
||||
print(e)
|
|
@ -1,6 +0,0 @@
|
|||
can't mkfs
|
||||
can't mount
|
||||
True
|
||||
can't umount
|
||||
can't umount
|
||||
too many devices mounted
|
|
@ -1,10 +1,11 @@
|
|||
import sys
|
||||
import uos
|
||||
import uerrno
|
||||
try:
|
||||
import uos_vfs as uos
|
||||
except ImportError:
|
||||
import uos
|
||||
try:
|
||||
uos.VfsFat
|
||||
uos.vfs_mkfs
|
||||
uos.vfs_mount
|
||||
except AttributeError:
|
||||
print("SKIP")
|
||||
sys.exit()
|
||||
|
@ -39,11 +40,11 @@ except MemoryError:
|
|||
print("SKIP")
|
||||
sys.exit()
|
||||
|
||||
uos.vfs_mkfs(bdev, "/ramdisk")
|
||||
uos.vfs_mount(bdev, "/ramdisk")
|
||||
uos.VfsFat.mkfs(bdev)
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, "/ramdisk")
|
||||
|
||||
# file io
|
||||
vfs = uos.VfsFat(bdev, "/ramdisk")
|
||||
with vfs.open("file.txt", "w") as f:
|
||||
f.write("hello!")
|
||||
|
||||
|
@ -54,6 +55,3 @@ with vfs.open("file.txt", "r") as f:
|
|||
|
||||
vfs.remove("file.txt")
|
||||
print(vfs.listdir())
|
||||
|
||||
# umount by device
|
||||
uos.vfs_umount(bdev)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import sys
|
||||
import uos
|
||||
import uerrno
|
||||
try:
|
||||
import uos_vfs as uos
|
||||
except ImportError:
|
||||
import uos
|
||||
try:
|
||||
uos.VfsFat
|
||||
except AttributeError:
|
||||
|
@ -44,7 +47,8 @@ uos.VfsFat.mkfs(bdev)
|
|||
print(b"FOO_FILETXT" not in bdev.data)
|
||||
print(b"hello!" not in bdev.data)
|
||||
|
||||
vfs = uos.VfsFat(bdev, "/ramdisk")
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, "/ramdisk")
|
||||
|
||||
print("statvfs:", vfs.statvfs("/ramdisk"))
|
||||
print("getcwd:", vfs.getcwd())
|
||||
|
@ -59,7 +63,6 @@ with vfs.open("foo_file.txt", "w") as f:
|
|||
print(vfs.listdir())
|
||||
|
||||
print("stat root:", vfs.stat("/"))
|
||||
print("stat disk:", vfs.stat("/ramdisk/"))
|
||||
print("stat file:", vfs.stat("foo_file.txt"))
|
||||
|
||||
print(b"FOO_FILETXT" in bdev.data)
|
||||
|
@ -81,7 +84,7 @@ except OSError as e:
|
|||
vfs.chdir("..")
|
||||
print("getcwd:", vfs.getcwd())
|
||||
|
||||
vfs.umount()
|
||||
uos.umount(vfs)
|
||||
|
||||
vfs = uos.VfsFat(bdev, "/ramdisk")
|
||||
vfs = uos.VfsFat(bdev)
|
||||
print(vfs.listdir(b""))
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
True
|
||||
True
|
||||
statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
|
||||
getcwd: /ramdisk
|
||||
getcwd: /
|
||||
True
|
||||
['foo_file.txt']
|
||||
stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
stat disk: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
stat file: (32768, 0, 0, 0, 0, 0, 6, -631238400, -631238400, -631238400)
|
||||
True
|
||||
True
|
||||
getcwd: /ramdisk/foo_dir
|
||||
getcwd: /foo_dir
|
||||
[]
|
||||
True
|
||||
getcwd: /ramdisk
|
||||
getcwd: /
|
||||
[b'foo_file.txt', b'foo_dir']
|
||||
|
|
Loading…
Reference in New Issue