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>
This commit is contained in:
Alessandro Gatti 2025-04-24 05:07:28 +02:00 committed by Damien George
parent 898c04ae0e
commit ce7f65f967

View file

@ -29,7 +29,21 @@ print(os.getcwd() == curdir)
print(type(os.stat("/"))) print(type(os.stat("/")))
# listdir and ilistdir # 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 # mkdir
os.mkdir(temp_dir) os.mkdir(temp_dir)