tests/vfs_fat_ramdisk: Add test for VfsFat.
This commit is contained in:
parent
e3c66a5a67
commit
0ee1d0f407
48
tests/extmod/vfs_fat_ramdisk.py
Normal file
48
tests/extmod/vfs_fat_ramdisk.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import sys
|
||||||
|
import uos
|
||||||
|
try:
|
||||||
|
uos.VfsFat
|
||||||
|
except AttributeError:
|
||||||
|
print("SKIP")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
class RAMFS:
|
||||||
|
def __init__(self, blocks):
|
||||||
|
self.data = bytearray(blocks * 512)
|
||||||
|
|
||||||
|
def readblocks(self, n, buf):
|
||||||
|
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
|
||||||
|
for i in range(len(buf)):
|
||||||
|
buf[i] = self.data[n*512+i]
|
||||||
|
|
||||||
|
def writeblocks(self, n, buf):
|
||||||
|
#print("writeblocks(%s, %x)" % (n, id(buf)))
|
||||||
|
for i in range(len(buf)):
|
||||||
|
self.data[n*512+i] = buf[i]
|
||||||
|
|
||||||
|
def sync(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def count(self):
|
||||||
|
return len(self.data) // 512
|
||||||
|
|
||||||
|
|
||||||
|
bdev = RAMFS(48)
|
||||||
|
uos.VfsFat.mkfs(bdev)
|
||||||
|
|
||||||
|
assert b"FOO_FILETXT" not in bdev.data
|
||||||
|
assert b"hello!" not in bdev.data
|
||||||
|
|
||||||
|
vfs = uos.VfsFat(bdev, "/ramdisk")
|
||||||
|
|
||||||
|
f = vfs.open("foo_file.txt", "w")
|
||||||
|
f.write("hello!")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
f2 = vfs.open("foo_file.txt")
|
||||||
|
print(f2.read())
|
||||||
|
f2.close()
|
||||||
|
|
||||||
|
assert b"FOO_FILETXT" in bdev.data
|
||||||
|
assert b"hello!" in bdev.data
|
1
tests/extmod/vfs_fat_ramdisk.py.exp
Normal file
1
tests/extmod/vfs_fat_ramdisk.py.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
hello!
|
Loading…
Reference in New Issue
Block a user