Add simple test
This commit is contained in:
parent
f832386cda
commit
1197394a03
70
tests/extmod/vfs_fat_case.py
Normal file
70
tests/extmod/vfs_fat_case.py
Normal file
@ -0,0 +1,70 @@
|
||||
try:
|
||||
import uerrno
|
||||
import uos
|
||||
except ImportError:
|
||||
print("missing u")
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
try:
|
||||
uos.VfsFat
|
||||
except AttributeError:
|
||||
print("missing VfsFat")
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
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]
|
||||
return 0
|
||||
|
||||
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]
|
||||
return 0
|
||||
|
||||
def ioctl(self, op, arg):
|
||||
# print("ioctl(%d, %r)" % (op, arg))
|
||||
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
||||
return len(self.data) // self.SEC_SIZE
|
||||
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||
return self.SEC_SIZE
|
||||
|
||||
|
||||
try:
|
||||
bdev = RAMFS(50)
|
||||
except MemoryError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
uos.VfsFat.mkfs(bdev)
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, "/ramdisk")
|
||||
uos.chdir("/ramdisk")
|
||||
|
||||
# Check ASCII case-insensitivity
|
||||
vfs.mkdir("foo_dir_az")
|
||||
print(uos.listdir(""))
|
||||
vfs.rmdir("fOO_dir_AZ")
|
||||
|
||||
# Characters outside of a-z are case sensitive.
|
||||
vfs.mkdir("extended_æ")
|
||||
print(uos.listdir(""))
|
||||
try:
|
||||
vfs.rmdir("extended_Æ")
|
||||
except OSError as e:
|
||||
print(e.errno == uerrno.ENOENT)
|
||||
vfs.rmdir("extended_æ")
|
||||
|
||||
# Emoji test for fun.
|
||||
vfs.mkdir("emoji_😀")
|
||||
vfs.rmdir("emoji_😀")
|
3
tests/extmod/vfs_fat_case.py.exp
Normal file
3
tests/extmod/vfs_fat_case.py.exp
Normal file
@ -0,0 +1,3 @@
|
||||
['foo_dir_az']
|
||||
['extended_æ']
|
||||
True
|
Loading…
Reference in New Issue
Block a user