diff options
author | Anson Mansfield <amansfield@mantaro.com> | 2025-04-22 09:08:14 -0400 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-04-26 15:49:48 +1000 |
commit | cee0419021396a87bd38bb3231b06311f604fad4 (patch) | |
tree | ff7e789025509bbc125f6f544c5313173a2c7bb2 | |
parent | 9a377801dc5a99825d6d613f6affcafe059306c0 (diff) | |
download | micropython-cee0419021396a87bd38bb3231b06311f604fad4.tar.gz micropython-cee0419021396a87bd38bb3231b06311f604fad4.zip |
tools/mpremote/tests: Add tests for errno behavior.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
-rwxr-xr-x | tools/mpremote/tests/test_errno.sh | 38 | ||||
-rw-r--r-- | tools/mpremote/tests/test_errno.sh.exp | 25 |
2 files changed, 63 insertions, 0 deletions
diff --git a/tools/mpremote/tests/test_errno.sh b/tools/mpremote/tests/test_errno.sh new file mode 100755 index 0000000000..0899706552 --- /dev/null +++ b/tools/mpremote/tests/test_errno.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -e + +# Special ErrorFS so the test can induce arbitrary filesystem errors. +cat << EOF > "${TMP}/fs.py" +import os, vfs, errno + +class ErrorFS: + def mount(self, *a, **k): + pass + def umount(self, *a, **k): + pass + def chdir(self, *a, **k): + pass + def open(self, *a, **k): + raise self.error + +fs = ErrorFS() +vfs.mount(fs, '/fs') +os.chdir('/fs') +EOF + +$MPREMOTE run "${TMP}/fs.py" + +echo ----- +$MPREMOTE resume exec "fs.error = Exception()" +( + $MPREMOTE resume cat :Exception.py || echo "expect error" +) 2> >(head -n1 >&2) # discard traceback specifics but keep main error message + +for errno in ENOENT EISDIR EEXIST ENODEV EINVAL EPERM EOPNOTSUPP ; do +echo ----- +$MPREMOTE resume exec "fs.error = OSError(errno.$errno, '')" +$MPREMOTE resume cat :$errno.py || echo "expect error" +done + +echo ----- +$MPREMOTE resume exec "vfs.umount('/fs')" diff --git a/tools/mpremote/tests/test_errno.sh.exp b/tools/mpremote/tests/test_errno.sh.exp new file mode 100644 index 0000000000..deda52f5fb --- /dev/null +++ b/tools/mpremote/tests/test_errno.sh.exp @@ -0,0 +1,25 @@ +----- +mpremote: Error with transport: +expect error +----- +mpremote: cat: ENOENT.py: No such file or directory. +expect error +----- +mpremote: cat: EISDIR.py: Is a directory. +expect error +----- +mpremote: cat: EEXIST.py: File exists. +expect error +----- +mpremote: cat: ENODEV.py: No such device. +expect error +----- +mpremote: cat: EINVAL.py: Invalid argument. +expect error +----- +mpremote: cat: EPERM.py: Operation not permitted. +expect error +----- +mpremote: cat: EOPNOTSUPP.py: Operation not supported. +expect error +----- |