Skip to content

Commit 0ee1d0f

Browse files
committed
tests/vfs_fat_ramdisk: Add test for VfsFat.
1 parent e3c66a5 commit 0ee1d0f

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

tests/extmod/vfs_fat_ramdisk.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import sys
2+
import uos
3+
try:
4+
uos.VfsFat
5+
except AttributeError:
6+
print("SKIP")
7+
sys.exit()
8+
9+
10+
class RAMFS:
11+
def __init__(self, blocks):
12+
self.data = bytearray(blocks * 512)
13+
14+
def readblocks(self, n, buf):
15+
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
16+
for i in range(len(buf)):
17+
buf[i] = self.data[n*512+i]
18+
19+
def writeblocks(self, n, buf):
20+
#print("writeblocks(%s, %x)" % (n, id(buf)))
21+
for i in range(len(buf)):
22+
self.data[n*512+i] = buf[i]
23+
24+
def sync(self):
25+
pass
26+
27+
def count(self):
28+
return len(self.data) // 512
29+
30+
31+
bdev = RAMFS(48)
32+
uos.VfsFat.mkfs(bdev)
33+
34+
assert b"FOO_FILETXT" not in bdev.data
35+
assert b"hello!" not in bdev.data
36+
37+
vfs = uos.VfsFat(bdev, "/ramdisk")
38+
39+
f = vfs.open("foo_file.txt", "w")
40+
f.write("hello!")
41+
f.close()
42+
43+
f2 = vfs.open("foo_file.txt")
44+
print(f2.read())
45+
f2.close()
46+
47+
assert b"FOO_FILETXT" in bdev.data
48+
assert b"hello!" in bdev.data
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello!

0 commit comments

Comments
 (0)