summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorOliver Joos <oliver.joos@feller.ch>2020-11-27 11:05:39 +0100
committerDamien George <damien@micropython.org>2020-12-17 22:43:19 +1100
commitdc1fd4df7360d101952426dd0d1574d3971e50f5 (patch)
tree6afa7be632c75ff06d0b3ca6291c4cb23740106e /tests
parent1719459c28138be009c8dd41f0e6cb3b942eb2dd (diff)
downloadmicropython-dc1fd4df7360d101952426dd0d1574d3971e50f5.tar.gz
micropython-dc1fd4df7360d101952426dd0d1574d3971e50f5.zip
tests/extmod: Add test to try and mount a block device directly.
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/extmod/vfs_lfs_mount.py26
-rw-r--r--tests/extmod/vfs_lfs_mount.py.exp2
2 files changed, 21 insertions, 7 deletions
diff --git a/tests/extmod/vfs_lfs_mount.py b/tests/extmod/vfs_lfs_mount.py
index 3d8cec6075..bea8a2723a 100644
--- a/tests/extmod/vfs_lfs_mount.py
+++ b/tests/extmod/vfs_lfs_mount.py
@@ -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]
@@ -35,9 +35,17 @@ class RAMBlockDevice:
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)
@@ -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
usys.modules.clear()
-bdev = RAMBlockDevice(30)
-
# initialise path
import usys
@@ -98,5 +110,5 @@ usys.path.append("/lfs")
usys.path.append("")
# run tests
-test(bdev, uos.VfsLfs1)
-test(bdev, uos.VfsLfs2)
+test(uos.VfsLfs1)
+test(uos.VfsLfs2)
diff --git a/tests/extmod/vfs_lfs_mount.py.exp b/tests/extmod/vfs_lfs_mount.py.exp
index aa654ebe05..68561b4807 100644
--- a/tests/extmod/vfs_lfs_mount.py.exp
+++ b/tests/extmod/vfs_lfs_mount.py.exp
@@ -1,4 +1,5 @@
test <class 'VfsLfs1'>
+OSError(19,)
hello from lfs
package
hello from lfs
@@ -6,6 +7,7 @@ lfsmod2.py: print("hello from lfs")
OSError(30,)
test <class 'VfsLfs2'>
+OSError(19,)
hello from lfs
package
hello from lfs