summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2025-04-24 05:07:28 +0200
committerDamien George <damien@micropython.org>2025-04-24 22:11:42 +1000
commitce7f65f96703bbbe6039ba29e079023a32dccef0 (patch)
tree2942116ec7115c9a448cc590876195445dc7d04a /tests
parent898c04ae0e24ca523a630eecc9ac4b4787e55a7e (diff)
downloadmicropython-ce7f65f96703bbbe6039ba29e079023a32dccef0.tar.gz
micropython-ce7f65f96703bbbe6039ba29e079023a32dccef0.zip
tests/extmod/vfs_posix.py: Fix test on Android.
This commit makes a slight change to the vfs_posix test suite to let it pass on Android. On Android, non-root processes can perform most filesystem operations only on a restricted set of directories. The vfs_posix test suite attempted to enumerate the filesystem root directory, and said directory happens to be restricted for non-root processes. This would raise an EACCES OSError and terminate the test with a unexpected failure. To fix this, rather than enumerating the filesystem root directory the enumeration target is the internal shared storage area root - which doesn't have enumeration restrictions for non-root processes. The path is hardcoded because it is guaranteed to be there on pretty much any recent-ish device for now (it stayed the same for more than a decade for compatibility reasons). The proper way would be to query the storage subsystem via a JNI round-trip call, but this introduces too much complexity for something that is unlikely to break going forward. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Diffstat (limited to 'tests')
-rw-r--r--tests/extmod/vfs_posix.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/extmod/vfs_posix.py b/tests/extmod/vfs_posix.py
index d060c0b9c8..b3ca2753ba 100644
--- a/tests/extmod/vfs_posix.py
+++ b/tests/extmod/vfs_posix.py
@@ -29,7 +29,21 @@ print(os.getcwd() == curdir)
print(type(os.stat("/")))
# listdir and ilistdir
-print(type(os.listdir("/")))
+target = "/"
+try:
+ import platform
+
+ # On Android non-root users are permitted full filesystem access only to
+ # selected directories. To let this test pass on bionic, the internal
+ # user-accessible storage area root is enumerated instead of the
+ # filesystem root. "/storage/emulated/0" should be there on pretty much
+ # any recent-ish device; querying the proper location requires a JNI
+ # round-trip, not really worth it.
+ if platform.platform().startswith("Android-"):
+ target = "/storage/emulated/0"
+except ImportError:
+ pass
+print(type(os.listdir(target)))
# mkdir
os.mkdir(temp_dir)