Skip to content

Commit

Permalink
tests/extmod: Add test to try and mount a block device directly.
Browse files Browse the repository at this point in the history
Mounting a bdev directly tries to auto-detect the filesystem and if none is
found an OSError(19,) should be raised.

The fourth parameter of readblocks() and writeblocks() must be optional to
support ports with MICROPY_VFS_FAT=1.  Otherwise mounting a bdev may fail
because looking for a FATFS will call readblocks() with only 3 parameters.
  • Loading branch information
Oliver Joos authored and pfalcon committed Dec 30, 2020
1 parent 253c1ea commit d0fcd30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tests/extmod/vfs_lfs_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class RAMBlockDevice:
def __init__(self, blocks):
self.data = bytearray(blocks * self.ERASE_BLOCK_SIZE)

def readblocks(self, block, buf, off):
def readblocks(self, block, buf, off=0):
addr = block * self.ERASE_BLOCK_SIZE + off
for i in range(len(buf)):
buf[i] = self.data[addr + i]

def writeblocks(self, block, buf, off):
def writeblocks(self, block, buf, off=0):
addr = block * self.ERASE_BLOCK_SIZE + off
for i in range(len(buf)):
self.data[addr + i] = buf[i]
Expand All @@ -35,9 +35,17 @@ def ioctl(self, op, arg):
return 0


def test(bdev, vfs_class):
def test(vfs_class):
print("test", vfs_class)

bdev = RAMBlockDevice(30)

# mount bdev unformatted
try:
uos.mount(bdev, "/lfs")
except Exception as er:
print(repr(er))

# mkfs
vfs_class.mkfs(bdev)

Expand Down Expand Up @@ -84,12 +92,16 @@ def test(bdev, vfs_class):
# umount
uos.umount("/lfs")

# mount bdev again
uos.mount(bdev, "/lfs")

# umount
uos.umount("/lfs")

# clear imported modules
sys.modules.clear()


bdev = RAMBlockDevice(30)

# initialise path
import sys

Expand All @@ -98,5 +110,5 @@ def test(bdev, vfs_class):
sys.path.append("")

# run tests
test(bdev, uos.VfsLfs1)
test(bdev, uos.VfsLfs2)
test(uos.VfsLfs1)
test(uos.VfsLfs2)
2 changes: 2 additions & 0 deletions tests/extmod/vfs_lfs_mount.py.exp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
test <class 'VfsLfs1'>
OSError(19,)
hello from lfs
package
hello from lfs
lfsmod2.py: print("hello from lfs")

OSError(30,)
test <class 'VfsLfs2'>
OSError(19,)
hello from lfs
package
hello from lfs
Expand Down

0 comments on commit d0fcd30

Please sign in to comment.