8000 tests/extmod: Add test to try and mount a block device directly. · mbtronics/micropython@dc1fd4d · GitHub
[go: up one dir, main page]

Skip to content

Commit dc1fd4d

Browse files
Oliver Joosdpgeorge
authored andcommitted
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.
1 parent 1719459 commit dc1fd4d

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

tests/extmod/vfs_lfs_mount.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class RAMBlockDevice:
1616
def __init__(self, blocks):
1717
self.data = bytearray(blocks * self.ERASE_BLOCK_SIZE)
1818

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

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

3737

38-
def test(bdev, vfs_class):
38+
def test(vfs_class):
3939
print("test", vfs_class)
4040

41+
bdev = RAMBlockDevice(30)
42+
43+
# mount bdev unformatted
44+
try:
45+
uos.mount(bdev, "/lfs")
46+
except Exception as er:
47+
print(repr(er))
48+
4149
# mkfs
4250
vfs_class.mkfs(bdev)
4351

@@ -84,12 +92,16 @@ def test(bdev, vfs_class):
8492
# umount
8593
uos.umount("/lfs")
8694

95+
# mount bdev again
96+
uos.mount(bdev, "/lfs")
97+
98+
# umount
99+
uos.umount("/lfs")
100+
87101
# clear imported modules
88102
usys.modules.clear()
89103

90104

91-
bdev = RAMBlockDevice(30)
92-
93105
# initialise path
94106
import usys
95107

@@ -98,5 +110,5 @@ def test(bdev, vfs_class):
98110
usys.path.append("")
99111

100112
# run tests
101-
test(bdev, uos.VfsLfs1)
102-
test(bdev, uos.VfsLfs2)
113+
test(uos.VfsLfs1)
114+
test(uos.VfsLfs2)

tests/extmod/vfs_lfs_mount.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
test <class 'VfsLfs1'>
2+
OSError(19,)
23
hello from lfs
34
package
45
hello from lfs
56
lfsmod2.py: print("hello from lfs")
67

78
OSError(30,)
89
test <class 'VfsLfs2'>
10+
OSError(19,)
911
hello from lfs
1012
package
1113
hello from lfs

0 commit comments

Comments
 (0)
0