Skip to content

Commit

Permalink
tests/vfs_fat_ramdisk: Add test for VfsFat.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Sokolovsky committed Feb 14, 2016
1 parent e3c66a5 commit 0ee1d0f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/extmod/vfs_fat_ramdisk.py
@@ -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 change: 1 addition & 0 deletions tests/extmod/vfs_fat_ramdisk.py.exp
@@ -0,0 +1 @@
hello!

0 comments on commit 0ee1d0f

Please sign in to comment.