From b9bfaa349aaba4462522fd9330dbc5b21f47d906 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Jan 2017 15:34:36 +1100 Subject: [PATCH] tests/extmod/vfs_fat: Update tests to work with new VFS sub-system. The vfs_fat_fsusermount test is no longer relevant so has been removed. --- tests/extmod/vfs_fat_fileio.py | 37 ++++++---- tests/extmod/vfs_fat_fileio.py.exp | 1 - tests/extmod/vfs_fat_fsusermount.py | 97 ------------------------- tests/extmod/vfs_fat_fsusermount.py.exp | 6 -- tests/extmod/vfs_fat_oldproto.py | 16 ++-- tests/extmod/vfs_fat_ramdisk.py | 13 ++-- tests/extmod/vfs_fat_ramdisk.py.exp | 7 +- 7 files changed, 40 insertions(+), 137 deletions(-) delete mode 100644 tests/extmod/vfs_fat_fsusermount.py delete mode 100644 tests/extmod/vfs_fat_fsusermount.py.exp diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio.py index fd84cdca8f..6fdac07102 100644 --- a/tests/extmod/vfs_fat_fileio.py +++ b/tests/extmod/vfs_fat_fileio.py @@ -1,6 +1,10 @@ import sys -import uos import uerrno +try: + import uos_vfs as uos + open = uos.vfs_open +except ImportError: + import uos try: uos.VfsFat except AttributeError: @@ -40,10 +44,12 @@ except MemoryError: sys.exit() uos.VfsFat.mkfs(bdev) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) +uos.mount(vfs, '/ramdisk') +uos.chdir('/ramdisk') # file IO -f = vfs.open("foo_file.txt", "w") +f = open("foo_file.txt", "w") print(str(f)[:17], str(f)[-1:]) f.write("hello!") f.flush() @@ -65,14 +71,14 @@ except OSError as e: print(e.args[0] == uerrno.EINVAL) try: - vfs.open("foo_file.txt", "x") + open("foo_file.txt", "x") except OSError as e: print(e.args[0] == uerrno.EEXIST) -with vfs.open("foo_file.txt", "a") as f: +with open("foo_file.txt", "a") as f: f.write("world!") -with vfs.open("foo_file.txt") as f2: +with open("foo_file.txt") as f2: print(f2.read()) print(f2.tell()) @@ -90,9 +96,10 @@ with vfs.open("foo_file.txt") as f2: print(f2.read(1)) # using constructor of FileIO type to open a file -FileIO = type(f) -with FileIO("/ramdisk/foo_file.txt") as f: - print(f.read()) +# no longer working with new VFS sub-system +#FileIO = type(f) +#with FileIO("/ramdisk/foo_file.txt") as f: +# print(f.read()) # dirs vfs.mkdir("foo_dir") @@ -123,13 +130,13 @@ except OSError as e: print(e.args[0] == uerrno.ENOENT) # file in dir -with vfs.open("foo_dir/file-in-dir.txt", "w+t") as f: +with open("foo_dir/file-in-dir.txt", "w+t") as f: f.write("data in file") -with vfs.open("foo_dir/file-in-dir.txt", "r+b") as f: +with open("foo_dir/file-in-dir.txt", "r+b") as f: print(f.read()) -with vfs.open("foo_dir/sub_file.txt", "w") as f: +with open("foo_dir/sub_file.txt", "w") as f: f.write("subdir file") # directory not empty @@ -146,11 +153,11 @@ vfs.rename("foo_dir/file.txt", "moved-to-root.txt") print(vfs.listdir()) # check that renaming to existing file will overwrite it -with vfs.open("temp", "w") as f: +with open("temp", "w") as f: f.write("new text") vfs.rename("temp", "moved-to-root.txt") print(vfs.listdir()) -with vfs.open("moved-to-root.txt") as f: +with open("moved-to-root.txt") as f: print(f.read()) # valid removes @@ -163,7 +170,7 @@ print(vfs.listdir()) try: bsize = vfs.statvfs("/ramdisk")[0] free = vfs.statvfs("/ramdisk")[2] + 1 - f = vfs.open("large_file.txt", "wb") + f = open("large_file.txt", "wb") f.write(bytearray(bsize * free)) except OSError as e: print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC diff --git a/tests/extmod/vfs_fat_fileio.py.exp b/tests/extmod/vfs_fat_fileio.py.exp index a09442ae80..4e34e83a82 100644 --- a/tests/extmod/vfs_fat_fileio.py.exp +++ b/tests/extmod/vfs_fat_fileio.py.exp @@ -9,7 +9,6 @@ h e True d -hello!world! True True True diff --git a/tests/extmod/vfs_fat_fsusermount.py b/tests/extmod/vfs_fat_fsusermount.py deleted file mode 100644 index 0ab15d827c..0000000000 --- a/tests/extmod/vfs_fat_fsusermount.py +++ /dev/null @@ -1,97 +0,0 @@ -import sys -import uos -import uerrno -try: - uos.VfsFat -except AttributeError: - print("SKIP") - sys.exit() - - -class RAMFS: - - 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 ioctl(self, op, arg): - #print("ioctl(%d, %r)" % (op, arg)) - if op == 4: # BP_IOCTL_SEC_COUNT - return len(self.data) // self.SEC_SIZE - if op == 5: # BP_IOCTL_SEC_SIZE - return self.SEC_SIZE - - -try: - bdev = RAMFS(50) -except MemoryError: - print("SKIP") - sys.exit() - -# can't mkfs readonly device -try: - uos.vfs_mkfs(bdev, "/ramdisk", readonly=True) -except OSError as e: - print(e) - -# mount before mkfs -try: - uos.vfs_mount(bdev, "/ramdisk") -except OSError as e: - print(e) - -# invalid umount -try: - uos.vfs_umount("/ramdisk") -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - uos.vfs_mount(None, "/ramdisk") -except OSError as e: - print(e) - -try: - uos.vfs_mkfs(None, "/ramdisk") -except OSError as e: - print(e) - -# valid mkfs/mount -uos.vfs_mkfs(bdev, "/ramdisk") -uos.vfs_mount(bdev, "/ramdisk") - -# umount by path -uos.vfs_umount("/ramdisk") - -# readonly mount -# note: this test doesn't work correctly with new OO FatFs -uos.vfs_mount(bdev, "/ramdisk", readonly=True) -vfs = uos.VfsFat(bdev, "/ramdisk") -try: - f = vfs.open("file.txt", "w") -except OSError as e: - print("EROFS:", e.args[0] == 30) # uerrno.EROFS - -# device is None == umount -uos.vfs_mount(None, "/ramdisk") - -# max mounted devices -dev = [] -try: - for i in range(0,4): - dev.append(RAMFS(50)) - uos.vfs_mkfs(dev[i], "/ramdisk" + str(i)) - uos.vfs_mount(dev[i], "/ramdisk" + str(i)) -except OSError as e: - print(e) diff --git a/tests/extmod/vfs_fat_fsusermount.py.exp b/tests/extmod/vfs_fat_fsusermount.py.exp deleted file mode 100644 index 3ace58372e..0000000000 --- a/tests/extmod/vfs_fat_fsusermount.py.exp +++ /dev/null @@ -1,6 +0,0 @@ -can't mkfs -can't mount -True -can't umount -can't umount -too many devices mounted diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index b43fbd286a..03ab76e35f 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,10 +1,11 @@ import sys -import uos import uerrno +try: + import uos_vfs as uos +except ImportError: + import uos try: uos.VfsFat - uos.vfs_mkfs - uos.vfs_mount except AttributeError: print("SKIP") sys.exit() @@ -39,11 +40,11 @@ except MemoryError: print("SKIP") sys.exit() -uos.vfs_mkfs(bdev, "/ramdisk") -uos.vfs_mount(bdev, "/ramdisk") +uos.VfsFat.mkfs(bdev) +vfs = uos.VfsFat(bdev) +uos.mount(vfs, "/ramdisk") # file io -vfs = uos.VfsFat(bdev, "/ramdisk") with vfs.open("file.txt", "w") as f: f.write("hello!") @@ -54,6 +55,3 @@ with vfs.open("file.txt", "r") as f: vfs.remove("file.txt") print(vfs.listdir()) - -# umount by device -uos.vfs_umount(bdev) diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 1480d52f6f..a9eb1679a7 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,6 +1,9 @@ import sys -import uos import uerrno +try: + import uos_vfs as uos +except ImportError: + import uos try: uos.VfsFat except AttributeError: @@ -44,7 +47,8 @@ uos.VfsFat.mkfs(bdev) print(b"FOO_FILETXT" not in bdev.data) print(b"hello!" not in bdev.data) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) +uos.mount(vfs, "/ramdisk") print("statvfs:", vfs.statvfs("/ramdisk")) print("getcwd:", vfs.getcwd()) @@ -59,7 +63,6 @@ with vfs.open("foo_file.txt", "w") as f: print(vfs.listdir()) print("stat root:", vfs.stat("/")) -print("stat disk:", vfs.stat("/ramdisk/")) print("stat file:", vfs.stat("foo_file.txt")) print(b"FOO_FILETXT" in bdev.data) @@ -81,7 +84,7 @@ except OSError as e: vfs.chdir("..") print("getcwd:", vfs.getcwd()) -vfs.umount() +uos.umount(vfs) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) print(vfs.listdir(b"")) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index 095620f178..fda7d300e0 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -1,16 +1,15 @@ True True statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255) -getcwd: /ramdisk +getcwd: / True ['foo_file.txt'] stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) -stat disk: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) stat file: (32768, 0, 0, 0, 0, 0, 6, -631238400, -631238400, -631238400) True True -getcwd: /ramdisk/foo_dir +getcwd: /foo_dir [] True -getcwd: /ramdisk +getcwd: / [b'foo_file.txt', b'foo_dir']