diff options
author | Alex March <alex.march.dev@gmail.com> | 2016-10-25 11:14:38 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-10-27 12:22:43 +1100 |
commit | fbca4f94b36397f914a663c4ea816990f17711fa (patch) | |
tree | 3d4e84c6884ea1d61cde1ee4442f8f044b85b0a8 | |
parent | 38a9359339805626fd39a59ec6e5249a6b5e2f5a (diff) |
tests/extmod/vfs_fat_oldproto: Test old block device protocol.
-rw-r--r-- | tests/extmod/vfs_fat_oldproto.py | 61 | ||||
-rw-r--r-- | tests/extmod/vfs_fat_oldproto.py.exp | 4 |
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py new file mode 100644 index 000000000..bb8dd824c --- /dev/null +++ b/tests/extmod/vfs_fat_oldproto.py @@ -0,0 +1,61 @@ +import sys +import uos +import uerrno +try: + uos.VfsFat +except AttributeError: + print("SKIP") + sys.exit() + +class RAMFS_OLD: + + SEC_SIZE = 512 + + def __init__(self, blocks): + self.data = bytearray(blocks * self.SEC_SIZE) + + 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 * self.SEC_SIZE + i] + + def writeblocks(self, n, buf): + #print("writeblocks(%s, %x)" % (n, id(buf))) + for i in range(len(buf)): + self.data[n * self.SEC_SIZE + i] = buf[i] + + def sync(self): + pass + + def count(self): + return len(self.data) // self.SEC_SIZE + + +try: + bdev = RAMFS_OLD(48) +except MemoryError: + print("SKIP") + sys.exit() + +uos.vfs_mkfs(bdev, "/ramdisk") +uos.vfs_mount(bdev, "/ramdisk") + +# file io +vfs = uos.VfsFat(bdev, "/ramdisk") +with vfs.open("file.txt", "w") as f: + f.write("hello!") + +print(vfs.listdir()) + +with vfs.open("file.txt", "r") as f: + print(f.read()) + +vfs.remove("file.txt") +print(vfs.listdir()) + +# umount by device +uos.vfs_umount(bdev) +try: + vfs.listdir() +except OSError as e: + print(e.args[0] == uerrno.ENODEV) diff --git a/tests/extmod/vfs_fat_oldproto.py.exp b/tests/extmod/vfs_fat_oldproto.py.exp new file mode 100644 index 000000000..4120c277a --- /dev/null +++ b/tests/extmod/vfs_fat_oldproto.py.exp @@ -0,0 +1,4 @@ +['file.txt'] +hello! +[] +True |