Skip to content

Commit 773b0ba

Browse files
committed
tests/extmod/vfs_basic: Add more tests for basic VFS functionality.
1 parent d1ae6ae commit 773b0ba

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

tests/extmod/vfs_basic.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,33 @@ def listdir(self, dir):
2525
return ['a%d' % self.id]
2626
def chdir(self, dir):
2727
print(self.id, 'chdir', dir)
28+
def getcwd(self):
29+
print(self.id, 'getcwd')
30+
return 'dir%d' % self.id
31+
def mkdir(self, path):
32+
print(self.id, 'mkdir', path)
33+
def remove(self, path):
34+
print(self.id, 'remove', path)
35+
def rename(self, old_path, new_path):
36+
print(self.id, 'rename', old_path, new_path)
37+
def rmdir(self, path):
38+
print(self.id, 'rmdir', path)
39+
def stat(self, path):
40+
print(self.id, 'stat', path)
41+
return (self.id,)
42+
def statvfs(self, path):
43+
print(self.id, 'statvfs', path)
44+
return (self.id,)
2845
def open(self, file, mode):
2946
print(self.id, 'open', file, mode)
3047

3148

49+
# stat root dir
50+
print(uos.stat('/'))
51+
52+
# getcwd when in root dir
53+
print(uos.getcwd())
54+
3255
# basic mounting and listdir
3356
uos.mount(Filesystem(1), '/test_mnt')
3457
print(uos.listdir())
@@ -42,14 +65,43 @@ def open(self, file, mode):
4265
print(uos.listdir())
4366
print(uos.listdir('/test_mnt2'))
4467

45-
# chdir
68+
# mounting over an existing mount point
69+
try:
70+
uos.mount(Filesystem(3), '/test_mnt2')
71+
except OSError:
72+
print('OSError')
73+
74+
# mkdir of a mount point
75+
try:
76+
uos.mkdir('/test_mnt')
77+
except OSError:
78+
print('OSError')
79+
80+
# rename across a filesystem
81+
try:
82+
uos.rename('/test_mnt/a', '/test_mnt2/b')
83+
except OSError:
84+
print('OSError')
85+
86+
# delegating to mounted filesystem
4687
uos.chdir('test_mnt')
4788
print(uos.listdir())
48-
49-
# open
89+
print(uos.getcwd())
90+
uos.mkdir('test_dir')
91+
uos.remove('test_file')
92+
uos.rename('test_file', 'test_file2')
93+
uos.rmdir('test_dir')
94+
print(uos.stat('test_file'))
95+
print(uos.statvfs('/test_mnt'))
5096
open('test_file')
5197
open('test_file', 'wb')
5298

5399
# umount
54100
uos.umount('/test_mnt')
55101
uos.umount('/test_mnt2')
102+
103+
# umount a non-existent mount point
104+
try:
105+
uos.umount('/test_mnt')
106+
except OSError:
107+
print('OSError')

tests/extmod/vfs_basic.py.exp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
2+
/
13
1 mount False False
24
['test_mnt']
35
1 listdir /
@@ -8,10 +10,25 @@
810
['test_mnt', 'test_mnt2']
911
2 listdir /
1012
['a2']
13+
3 mount False False
14+
OSError
15+
OSError
16+
OSError
1117
1 chdir /
1218
1 listdir
1319
['a1']
20+
1 getcwd
21+
/test_mntdir1
22+
1 mkdir test_dir
23+
1 remove test_file
24+
1 rename test_file test_file2
25+
1 rmdir test_dir
26+
1 stat test_file
27+
(1,)
28+
1 statvfs /
29+
(1,)
1430
1 open test_file r
1531
1 open test_file wb
1632
1 umount
1733
2 umount
34+
OSError

0 commit comments

Comments
 (0)