Skip to content

Commit de554d6

Browse files
authored
bpo-40280: Skip more tests/features that don't apply to Emscripten (GH-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.
1 parent 8714b6f commit de554d6

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

Lib/test/support/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def requires_fork():
517517
has_subprocess_support = not is_emscripten and not is_wasi
518518

519519
def requires_subprocess():
520-
"""Used for subprocess, os.spawn calls"""
520+
"""Used for subprocess, os.spawn calls, fd inheritance"""
521521
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
522522

523523

Lib/test/test_os.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,7 @@ def test_write(self):
21922192
def test_writev(self):
21932193
self.check(os.writev, [b'abc'])
21942194

2195+
@support.requires_subprocess()
21952196
def test_inheritable(self):
21962197
self.check(os.get_inheritable)
21972198
self.check(os.set_inheritable, True)
@@ -3866,6 +3867,8 @@ def test_cpu_count(self):
38663867
self.skipTest("Could not determine the number of CPUs")
38673868

38683869

3870+
# FD inheritance check is only useful for systems with process support.
3871+
@support.requires_subprocess()
38693872
class FDInheritanceTests(unittest.TestCase):
38703873
def test_get_set_inheritable(self):
38713874
fd = os.open(__file__, os.O_RDONLY)

Lib/test/test_pathlib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from unittest import mock
1414

1515
from test.support import import_helper
16+
from test.support import is_emscripten
1617
from test.support import os_helper
1718
from test.support.os_helper import TESTFN, FakePath
1819

@@ -2158,6 +2159,7 @@ def test_mkdir_exist_ok_with_parent(self):
21582159
self.assertTrue(p.exists())
21592160
self.assertEqual(p.stat().st_ctime, st_ctime_first)
21602161

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

23442346
@unittest.skipUnless(hasattr(socket, "AF_UNIX"), "Unix sockets required")
2347+
@unittest.skipIf(
2348+
is_emscripten, "Unix sockets are not implemented on Emscripten."
2349+
)
23452350
def test_is_socket_true(self):
23462351
P = self.cls(BASE, 'mysock')
23472352
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -2497,6 +2502,9 @@ def _check_symlink_loop(self, *args, strict=True):
24972502
with self.assertRaises(RuntimeError):
24982503
print(path.resolve(strict))
24992504

2505+
@unittest.skipIf(
2506+
is_emscripten, "umask is not implemented on Emscripten."
2507+
)
25002508
def test_open_mode(self):
25012509
old_mask = os.umask(0)
25022510
self.addCleanup(os.umask, old_mask)
@@ -2520,6 +2528,9 @@ def test_resolve_root(self):
25202528
finally:
25212529
os.chdir(current_directory)
25222530

2531+
@unittest.skipIf(
2532+
is_emscripten, "umask is not implemented on Emscripten."
2533+
)
25232534
def test_touch_mode(self):
25242535
old_mask = os.umask(0)
25252536
self.addCleanup(os.umask, old_mask)

Lib/test/test_posix.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@
3030
_DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
3131
os_helper.TESTFN + '-dummy-symlink')
3232

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

3639
def _supports_sched():
3740
if not hasattr(posix, 'sched_getscheduler'):
@@ -578,6 +581,7 @@ def test_dup2(self):
578581

579582
@unittest.skipUnless(hasattr(os, 'O_CLOEXEC'), "needs os.O_CLOEXEC")
580583
@support.requires_linux_version(2, 6, 23)
584+
@support.requires_subprocess()
581585
def test_oscloexec(self):
582586
fd = os.open(os_helper.TESTFN, os.O_RDONLY|os.O_CLOEXEC)
583587
self.addCleanup(os.close, fd)
@@ -737,7 +741,11 @@ def check_stat(uid, gid):
737741
is_root = (uid in (0, 1))
738742
else:
739743
is_root = (uid == 0)
740-
if is_root:
744+
if support.is_emscripten:
745+
# Emscripten getuid() / geteuid() always return 0 (root), but
746+
# cannot chown uid/gid to random value.
747+
pass
748+
elif is_root:
741749
# Try an amusingly large uid/gid to make sure we handle
742750
# large unsigned values. (chown lets you use any
743751
# uid/gid you like, even if they aren't defined.)

Lib/test/test_tarfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ def test_stream_padding(self):
14981498

14991499
@unittest.skipUnless(sys.platform != "win32" and hasattr(os, "umask"),
15001500
"Missing umask implementation")
1501+
@unittest.skipIf(support.is_emscripten, "Emscripten's umask is a stub.")
15011502
def test_file_mode(self):
15021503
# Test for issue #8464: Create files with correct
15031504
# permissions.

Tools/wasm/config.site-wasm32-emscripten

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ac_cv_func_pwritev2=no
6262
ac_cv_func_pwritev=no
6363
ac_cv_func_pipe2=no
6464
ac_cv_func_nice=no
65+
ac_cv_func_setpriority=no
6566
ac_cv_func_setitimer=no
6667
# unsupported syscall: __syscall_prlimit64
6768
ac_cv_func_prlimit=no
@@ -92,11 +93,6 @@ ac_cv_func_setgroups=no
9293
ac_cv_func_setresuid=no
9394
ac_cv_func_setresgid=no
9495

95-
# Emscripten geteuid() / getegid() always return 0 (root), which breaks
96-
# assumption in tarfile module and some tests.
97-
ac_cv_func_getegid=no
98-
ac_cv_func_geteuid=no
99-
10096
# Emscripten does not support hard links, always fails with errno 34
10197
# "Too many links". See emscripten_syscall_stubs.c
10298
ac_cv_func_link=no

0 commit comments

Comments
 (0)