Skip to content

Commit ce7f65f

Browse files
agattidpgeorge
authored andcommitted
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 <[email protected]>
1 parent 898c04a commit ce7f65f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/extmod/vfs_posix.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,21 @@
2929
print(type(os.stat("/")))
3030

3131
# listdir and ilistdir
32-
print(type(os.listdir("/")))
32+
target = "/"
33+
try:
34+
import platform
35+
36+
# On Android non-root users are permitted full filesystem access only to
37+
# selected directories. To let this test pass on bionic, the internal
38+
# user-accessible storage area root is enumerated instead of the
39+
# filesystem root. "/storage/emulated/0" should be there on pretty much
40+
# any recent-ish device; querying the proper location requires a JNI
41+
# round-trip, not really worth it.
42+
if platform.platform().startswith("Android-"):
43+
target = "/storage/emulated/0"
44+
except ImportError:
45+
pass
46+
print(type(os.listdir(target)))
3347

3448
# mkdir
3549
os.mkdir(temp_dir)

0 commit comments

Comments
 (0)