8000 gh-90473: Decrease recursion limit and skip tests on WASI (GH-92803) by tiran · Pull Request #92803 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90473: Decrease recursion limit and skip tests on WASI (GH-92803) #92803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-90473: Decrease recursion limit and skip tests on WASI
Reduce recursion limit to 750. WASI has limited call stack.

Mark tests that require mmap, os.pipe, or fail on musl libc.
  • Loading branch information
tiran committed May 18, 2022
commit 1f769f66efe92e88e326bca463ed870314c24aa7
8 changes: 7 additions & 1 deletion Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ extern "C" {
struct pyruntimestate;
struct _ceval_runtime_state;

/* WASI has limited call stack. wasmtime 0.36 can handle sufficient amount of
C stack frames for little more than 750 recursions. */
#ifndef Py_DEFAULT_RECURSION_LIMIT
# define Py_DEFAULT_RECURSION_LIMIT 1000
# ifdef __wasi__
# define Py_DEFAULT_RECURSION_LIMIT 750
# else
# define Py_DEFAULT_RECURSION_LIMIT 1000
# endif
#endif

#include "pycore_interp.h" // PyInterpreterState.eval_frame
Expand Down
4 changes: 4 additions & 0 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):

executable = sys.executable

if not executable:
# sys.executable is not set.
return lib, version

V = _comparable_version
# We use os.path.realpath()
# here to work around problems with Cygwin not being
Expand Down
10 changes: 8 additions & 2 deletions Lib/test/pythoninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,14 @@ def format_attr(attr, value):
def collect_socket(info_add):
import socket

hostname = socket.gethostname()
info_add('socket.hostname', hostname)
try:
hostname = socket.gethostname()
except OSError:
# WASI SDK 15.0 does not have gethostname(2).
if sys.platform != "wasi":
raise
else:
info_add('socket.hostname', hostname)


def collect_sqlite(info_add):
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def __getitem__(self, key):
self.assertEqual(d['z'], 12)

def test_extended_arg(self):
longexpr = 'x = x or ' + '-x' * 2500
# default: 1000 * 2.5 = 2500 repetitions
repeat = int(sys.getrecursionlimit() * 2.5)
longexpr = 'x = x or ' + '-x' * repeat
g = {}
code = '''
def f(x):
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from weakref import proxy
from functools import wraps

from test.support import cpython_only, swap_attr, gc_collect, is_emscripten
from test.support import (
cpython_only, swap_attr, gc_collect, is_emscripten, is_wasi
)
from test.support.os_helper import (TESTFN, TESTFN_UNICODE, make_bad_fd)
from test.support.warnings_helper import check_warnings
from collections import UserList
Expand Down Expand Up @@ -65,6 +67,7 @@ def testAttributes(self):
self.assertRaises((AttributeError, TypeError),
setattr, f, attr, 'oops')

@unittest.skipIf(is_wasi, "WASI does not expose st_blksize.")
def testBlksize(self):
# test private _blksize attribute
blksize = io.DEFAULT_BUFFER_SIZE
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_largefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def test_seekable(self):
def skip_no_disk_space(path, required):
def decorator(fun):
def wrapper(*args, **kwargs):
if not hasattr(shutil, "disg_usage"):
raise unittest.SkipTest("requires shutil.disk_usage")
if shutil.disk_usage(os.path.realpath(path)).free < required:
hsize = int(required / 1024 / 1024)
raise unittest.SkipTest(
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5280,6 +5280,7 @@ def test_emit_after_closing_in_write_mode(self):
self.assertEqual(fp.read().strip(), '1')

class RotatingFileHandlerTest(BaseFileTest):
@unittest.skipIf(support.is_wasi, "WASI does not have /dev/null.")
def test_should_not_rollover(self):
# If maxbytes is zero rollover never occurs
rh = logging.handlers.RotatingFileHandler(
Expand Down Expand Up @@ -5387,6 +5388,7 @@ def rotator(source, dest):
rh.close()

class TimedRotatingFileHandlerTest(BaseFileTest):
@unittest.skipIf(support.is_wasi, "WASI does not have /dev/null.")
def test_should_not_rollover(self):
# See bpo-45401. Should only ever rollover regular files
fh = logging.handlers.TimedRotatingFileHandler(
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import fractions
import itertools
import locale
import mmap
import os
import pickle
import select
Expand Down Expand Up @@ -59,6 +58,10 @@
except ImportError:
INT_MAX = PY_SSIZE_T_MAX = sys.maxsize

try:
import mmap
except ImportError:
mmap = None

from test.support.script_helper import assert_python_ok
from test.support import unix_shell
Expand Down Expand Up @@ -2460,6 +2463,7 @@ def test_kill_int(self):
# os.kill on Windows can take an int which gets set as the exit code
self._kill(100)

@unittest.skipIf(mmap is None, "requires mmap")
def _kill_with_event(self, event, name):
tagname = "test_os_%s" % uuid.uuid1()
m = mmap.mmap(-1, 1, tagname)
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def test_interprocess_signal(self):
script = os.path.join(dirname, 'signalinterproctester.py')
assert_python_ok(script)

@unittest.skipUnless(
hasattr(signal, "valid_signals"),
"requires signal.valid_signals"
)
def test_valid_signals(self):
s = signal.valid_signals()
self.assertIsInstance(s, set)
Expand Down Expand Up @@ -212,6 +216,7 @@ def test_invalid_fd(self):
self.assertRaises((ValueError, OSError),
signal.set_wakeup_fd, fd)

@unittest.skipUnless(support.has_socket_support, "needs working sockets.")
def test_invalid_socket(self):
sock = socket.socket()
fd = sock.fileno()
Expand Down Expand Up @@ -241,6 +246,7 @@ def test_set_wakeup_fd_result(self):
self.assertEqual(signal.set_wakeup_fd(-1), -1)

@unittest.skipIf(support.is_emscripten, "Emscripten cannot fstat pipes.")
@unittest.skipUnless(support.has_socket_support, "needs working sockets.")
def test_set_wakeup_fd_socket_result(self):
sock1 = socket.socket()
self.addCleanup(sock1.close)
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,7 @@ def test_syntax_error_on_deeply_nested_blocks(self):
self._check_error(source, "too many statically nested blocks")

@support.cpython_only
@unittest.skipIf(support.is_wasi, "Exhausts WASI call stack")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way we could tweak the test to get the same coverage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to make the test pass with a smaller parser MAXSTACK value on WASI.

CC @pablogsal

def test_error_on_parser_stack_overflow(self):
source = "-" * 100000 + "4"
for mode in ["exec", "eval", "single"]:
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ def testEmptyFile(self):
os_helper.create_empty_file(TESTMOD)
self.assertZipFailure(TESTMOD)

@unittest.skipIf(support.is_wasi, "mode 000 not supported.")
def testFileUnreadable(self):
os_helper.unlink(TESTMOD)
fd = os.open(TESTMOD, os.O_CREAT, 000)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Decrease default recursion limit on WASI to address limited call stack size.
2 changes: 1 addition & 1 deletion Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)

#elif defined(HAVE_CLOCK_GETTIME) && \
defined(CLOCK_PROCESS_CPUTIME_ID) && \
!defined(__EMSCRIPTEN__)
!defined(__EMSCRIPTEN__) && !defined(__wasi__)
#define HAVE_THREAD_TIME

#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)
Expand Down
15 changes: 15 additions & 0 deletions Tools/wasm/config.site-wasm32-wasi
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ ac_cv_header_sys_resource_h=no

# undefined symbols / unsupported features
ac_cv_func_eventfd=no

# WASI SDK 15.0 has no pipe syscall
ac_cv_func_pipe=no

# fdopendir() fails on SDK 15.0
# OSError: [Errno 28] Invalid argument: '.'
ac_cv_func_fdopendir=no

# WASIX stubs we don't want to use.
ac_cv_func_kill=no

# WASI sockets are limited to operations on given socket fd and inet sockets.
# Disable AF_UNIX and AF_PACKET support, see socketmodule.h.
ac_cv_header_sys_un_h=no
ac_cv_header_netpacket_packet_h=no
1 change: 1 addition & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6690,8 +6690,10 @@ AS_CASE([$ac_sys_system],
],
[Emscripten/node*], [],
[WASI/*], [
dnl WASI SDK 15.0 does not support file locking.
PY_STDLIB_MOD_SET_NA(
[_ctypes_test],
[fcntl],
)
]
)
Expand Down
0