Commit Graph

559 Commits

Author SHA1 Message Date
sobolevn cc39b19f0f
gh-133167: Fix compilation process with `--enable-optimizations` and `--without-docstrings` (#133187) 2025-04-30 16:41:50 +03:00
Lysandros Nikolaou 60202609a2
gh-132661: Implement PEP 750 (#132662)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Wingy <git@wingysam.xyz>
Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
Co-authored-by: Dave Peck <davepeck@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Paul Everitt <pauleveritt@me.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
2025-04-30 11:46:41 +02:00
Chris Eibl 11f457cf41
GH-114911: use time.perf_counter in Stopwatch (GH-131469)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-04-28 13:55:08 +02:00
Bénédikt Tran 3695ba93d5
gh-132993: expose `HASHLIB_GIL_MINSIZE` to private extension modules (#132999) 2025-04-27 22:20:15 +00:00
Victor Stinner de6482eda3
gh-132415: Use shutil.which() in missing_compiler_executable() (#132906)
Replace deprecated distutils.spawn.find_executable() with
shutil.which() in missing_compiler_executable() of test.support.
2025-04-25 11:50:55 +02:00
Adam Turner c9f3f5b4ed
gh-132415: Update vendored setuptools in ``Lib/test/wheeldata`` (#132887) 2025-04-25 00:46:20 +01:00
John 862fd89036
gh-109981: Resolve situation on iOS regarding fd_count. (#132823)
Modifies the test helper that counts the list of open file descriptors to use
the optimised ``/dev/fd`` approach on all Apple platforms, not just macOS. This
avoids crashes caused by guarded file descriptors.
2025-04-23 03:22:57 +00:00
Jelle Zijlstra 39ee468e09
gh-118761: Add helper to ensure that lazy imports are actually lazy (#132614)
This ensures that if we jump through some hoops to make sure something is imported
lazily, we don't regress on importing it.

I recently already accidentally made typing import warnings and annotationlib eagerly.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-04-17 03:46:36 +00:00
sobolevn fcf2d07228
gh-132316: Require `socket` and `GITHUB_TOKEN` env to use `GitHubArtifactDatabase` (#132348)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-04-10 14:30:58 +03:00
Neil Schemenauer d687900f98
gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)
Make `warnings.catch_warnings()` use a context variable for holding
the warning filtering state if the `sys.flags.context_aware_warnings`
flag is set to true.  This makes using the context manager thread-safe in
multi-threaded programs.

Add the `sys.flags.thread_inherit_context` flag.  If true, starting a new
thread with `threading.Thread` will use a copy of the context
from the caller of `Thread.start()`.

Both these flags are set to true by default for the free-threaded build
and false for the default build.

Move the Python implementation of warnings.py into _py_warnings.py.

Make _contextvars a builtin module.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-04-09 16:18:54 -07:00
Jelle Zijlstra ac14d4a23f
gh-129463, gh-128593: Simplify ForwardRef (#129465) 2025-04-05 04:36:34 +00:00
Bénédikt Tran 0a97427ee5
gh-99108: Implement HACL* HMAC (#130157)
A new extension module, `_hmac`, now exposes the HACL* HMAC (formally verified) implementation.

The HACL* implementation is used as a fallback implementation when the OpenSSL implementation of HMAC
is not available or disabled. For now, only named hash algorithms are recognized and SIMD support provided
by HACL* for the BLAKE2 hash functions is not yet used.
2025-04-04 19:04:00 +02:00
Victor Stinner 643dd5107c
gh-111178: Skip test_perf_profiler on function sanitizer (#132020)
Add 'function' parameter to check_sanitizer() of test.support.
2025-04-02 18:46:10 +02:00
Thomas Grainger 8a00c9a4d2
gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings, and internal test warnings that are now logged (#128973)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-27 21:06:52 +02:00
R. David Murray 6146295a5b
gh-90548: Make musl test skips smarter (fixes Alpine errors) (#131313)
* Make musl test skips smarter (fixes Alpine errors)

A relatively small number of tests fail when the underlying c library is
provided by musl.  This was originally reported in bpo-46390 by
Christian Heimes.  Among other changes, these tests were marked for
skipping in gh-31947/ef1327e3 as part of bpo-40280 (emscripten support),
but the skips were conditioned on the *platform* being emscripten (or
wasi, skips for which ere added in 9b50585e02).

In gh-131071 Victor Stinner added a linked_to_musl function to enable
skipping a test in test_math that fails under musl, like it does on a
number of other platforms.  This check can successfully detect that
python is running under musl on Alpine, which was the original problem
report in bpo-46390.

This PR replaces Victor's solution with an enhancement to
platform.libc_ver that does the check more cheaply, and also gets the
version number.  The latter is important because the math test being
skipped is due to a bug in musl that has been fixed, but as of this
checkin date has not yet been released.  When it is, the test skip can
be fixed to check for the minimum needed version.

The enhanced version of linked_to_musl is also used to do the skips of
the other tests that generically fail under musl, as opposed to
emscripten or wasi only failures.  This will allow these tests to be
skipped automatically on Alpine.

This PR does *not* enhance libc_ver to support emscripten and wasi, as
I'm not familiar with those platforms; instead it returns a version
triple of (0, 0, 0) for those platforms.  This means the musl tests will
be skipped regardless of musl version, so ideally someone will add
support to libc_ver for these platforms.

* Platform tests and bug fixes.

In adding tests for the new platform code I found a bug in the old code:
if a valid version is passed for version and it is greater than the
version found for an so *and* there is no glibc version, then the
version from the argument was returned.  The code changes here fix
that.

* Add support docs, including for some preexisting is_xxx's.

* Add news item about libc_ver enhancement.

* Prettify platform re expression using re.VERBOSE.
2025-03-19 13:05:09 -04:00
Bénédikt Tran de8890f5ab
gh-130149: cleanup refactorization of `test_hmac.py` (#131318)
New features:

* refactor `hashlib_helper.requires_hashdigest` in prevision of a future
  `hashlib_helper.requires_builtin_hashdigest` for built-in hashes only
* add `hashlib_helper.requires_openssl_hashdigest` to request OpenSSL
   hashes, assuming that `_hashlib` exists.

Refactoring:

* split hmac.copy() test by implementation
* update how algorithms are discovered for RFC test cases
* simplify how OpenSSL hash digests are requested
* refactor hexdigest tests for RFC test vectors
* typo fix: `assert_hmac_hexdigest_by_new` -> `assert_hmac_hexdigest_by_name`

Improvements:

* strengthen contract on `hmac_new_by_name` and `hmac_digest_by_name`
* rename mixin classes to better match their responsibility
2025-03-17 11:10:03 +01:00
Bénédikt Tran 3185e3115c
gh-131277: allow `EnvironmentVarGuard` to unset more than one environment variable at once (#131280)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-03-16 14:09:33 +01:00
Victor Stinner 73ab9e2ede
gh-131152: Remove unused imports from tests (#131153) 2025-03-13 10:55:23 +01:00
Victor Stinner 68922ace4d
gh-131032: Add support.linked_to_musl() function (#131071)
Skip test_math.test_fma_zero_result() if Python is linked to the musl
C library.
2025-03-13 10:33:46 +01:00
Bénédikt Tran 8f11af45de
gh-130149: refactor tests for HMAC (#130150)
Since we plan to introduce a built-in implementation for HMAC based on HACL*,
it becomes important for the HMAC tests to be flexible enough to avoid code
duplication.

In addition to the new layout based on mixin classes, we extend test coverage by
also testing the `__repr__` of HMAC objects and the HMAC one-shot functions.

We also fix the import to `_sha256` which, since gh-101924, resulted in some tests being
skipped as the module is no more available (its content was moved to the `_sha2` module).
2025-03-03 11:22:05 +01:00
Mark Shannon 129db32d6f
GH-130396: Treat clang -Og as optimized for gdb tests (GH-130550) 2025-02-26 09:01:58 +00:00
Mark Shannon 014223649c
GH-130396: Use computed stack limits on linux (GH-130398)
* Implement C recursion protection with limit pointers for Linux, MacOS and Windows

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
2025-02-25 09:24:48 +00:00
Petr Viktorin ef29104f7d
GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now (GH130413)
Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now

Unfortunatlely, the change broke some buildbots.

This reverts commit 2498c22fa0.
2025-02-24 11:16:08 +01:00
Mark Shannon 2498c22fa0
GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)
* Implement C recursion protection with limit pointers

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
2025-02-19 11:44:57 +00:00
Sam Gross e5f10a7414
gh-127933: Add option to run regression tests in parallel (gh-128003)
This adds a new command line argument, `--parallel-threads` to the
regression test runner to allow it to run individual tests in multiple
threads in parallel in order to find multithreading bugs.

Some tests pass when run with `--parallel-threads`, but there's still
more work before the entire suite passes.
2025-02-04 17:44:59 -05:00
Brandt Bucher 674befbd7b
GH-129386: Add `test.support.reset_code` (GH-129486) 2025-01-31 11:50:54 +01:00
Filipe Laíns 🇵🇸 a4722449ca
tests: add test.support.venv.VirtualEnvironmentMixin (#129461) 2025-01-30 03:32:24 +00:00
Brandt Bucher 828b27680f
GH-126599: Remove the PyOptimizer API (GH-129194) 2025-01-28 16:10:51 -08:00
Alex Willmer a8dc6d6d44
gh-115911: Ignore PermissionError during import from cwd (#116131)
Ignore PermissionError when checking cwd during import

On macOS `getcwd(3)` can return EACCES if a path component isn't readable,
resulting in PermissionError. `PathFinder.find_spec()` now catches these and
ignores them - the same treatment as a missing/deleted cwd.

Introduces `test.support.os_helper.save_mode(path, ...)`, a context manager
that restores the mode of a path on exit.

This is allows finer control of exception handling and robust environment
restoration across platforms in `FinderTests.test_permission_error_cwd()`.

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Co-authored-by: Brett Cannon <brett@python.org>
2025-01-26 19:00:28 +00:00
Hugo van Kemenade 05d12eecbd
gh-127873: Only check `sys.flags.ignore_environment` for `PYTHON*` env vars (#127877) 2025-01-21 16:10:08 +00:00
Victor Stinner 8ceb6cb117
gh-129033: Remove _PyInterpreterState_SetConfig() function (#129048)
Remove _PyInterpreterState_GetConfigCopy() and
_PyInterpreterState_SetConfig() private functions. PEP 741 "Python
Configuration C API" added a better public C API: PyConfig_Get() and
PyConfig_Set().
2025-01-20 16:31:33 +01:00
Hugo van Kemenade 6f167d7134
gh-128595: Default to stdout isatty for colour detection instead of stderr (#128498)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-01-20 12:52:42 +02:00
Hugo van Kemenade afb9dc887c
gh-128595: Add test class helper to force no terminal colour (#128687)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2025-01-13 11:05:02 +00:00
Gregory P. Smith ffece5590e
gh-128192: mark new tests with skips based on hashlib algorithm availability (gh-128324)
Puts the _hashlib get_fips_mode logic check into test.support rather than spreading it out among other tests.
2024-12-28 22:32:32 -08:00
Thomas Grainger aab51c3414
gh-128265: Support WASI/Emscripten on PDB tests, by removing asyncio from pdb tests (#128264)
A part of `Lib/test/test_pdb.py` was previously unable to run on WASI/Emscripten
platforms because it lacked support for `asyncio`.
In fact, these tests could be rewritten without the `asyncio` framework because 
`test_pdb` tests the behavior of coroutines, which are not part of `asyncio`.

Now reliance on the availability of `asyncio` has been removed and
part of `test_pdb` that deals with coroutines working on WASI/Emscripten platforms.
2024-12-28 16:59:49 +02:00
Cody Maloney c0264fc57c
gh-127747: Resolve BytesWarning in test.support.strace_helper (#127849)
The strace_helper code has a _make_error function to simplify making
StraceResult objects in error cases. That takes a details parameter
which is either a caught OSError or `bytes`. If it's bytes, _make_error
would implicitly coerce that to a str inside of a f-string, resulting in
 a BytesWarning.

It's useful to see if it's an OSError or bytes when debugging, resolve
by changing to format with repr().

This is an error message on an internal helper.

A non-zero exit code occurs if the strace binary isn't found, and no
events will be parsed in that case (there is no output). Handle that
case by checking exit code before checking for events.

Still asserting around events rather than returning false, so that
hopefully if there's some change to `strace` that breaks the parsing,
will see that as a test failure rather than silently loosing strace
tests because they are auto-disabled.
2024-12-13 23:36:47 -08:00
Hood Chatham 43634fc1fc
gh-127146: Emscripten: Skip segfaults in test suite (#127151)
Added skips for tests known to cause problems when running on Emscripten. 
These mostly relate to the limited stack depth on Emscripten.
2024-12-05 08:26:25 +08:00
Cody Maloney 46f8a7bbdb
gh-127076: Ignore memory mmap in FileIO testing (#127088)
`mmap`, `munmap`, and `mprotect` are used by CPython for memory
management, which may occur in the middle of the FileIO tests. The
system calls can also be used with files, so `strace` includes them
in its `%file` and `%desc` filters.

Filter out the `mmap` system calls related to memory allocation for the
file tests. Currently FileIO doesn't do `mmap` at all, so didn't add
code to track from `mmap` through `munmap` since it wouldn't be used.
For now if an `mmap` on a fd happens, the call will be included (which
may cause test to fail), and at that time support for tracking the
address throug `munmap` could be added.
2024-11-22 15:55:32 +01:00
Cody Maloney ff2278e2bf
gh-127076: Disable strace tests under LD_PRELOAD (#127086)
Distribution tooling (ex. sandbox on Gentoo and fakeroot on Debian) uses
LD_PRELOAD to intercept system calls and potentially modify them when
building. These tools can change the set of system calls, so disable
system call testing under these cases.

Co-authored-by: Michał Górny <mgorny@gentoo.org>
2024-11-21 10:33:12 +01:00
Brandt Bucher 48c50ff1a2
GH-126892: Reset warmup counters when JIT compiling code (GH-126893) 2024-11-20 08:11:25 -08:00
Malcolm Smith c5c9286804
gh-118201: Simplify conv_confname (#126089) 2024-11-19 10:42:19 -05:00
Filipe Laíns 🇵🇸 acbd5c9c6c
GH-126789: fix some sysconfig data on late site initializations 2024-11-17 00:07:25 +00:00
Tomas R. dff074d144
gh-126413: Add translation tests for getopt and optparse (GH-126698) 2024-11-12 00:16:39 +02:00
mpage 2e95c5ba3b
gh-115999: Implement thread-local bytecode and enable specialization for `BINARY_OP` (#123926)
Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads.

Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization.

Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.
2024-11-04 11:13:32 -08:00
Cody Maloney 9ad57cf58b
gh-120754: Add a strace helper and test set of syscalls for open().read(), Take 2 (#123413) 2024-11-02 20:37:21 -07:00
Malcolm Smith c51b56038b
Android: Update tests for newly-available functions affected by SELinux (#126015)
Skip tests on Android that involve use of SELinux-protected methods.
2024-10-27 10:35:53 +08:00
Sam Gross 332356b880
gh-125900: Clean-up logic around immortalization in free-threading (#125901)
* Remove `@suppress_immortalization` decorator
* Make suppression flag per-thread instead of per-interpreter
* Suppress immortalization in `eval()` to avoid refleaks in three tests
  (test_datetime.test_roundtrip, test_logging.test_config8_ok, and
   test_random.test_after_fork).
* frozenset() is constant, but not a singleton. When run multiple times,
  the test could fail due to constant interning.
2024-10-24 18:09:59 -04:00
Petr Viktorin cc5a225cdc
gh-125041: test_zlib: For s390x HW acceleration, only skip checking the compressed bytes (#125042) 2024-10-15 11:29:43 +00:00
Erlend E. Aasland ce740d4624
gh-61698: Use launchctl to detect macOS window manager in tests (#118390) 2024-10-13 10:22:31 +02:00
Serhiy Storchaka 19984fe024
gh-53203: Improve tests for strptime() (GH-125090)
Run them with different locales and different date and time.

Add the @run_with_locales() decorator to run the test with multiple
locales.

Improve the run_with_locale() context manager/decorator -- it now
catches only expected exceptions and reports the test as skipped if no
appropriate locale is available.
2024-10-08 08:40:02 +00:00