Skip to content

Commit cee0419

Browse files
AJMansfielddpgeorge
authored andcommitted
tools/mpremote/tests: Add tests for errno behavior.
Signed-off-by: Anson Mansfield <[email protected]>
1 parent 9a37780 commit cee0419

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tools/mpremote/tests/test_errno.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Special ErrorFS so the test can induce arbitrary filesystem errors.
5+
cat << EOF > "${TMP}/fs.py"
6+
import os, vfs, errno
7+
8+
class ErrorFS:
9+
def mount(self, *a, **k):
10+
pass
11+
def umount(self, *a, **k):
12+
pass
13+
def chdir(self, *a, **k):
14+
pass
15+
def open(self, *a, **k):
16+
raise self.error
17+
18+
fs = ErrorFS()
19+
vfs.mount(fs, '/fs')
20+
os.chdir('/fs')
21+
EOF
22+
23+
$MPREMOTE run "${TMP}/fs.py"
24+
25+
echo -----
26+
$MPREMOTE resume exec "fs.error = Exception()"
27+
(
28+
$MPREMOTE resume cat :Exception.py || echo "expect error"
29+
) 2> >(head -n1 >&2) # discard traceback specifics but keep main error message
30+
31+
for errno in ENOENT EISDIR EEXIST ENODEV EINVAL EPERM EOPNOTSUPP ; do
32+
echo -----
33+
$MPREMOTE resume exec "fs.error = OSError(errno.$errno, '')"
34+
$MPREMOTE resume cat :$errno.py || echo "expect error"
35+
done
36+
37+
echo -----
38+
$MPREMOTE resume exec "vfs.umount('/fs')"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-----
2+
mpremote: Error with transport:
3+
expect error
4+
-----
5+
mpremote: cat: ENOENT.py: No such file or directory.
6+
expect error
7+
-----
8+
mpremote: cat: EISDIR.py: Is a directory.
9+
expect error
10+
-----
11+
mpremote: cat: EEXIST.py: File exists.
12+
expect error
13+
-----
14+
mpremote: cat: ENODEV.py: No such device.
15+
expect error
16+
-----
17+
mpremote: cat: EINVAL.py: Invalid argument.
18+
expect error
19+
-----
20+
mpremote: cat: EPERM.py: Operation not permitted.
21+
expect error
22+
-----
23+
mpremote: cat: EOPNOTSUPP.py: Operation not supported.
24+
expect error
25+
-----

0 commit comments

Comments
 (0)