tests/vfs_fat_ramdisk: Add test for VfsFat.

This commit is contained in:
Paul Sokolovsky 2016-02-14 19:02:34 +02:00
parent e3c66a5a67
commit 0ee1d0f407
2 changed files with 49 additions and 0 deletions

View 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

View File

@ -0,0 +1 @@
hello!