From de554d6e02228b840eb6bffaf7d406c0ef368d5f Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Thu, 10 Mar 2022 14:43:40 +0200 Subject: 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. --- Lib/test/support/__init__.py | 2 +- Lib/test/test_os.py | 3 +++ Lib/test/test_pathlib.py | 11 +++++++++++ Lib/test/test_posix.py | 14 +++++++++++--- Lib/test/test_tarfile.py | 1 + Tools/wasm/config.site-wasm32-emscripten | 6 +----- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index d80472d..865fb97 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -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") diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 4800291..ae8d930 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -2192,6 +2192,7 @@ class TestInvalidFD(unittest.TestCase): 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) @@ -3866,6 +3867,8 @@ class CPUCountTests(unittest.TestCase): 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) diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 713d279..66e4447 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -13,6 +13,7 @@ import unittest 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 @@ -2158,6 +2159,7 @@ class _BasePathTest(object): 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) @@ -2342,6 +2344,9 @@ class _BasePathTest(object): 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) @@ -2497,6 +2502,9 @@ class PosixPathTest(_BasePathTest, unittest.TestCase): 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) @@ -2520,6 +2528,9 @@ class PosixPathTest(_BasePathTest, unittest.TestCase): 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) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 395f065..c10039b 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -30,8 +30,11 @@ except ImportError: _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'): @@ -578,6 +581,7 @@ class PosixTester(unittest.TestCase): @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) @@ -737,7 +741,11 @@ class PosixTester(unittest.TestCase): 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.) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 0a67bcb..12850cd 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1498,6 +1498,7 @@ class StreamWriteTest(WriteTestBase, unittest.TestCase): @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. diff --git a/Tools/wasm/config.site-wasm32-emscripten b/Tools/wasm/config.site-wasm32-emscripten index f85024e..5eaa793 100644 --- a/Tools/wasm/config.site-wasm32-emscripten +++ b/Tools/wasm/config.site-wasm32-emscripten @@ -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 @@ -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 -- cgit v0.12