Skip to content

Commit fbca4f9

Browse files
hosakadpgeorge
authored andcommitted
tests/extmod/vfs_fat_oldproto: Test old block device protocol.
1 parent 38a9359 commit fbca4f9

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

tests/extmod/vfs_fat_oldproto.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import sys
2+
import uos
3+
import uerrno
4+
try:
5+
uos.VfsFat
6+
except AttributeError:
7+
print("SKIP")
8+
sys.exit()
9+
10+
class RAMFS_OLD:
11+
12+
SEC_SIZE = 512
13+
14+
def __init__(self, blocks):
15+
self.data = bytearray(blocks * self.SEC_SIZE)
16+
17+
def readblocks(self, n, buf):
18+
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
19+
for i in range(len(buf)):
20+
buf[i] = self.data[n * self.SEC_SIZE + i]
21+
22+
def writeblocks(self, n, buf):
23+
#print("writeblocks(%s, %x)" % (n, id(buf)))
24+
for i in range(len(buf)):
25+
self.data[n * self.SEC_SIZE + i] = buf[i]
26+
27+
def sync(self):
28+
pass
29+
30+
def count(self):
31+
return len(self.data) // self.SEC_SIZE
32+
33+
34+
try:
35+
bdev = RAMFS_OLD(48)
36+
except MemoryError:
37+
print("SKIP")
38+
sys.exit()
39+
40+
uos.vfs_mkfs(bdev, "/ramdisk")
41+
uos.vfs_mount(bdev, "/ramdisk")
42+
43+
# file io
44+
vfs = uos.VfsFat(bdev, "/ramdisk")
45+
with vfs.open("file.txt", "w") as f:
46+
f.write("hello!")
47+
48+
print(vfs.listdir())
49+
50+
with vfs.open("file.txt", "r") as f:
51+
print(f.read())
52+
53+
vfs.remove("file.txt")
54+
print(vfs.listdir())
55+
56+
# umount by device
57+
uos.vfs_umount(bdev)
58+
try:
59+
vfs.listdir()
60+
except OSError as e:
61+
print(e.args[0] == uerrno.ENODEV)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
['file.txt']
2+
hello!
3+
[]
4+
True

0 commit comments

Comments
 (0)