diff options
| author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2023-10-31 15:14:05 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-11-09 11:20:31 +1100 |
| commit | 4cf741062b20fa34062d236d56b2168515e990b4 (patch) | |
| tree | f5362f11623a29ded6d47398e5fe9f480e2f3e50 /tests | |
| parent | dff293840e381444bcd843a325ab3dd7da685733 (diff) | |
extmod/vfs_reader: Add file ioctl to set read buffer size.
Can be used to speed up importing a file from a vfs based filesystem.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extmod/vfs_userfs.py | 18 | ||||
| -rw-r--r-- | tests/extmod/vfs_userfs.py.exp | 16 |
2 files changed, 33 insertions, 1 deletions
diff --git a/tests/extmod/vfs_userfs.py b/tests/extmod/vfs_userfs.py index 36f108887..5c487315e 100644 --- a/tests/extmod/vfs_userfs.py +++ b/tests/extmod/vfs_userfs.py @@ -16,6 +16,8 @@ except (ImportError, AttributeError): class UserFile(io.IOBase): + buffer_size = 16 + def __init__(self, mode, data): assert isinstance(data, bytes) self.is_text = mode.find("b") == -1 @@ -39,7 +41,11 @@ class UserFile(io.IOBase): def ioctl(self, req, arg): print("ioctl", req, arg) - return 0 + if req == 4: # MP_STREAM_CLOSE + return 0 + if req == 11: # MP_STREAM_GET_BUFFER_SIZE + return UserFile.buffer_size + return -1 class UserFS: @@ -70,6 +76,8 @@ user_files = { "/usermod2.py": b"print('in usermod2')", "/usermod3.py": b"syntax error", "/usermod4.mpy": b"syntax error", + "/usermod5.py": b"print('in usermod5')", + "/usermod6.py": b"print('in usermod6')", } os.mount(UserFS(user_files), "/userfs") @@ -93,6 +101,14 @@ try: except ValueError: print("ValueError in usermod4") +# Test an import with largest buffer size +UserFile.buffer_size = 255 +import usermod5 + +# Test an import with over-size buffer size (should be safely limited internally) +UserFile.buffer_size = 1024 +import usermod6 + # unmount and undo path addition os.umount("/userfs") sys.path.pop() diff --git a/tests/extmod/vfs_userfs.py.exp b/tests/extmod/vfs_userfs.py.exp index 05cff0452..be8011d56 100644 --- a/tests/extmod/vfs_userfs.py.exp +++ b/tests/extmod/vfs_userfs.py.exp @@ -3,21 +3,37 @@ some data in a text file stat /usermod1 stat /usermod1.py open /usermod1.py rb +ioctl 11 0 ioctl 4 0 in usermod1 stat /usermod2 stat /usermod2.py open /usermod2.py rb +ioctl 11 0 ioctl 4 0 in usermod2 stat /usermod3 stat /usermod3.py open /usermod3.py rb +ioctl 11 0 ioctl 4 0 SyntaxError in usermod3 stat /usermod4 stat /usermod4.py stat /usermod4.mpy open /usermod4.mpy rb +ioctl 11 0 ioctl 4 0 ValueError in usermod4 +stat /usermod5 +stat /usermod5.py +open /usermod5.py rb +ioctl 11 0 +ioctl 4 0 +in usermod5 +stat /usermod6 +stat /usermod6.py +open /usermod6.py rb +ioctl 11 0 +ioctl 4 0 +in usermod6 |
