Skip to content

Commit

Permalink
bpo-40280: Skip more tests/features that don't apply to Emscripten (G…
Browse files Browse the repository at this point in the history
…H-31791)

- fd inheritance can't be modified because Emscripten doesn't support subprocesses anyway.
- setpriority always fails
- geteuid no longer causes problems with latest emsdk
- umask is a stub
- geteuid / getuid always return 0, but process cannot chown to random uid.
  • Loading branch information
tiran authored Mar 10, 2022
1 parent 8714b6f commit de554d6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def requires_fork():
has_subprocess_support = not is_emscripten and not is_wasi

def requires_subprocess():
"""Used for subprocess, os.spawn calls"""
"""Used for subprocess, os.spawn calls, fd inheritance"""
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")


Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,7 @@ def test_write(self):
def test_writev(self):
self.check(os.writev, [b'abc'])

@support.requires_subprocess()
def test_inheritable(self):
self.check(os.get_inheritable)
self.check(os.set_inheritable, True)
Expand Down Expand Up @@ -3866,6 +3867,8 @@ def test_cpu_count(self):
self.skipTest("Could not determine the number of CPUs")


# FD inheritance check is only useful for systems with process support.
@support.requires_subprocess()
class FDInheritanceTests(unittest.TestCase):
def test_get_set_inheritable(self):
fd = os.open(__file__, os.O_RDONLY)
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from unittest import mock

from test.support import import_helper
from test.support import is_emscripten
from test.support import os_helper
from test.support.os_helper import TESTFN, FakePath

Expand Down Expand Up @@ -2158,6 +2159,7 @@ def test_mkdir_exist_ok_with_parent(self):
self.assertTrue(p.exists())
self.assertEqual(p.stat().st_ctime, st_ctime_first)

@unittest.skipIf(is_emscripten, "FS root cannot be modified on Emscripten.")
def test_mkdir_exist_ok_root(self):
# Issue #25803: A drive root could raise PermissionError on Windows.
self.cls('/').resolve().mkdir(exist_ok=True)
Expand Down Expand Up @@ -2342,6 +2344,9 @@ def test_is_socket_false(self):
self.assertIs((P / 'fileA\x00').is_socket(), False)

@unittest.skipUnless(hasattr(socket, "AF_UNIX"), "Unix sockets required")
@unittest.skipIf(
is_emscripten, "Unix sockets are not implemented on Emscripten."
)
def test_is_socket_true(self):
P = self.cls(BASE, 'mysock')
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
Expand Down Expand Up @@ -2497,6 +2502,9 @@ def _check_symlink_loop(self, *args, strict=True):
with self.assertRaises(RuntimeError):
print(path.resolve(strict))

@unittest.skipIf(
is_emscripten, "umask is not implemented on Emscripten."
)
def test_open_mode(self):
old_mask = os.umask(0)
self.addCleanup(os.umask, old_mask)
Expand All @@ -2520,6 +2528,9 @@ def test_resolve_root(self):
finally:
os.chdir(current_directory)

@unittest.skipIf(
is_emscripten, "umask is not implemented on Emscripten."
)
def test_touch_mode(self):
old_mask = os.umask(0)
self.addCleanup(os.umask, old_mask)
Expand Down
14 changes: 11 additions & 3 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
_DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
os_helper.TESTFN + '-dummy-symlink')

requires_32b = unittest.skipUnless(sys.maxsize < 2**32,
'test is only meaningful on 32-bit builds')
requires_32b = unittest.skipUnless(
# Emscripten has 32 bits pointers, but support 64 bits syscall args.
sys.maxsize < 2**32 and not support.is_emscripten,
'test is only meaningful on 32-bit builds'
)

def _supports_sched():
if not hasattr(posix, 'sched_getscheduler'):
Expand Down Expand Up @@ -578,6 +581,7 @@ def test_dup2(self):

@unittest.skipUnless(hasattr(os, 'O_CLOEXEC'), "needs os.O_CLOEXEC")
@support.requires_linux_version(2, 6, 23)
@support.requires_subprocess()
def test_oscloexec(self):
fd = os.open(os_helper.TESTFN, os.O_RDONLY|os.O_CLOEXEC)
self.addCleanup(os.close, fd)
Expand Down Expand Up @@ -737,7 +741,11 @@ def check_stat(uid, gid):
is_root = (uid in (0, 1))
else:
is_root = (uid == 0)
if is_root:
if support.is_emscripten:
# Emscripten getuid() / geteuid() always return 0 (root), but
# cannot chown uid/gid to random value.
pass
elif is_root:
# Try an amusingly large uid/gid to make sure we handle
# large unsigned values. (chown lets you use any
# uid/gid you like, even if they aren't defined.)
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,7 @@ def test_stream_padding(self):

@unittest.skipUnless(sys.platform != "win32" and hasattr(os, "umask"),
"Missing umask implementation")
@unittest.skipIf(support.is_emscripten, "Emscripten's umask is a stub.")
def test_file_mode(self):
# Test for issue #8464: Create files with correct
# permissions.
Expand Down
6 changes: 1 addition & 5 deletions Tools/wasm/config.site-wasm32-emscripten
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ac_cv_func_pwritev2=no
ac_cv_func_pwritev=no
ac_cv_func_pipe2=no
ac_cv_func_nice=no
ac_cv_func_setpriority=no
ac_cv_func_setitimer=no
# unsupported syscall: __syscall_prlimit64
ac_cv_func_prlimit=no
Expand Down Expand Up @@ -92,11 +93,6 @@ ac_cv_func_setgroups=no
ac_cv_func_setresuid=no
ac_cv_func_setresgid=no

# Emscripten geteuid() / getegid() always return 0 (root), which breaks
# assumption in tarfile module and some tests.
ac_cv_func_getegid=no
ac_cv_func_geteuid=no

# Emscripten does not support hard links, always fails with errno 34
# "Too many links". See emscripten_syscall_stubs.c
ac_cv_func_link=no
Expand Down

0 comments on commit de554d6

Please sign in to comment.