[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
import dataclasses
|
2016-03-23 02:04:32 +01:00
|
|
|
import faulthandler
|
2015-09-29 23:15:38 +02:00
|
|
|
import json
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
import os.path
|
2015-09-30 03:05:43 +02:00
|
|
|
import queue
|
2019-10-18 15:49:08 +02:00
|
|
|
import signal
|
2019-04-26 08:40:25 +02:00
|
|
|
import subprocess
|
2015-09-29 23:15:38 +02:00
|
|
|
import sys
|
2022-06-29 13:51:25 +02:00
|
|
|
import tempfile
|
2017-09-07 18:56:24 +02:00
|
|
|
import threading
|
2015-09-30 00:33:29 +02:00
|
|
|
import time
|
2019-04-26 08:40:25 +02:00
|
|
|
import traceback
|
2022-06-29 13:51:25 +02:00
|
|
|
from typing import NamedTuple, NoReturn, Literal, Any, TextIO
|
2021-07-22 20:25:58 +02:00
|
|
|
|
2015-09-29 23:15:38 +02:00
|
|
|
from test import support
|
2020-06-30 21:46:06 +08:00
|
|
|
from test.support import os_helper
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
from test.support import TestStats
|
2015-09-29 23:15:38 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
from test.libregrtest.cmdline import Namespace
|
|
|
|
|
from test.libregrtest.main import Regrtest
|
2016-03-23 12:14:10 +01:00
|
|
|
from test.libregrtest.runtest import (
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
runtest, TestResult, State,
|
|
|
|
|
PROGRESS_MIN_TIME)
|
2015-09-30 02:17:28 +02:00
|
|
|
from test.libregrtest.setup import setup_tests
|
2019-10-01 12:29:36 +02:00
|
|
|
from test.libregrtest.utils import format_duration, print_warning
|
2015-09-29 23:15:38 +02:00
|
|
|
|
2022-10-21 07:52:17 -07:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
|
import locale
|
|
|
|
|
|
2015-09-29 23:15:38 +02:00
|
|
|
|
2015-09-30 03:05:43 +02:00
|
|
|
# Display the running tests if nothing happened last N seconds
|
2015-11-04 09:03:53 +01:00
|
|
|
PROGRESS_UPDATE = 30.0 # seconds
|
2019-09-17 10:08:19 +02:00
|
|
|
assert PROGRESS_UPDATE >= PROGRESS_MIN_TIME
|
2015-09-30 03:05:43 +02:00
|
|
|
|
2019-10-08 18:45:43 +02:00
|
|
|
# Kill the main process after 5 minutes. It is supposed to write an update
|
|
|
|
|
# every PROGRESS_UPDATE seconds. Tolerate 5 minutes for Python slowest
|
|
|
|
|
# buildbot workers.
|
|
|
|
|
MAIN_PROCESS_TIMEOUT = 5 * 60.0
|
|
|
|
|
assert MAIN_PROCESS_TIMEOUT >= PROGRESS_UPDATE
|
|
|
|
|
|
2019-05-14 03:47:32 +02:00
|
|
|
# Time to wait until a worker completes: should be immediate
|
|
|
|
|
JOIN_TIMEOUT = 30.0 # seconds
|
|
|
|
|
|
2019-10-18 15:49:08 +02:00
|
|
|
USE_PROCESS_GROUP = (hasattr(os, "setsid") and hasattr(os, "killpg"))
|
|
|
|
|
|
2016-03-24 12:04:15 +01:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def must_stop(result: TestResult, ns: Namespace) -> bool:
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
if result.state == State.INTERRUPTED:
|
2019-05-13 19:17:54 +02:00
|
|
|
return True
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
if ns.failfast and result.is_failed(ns.fail_env_changed):
|
2019-05-13 19:17:54 +02:00
|
|
|
return True
|
|
|
|
|
return False
|
2015-09-30 00:33:29 +02:00
|
|
|
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def parse_worker_args(worker_args) -> tuple[Namespace, str]:
|
2019-05-14 15:49:16 +02:00
|
|
|
ns_dict, test_name = json.loads(worker_args)
|
2021-07-22 20:25:58 +02:00
|
|
|
ns = Namespace(**ns_dict)
|
2019-05-14 15:49:16 +02:00
|
|
|
return (ns, test_name)
|
|
|
|
|
|
|
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
def run_test_in_subprocess(testname: str, ns: Namespace, tmp_dir: str, stdout_fh: TextIO) -> subprocess.Popen:
|
2015-09-30 01:32:39 +02:00
|
|
|
ns_dict = vars(ns)
|
2018-09-07 17:20:42 +02:00
|
|
|
worker_args = (ns_dict, testname)
|
|
|
|
|
worker_args = json.dumps(worker_args)
|
2022-05-02 15:51:34 -07:00
|
|
|
if ns.python is not None:
|
2022-06-21 06:07:26 -07:00
|
|
|
executable = ns.python
|
2022-05-02 15:51:34 -07:00
|
|
|
else:
|
|
|
|
|
executable = [sys.executable]
|
|
|
|
|
cmd = [*executable, *support.args_from_interpreter_flags(),
|
2016-09-21 17:12:50 +02:00
|
|
|
'-u', # Unbuffered stdout and stderr
|
2015-09-30 00:33:29 +02:00
|
|
|
'-m', 'test.regrtest',
|
2018-09-07 17:20:42 +02:00
|
|
|
'--worker-args', worker_args]
|
2015-09-30 00:33:29 +02:00
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
env = dict(os.environ)
|
|
|
|
|
if tmp_dir is not None:
|
|
|
|
|
env['TMPDIR'] = tmp_dir
|
|
|
|
|
env['TEMP'] = tmp_dir
|
|
|
|
|
env['TMP'] = tmp_dir
|
|
|
|
|
|
2015-09-29 23:15:38 +02:00
|
|
|
# Running the child from the same working directory as regrtest's original
|
|
|
|
|
# invocation ensures that TEMPDIR for the child is the same when
|
|
|
|
|
# sysconfig.is_python_build() is true. See issue 15300.
|
2022-06-29 13:51:25 +02:00
|
|
|
kw = dict(
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
env=env,
|
2022-06-29 13:51:25 +02:00
|
|
|
stdout=stdout_fh,
|
|
|
|
|
# bpo-45410: Write stderr into stdout to keep messages order
|
|
|
|
|
stderr=stdout_fh,
|
|
|
|
|
text=True,
|
|
|
|
|
close_fds=(os.name != 'nt'),
|
|
|
|
|
cwd=os_helper.SAVEDCWD,
|
|
|
|
|
)
|
2019-10-18 15:49:08 +02:00
|
|
|
if USE_PROCESS_GROUP:
|
|
|
|
|
kw['start_new_session'] = True
|
2022-06-29 13:51:25 +02:00
|
|
|
return subprocess.Popen(cmd, **kw)
|
2015-09-29 23:15:38 +02:00
|
|
|
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def run_tests_worker(ns: Namespace, test_name: str) -> NoReturn:
|
2015-09-30 02:17:28 +02:00
|
|
|
setup_tests(ns)
|
2015-09-30 01:32:39 +02:00
|
|
|
|
2019-05-14 15:49:16 +02:00
|
|
|
result = runtest(ns, test_name)
|
|
|
|
|
|
2015-09-29 23:15:38 +02:00
|
|
|
print() # Force a newline (just in case)
|
2019-05-14 15:49:16 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
# Serialize TestResult as dict in JSON
|
|
|
|
|
print(json.dumps(result, cls=EncodeTestResult), flush=True)
|
2015-09-29 23:15:38 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# We do not use a generator so multiple threads can call next().
|
|
|
|
|
class MultiprocessIterator:
|
|
|
|
|
|
|
|
|
|
"""A thread-safe iterator over tests for multiprocess mode."""
|
|
|
|
|
|
2019-05-13 19:17:54 +02:00
|
|
|
def __init__(self, tests_iter):
|
2015-09-29 23:15:38 +02:00
|
|
|
self.lock = threading.Lock()
|
2019-05-13 19:17:54 +02:00
|
|
|
self.tests_iter = tests_iter
|
2015-09-29 23:15:38 +02:00
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
def __next__(self):
|
|
|
|
|
with self.lock:
|
2019-05-13 19:17:54 +02:00
|
|
|
if self.tests_iter is None:
|
|
|
|
|
raise StopIteration
|
|
|
|
|
return next(self.tests_iter)
|
|
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
|
with self.lock:
|
|
|
|
|
self.tests_iter = None
|
2015-09-29 23:15:38 +02:00
|
|
|
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
class MultiprocessResult(NamedTuple):
|
|
|
|
|
result: TestResult
|
2021-10-08 17:14:37 +02:00
|
|
|
# bpo-45410: stderr is written into stdout to keep messages order
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
worker_stdout: str | None = None
|
|
|
|
|
err_msg: str | None = None
|
2021-07-22 20:25:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
ExcStr = str
|
|
|
|
|
QueueOutput = tuple[Literal[False], MultiprocessResult] | tuple[Literal[True], ExcStr]
|
|
|
|
|
|
2019-04-26 04:08:53 +02:00
|
|
|
|
2019-05-14 03:47:32 +02:00
|
|
|
class ExitThread(Exception):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2019-10-01 12:29:36 +02:00
|
|
|
class TestWorkerProcess(threading.Thread):
|
2021-07-22 20:25:58 +02:00
|
|
|
def __init__(self, worker_id: int, runner: "MultiprocessTestRunner") -> None:
|
2015-09-29 23:15:38 +02:00
|
|
|
super().__init__()
|
2019-10-01 12:29:36 +02:00
|
|
|
self.worker_id = worker_id
|
2019-10-03 16:15:16 +02:00
|
|
|
self.pending = runner.pending
|
|
|
|
|
self.output = runner.output
|
|
|
|
|
self.ns = runner.ns
|
|
|
|
|
self.timeout = runner.worker_timeout
|
|
|
|
|
self.regrtest = runner.regrtest
|
2019-04-26 04:08:53 +02:00
|
|
|
self.current_test_name = None
|
2015-09-30 00:33:29 +02:00
|
|
|
self.start_time = None
|
2019-04-26 08:40:25 +02:00
|
|
|
self._popen = None
|
2019-05-14 03:47:32 +02:00
|
|
|
self._killed = False
|
2019-10-01 12:29:36 +02:00
|
|
|
self._stopped = False
|
2019-05-14 03:47:32 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def __repr__(self) -> str:
|
2019-10-01 12:29:36 +02:00
|
|
|
info = [f'TestWorkerProcess #{self.worker_id}']
|
2019-05-14 03:47:32 +02:00
|
|
|
if self.is_alive():
|
2019-10-02 13:35:11 +02:00
|
|
|
info.append("running")
|
2019-10-01 12:29:36 +02:00
|
|
|
else:
|
|
|
|
|
info.append('stopped')
|
|
|
|
|
test = self.current_test_name
|
2019-05-14 03:47:32 +02:00
|
|
|
if test:
|
|
|
|
|
info.append(f'test={test}')
|
|
|
|
|
popen = self._popen
|
2019-10-02 13:35:11 +02:00
|
|
|
if popen is not None:
|
|
|
|
|
dt = time.monotonic() - self.start_time
|
|
|
|
|
info.extend((f'pid={self._popen.pid}',
|
|
|
|
|
f'time={format_duration(dt)}'))
|
2019-05-14 03:47:32 +02:00
|
|
|
return '<%s>' % ' '.join(info)
|
2015-09-30 00:33:29 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def _kill(self) -> None:
|
2019-08-21 10:59:20 +01:00
|
|
|
popen = self._popen
|
2019-10-01 12:29:36 +02:00
|
|
|
if popen is None:
|
|
|
|
|
return
|
2019-08-21 10:59:20 +01:00
|
|
|
|
2019-10-02 13:35:11 +02:00
|
|
|
if self._killed:
|
|
|
|
|
return
|
|
|
|
|
self._killed = True
|
|
|
|
|
|
2019-10-18 15:49:08 +02:00
|
|
|
if USE_PROCESS_GROUP:
|
|
|
|
|
what = f"{self} process group"
|
|
|
|
|
else:
|
|
|
|
|
what = f"{self}"
|
|
|
|
|
|
|
|
|
|
print(f"Kill {what}", file=sys.stderr, flush=True)
|
2019-08-21 10:59:20 +01:00
|
|
|
try:
|
2019-10-18 15:49:08 +02:00
|
|
|
if USE_PROCESS_GROUP:
|
|
|
|
|
os.killpg(popen.pid, signal.SIGKILL)
|
|
|
|
|
else:
|
|
|
|
|
popen.kill()
|
2019-10-17 00:29:12 +02:00
|
|
|
except ProcessLookupError:
|
2019-10-18 15:49:08 +02:00
|
|
|
# popen.kill(): the process completed, the TestWorkerProcess thread
|
|
|
|
|
# read its exit status, but Popen.send_signal() read the returncode
|
|
|
|
|
# just before Popen.wait() set returncode.
|
2019-10-17 00:29:12 +02:00
|
|
|
pass
|
2019-08-21 10:59:20 +01:00
|
|
|
except OSError as exc:
|
2019-10-18 15:49:08 +02:00
|
|
|
print_warning(f"Failed to kill {what}: {exc!r}")
|
2019-08-21 10:59:20 +01:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def stop(self) -> None:
|
2019-10-01 12:29:36 +02:00
|
|
|
# Method called from a different thread to stop this thread
|
|
|
|
|
self._stopped = True
|
|
|
|
|
self._kill()
|
2019-08-14 14:18:51 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def mp_result_error(
|
|
|
|
|
self,
|
|
|
|
|
test_result: TestResult,
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
stdout: str | None = None,
|
2021-07-22 20:25:58 +02:00
|
|
|
err_msg=None
|
|
|
|
|
) -> MultiprocessResult:
|
2021-10-08 17:14:37 +02:00
|
|
|
return MultiprocessResult(test_result, stdout, err_msg)
|
2021-07-22 20:25:58 +02:00
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
def _run_process(self, test_name: str, tmp_dir: str, stdout_fh: TextIO) -> int:
|
2019-10-01 12:29:36 +02:00
|
|
|
self.current_test_name = test_name
|
|
|
|
|
try:
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
popen = run_test_in_subprocess(test_name, self.ns, tmp_dir, stdout_fh)
|
2019-10-02 13:35:11 +02:00
|
|
|
|
2019-10-01 12:29:36 +02:00
|
|
|
self._killed = False
|
2019-10-02 13:35:11 +02:00
|
|
|
self._popen = popen
|
2019-10-01 12:29:36 +02:00
|
|
|
except:
|
|
|
|
|
self.current_test_name = None
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if self._stopped:
|
|
|
|
|
# If kill() has been called before self._popen is set,
|
|
|
|
|
# self._popen is still running. Call again kill()
|
|
|
|
|
# to ensure that the process is killed.
|
|
|
|
|
self._kill()
|
|
|
|
|
raise ExitThread
|
|
|
|
|
|
2019-08-21 10:59:20 +01:00
|
|
|
try:
|
2022-06-29 13:51:25 +02:00
|
|
|
# gh-94026: stdout+stderr are written to tempfile
|
|
|
|
|
retcode = popen.wait(timeout=self.timeout)
|
2019-10-08 18:45:43 +02:00
|
|
|
assert retcode is not None
|
2022-06-29 13:51:25 +02:00
|
|
|
return retcode
|
2019-10-01 12:29:36 +02:00
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
|
if self._stopped:
|
2021-10-08 17:14:37 +02:00
|
|
|
# kill() has been called: communicate() fails on reading
|
|
|
|
|
# closed stdout
|
2019-10-01 12:29:36 +02:00
|
|
|
raise ExitThread
|
|
|
|
|
|
2019-10-08 18:45:43 +02:00
|
|
|
# On timeout, kill the process
|
|
|
|
|
self._kill()
|
|
|
|
|
|
|
|
|
|
# None means TIMEOUT for the caller
|
|
|
|
|
retcode = None
|
|
|
|
|
# bpo-38207: Don't attempt to call communicate() again: on it
|
2021-10-08 17:14:37 +02:00
|
|
|
# can hang until all child processes using stdout
|
2019-10-08 18:45:43 +02:00
|
|
|
# pipes completes.
|
2019-10-01 12:29:36 +02:00
|
|
|
except OSError:
|
|
|
|
|
if self._stopped:
|
|
|
|
|
# kill() has been called: communicate() fails
|
2021-10-08 17:14:37 +02:00
|
|
|
# on reading closed stdout
|
2019-10-01 12:29:36 +02:00
|
|
|
raise ExitThread
|
|
|
|
|
raise
|
|
|
|
|
except:
|
|
|
|
|
self._kill()
|
|
|
|
|
raise
|
2015-09-30 00:33:29 +02:00
|
|
|
finally:
|
2019-10-01 12:29:36 +02:00
|
|
|
self._wait_completed()
|
2019-04-26 08:40:25 +02:00
|
|
|
self._popen = None
|
2019-10-01 12:29:36 +02:00
|
|
|
self.current_test_name = None
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def _runtest(self, test_name: str) -> MultiprocessResult:
|
2022-10-21 07:52:17 -07:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
|
# gh-95027: When stdout is not a TTY, Python uses the ANSI code
|
|
|
|
|
# page for the sys.stdout encoding. If the main process runs in a
|
|
|
|
|
# terminal, sys.stdout uses WindowsConsoleIO with UTF-8 encoding.
|
|
|
|
|
encoding = locale.getencoding()
|
|
|
|
|
else:
|
|
|
|
|
encoding = sys.stdout.encoding
|
2023-06-28 04:58:34 +02:00
|
|
|
|
2022-06-29 13:51:25 +02:00
|
|
|
# gh-94026: Write stdout+stderr to a tempfile as workaround for
|
|
|
|
|
# non-blocking pipes on Emscripten with NodeJS.
|
2022-10-21 07:52:17 -07:00
|
|
|
with tempfile.TemporaryFile('w+', encoding=encoding) as stdout_fh:
|
2022-06-29 13:51:25 +02:00
|
|
|
# gh-93353: Check for leaked temporary files in the parent process,
|
|
|
|
|
# since the deletion of temporary files can happen late during
|
|
|
|
|
# Python finalization: too late for libregrtest.
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
if not support.is_wasi:
|
|
|
|
|
# Don't check for leaked temporary files and directories if Python is
|
|
|
|
|
# run on WASI. WASI don't pass environment variables like TMPDIR to
|
|
|
|
|
# worker processes.
|
|
|
|
|
tmp_dir = tempfile.mkdtemp(prefix="test_python_")
|
|
|
|
|
tmp_dir = os.path.abspath(tmp_dir)
|
|
|
|
|
try:
|
|
|
|
|
retcode = self._run_process(test_name, tmp_dir, stdout_fh)
|
|
|
|
|
finally:
|
|
|
|
|
tmp_files = os.listdir(tmp_dir)
|
|
|
|
|
os_helper.rmtree(tmp_dir)
|
|
|
|
|
else:
|
|
|
|
|
retcode = self._run_process(test_name, None, stdout_fh)
|
|
|
|
|
tmp_files = ()
|
2022-06-29 13:51:25 +02:00
|
|
|
stdout_fh.seek(0)
|
2023-06-28 04:58:34 +02:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
stdout = stdout_fh.read().strip()
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
# gh-101634: Catch UnicodeDecodeError if stdout cannot be
|
|
|
|
|
# decoded from encoding
|
|
|
|
|
err_msg = f"Cannot read process stdout: {exc}"
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
result = TestResult(test_name, state=State.MULTIPROCESSING_ERROR)
|
|
|
|
|
return self.mp_result_error(result, err_msg=err_msg)
|
2019-10-01 12:29:36 +02:00
|
|
|
|
2019-10-08 18:45:43 +02:00
|
|
|
if retcode is None:
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
result = TestResult(test_name, state=State.TIMEOUT)
|
|
|
|
|
return self.mp_result_error(result, stdout)
|
2015-09-30 00:33:29 +02:00
|
|
|
|
2019-04-26 08:40:25 +02:00
|
|
|
err_msg = None
|
2015-09-30 00:33:29 +02:00
|
|
|
if retcode != 0:
|
2019-04-26 08:40:25 +02:00
|
|
|
err_msg = "Exit code %s" % retcode
|
|
|
|
|
else:
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
stdout, _, worker_json = stdout.rpartition("\n")
|
2019-04-26 08:40:25 +02:00
|
|
|
stdout = stdout.rstrip()
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
if not worker_json:
|
2019-04-26 08:40:25 +02:00
|
|
|
err_msg = "Failed to parse worker stdout"
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
# deserialize run_tests_worker() output
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
result = json.loads(worker_json,
|
|
|
|
|
object_hook=decode_test_result)
|
2019-04-26 08:40:25 +02:00
|
|
|
except Exception as exc:
|
|
|
|
|
err_msg = "Failed to parse worker JSON: %s" % exc
|
|
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
if err_msg:
|
|
|
|
|
result = TestResult(test_name, state=State.MULTIPROCESSING_ERROR)
|
|
|
|
|
return self.mp_result_error(result, stdout, err_msg)
|
|
|
|
|
|
|
|
|
|
if tmp_files:
|
|
|
|
|
msg = (f'\n\n'
|
|
|
|
|
f'Warning -- {test_name} leaked temporary files '
|
|
|
|
|
f'({len(tmp_files)}): {", ".join(sorted(tmp_files))}')
|
|
|
|
|
stdout += msg
|
|
|
|
|
result.set_env_changed()
|
2015-09-30 00:33:29 +02:00
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
return MultiprocessResult(result, stdout)
|
2015-09-29 23:15:38 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def run(self) -> None:
|
2019-10-01 12:29:36 +02:00
|
|
|
while not self._stopped:
|
2019-04-26 08:40:25 +02:00
|
|
|
try:
|
|
|
|
|
try:
|
|
|
|
|
test_name = next(self.pending)
|
|
|
|
|
except StopIteration:
|
|
|
|
|
break
|
2015-09-29 23:15:38 +02:00
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
self.start_time = time.monotonic()
|
2019-04-26 08:40:25 +02:00
|
|
|
mp_result = self._runtest(test_name)
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
mp_result.result.duration = time.monotonic() - self.start_time
|
2019-04-26 08:40:25 +02:00
|
|
|
self.output.put((False, mp_result))
|
2015-09-29 23:15:38 +02:00
|
|
|
|
2019-05-13 19:17:54 +02:00
|
|
|
if must_stop(mp_result.result, self.ns):
|
2019-04-26 08:40:25 +02:00
|
|
|
break
|
2019-05-14 03:47:32 +02:00
|
|
|
except ExitThread:
|
|
|
|
|
break
|
2019-04-26 08:40:25 +02:00
|
|
|
except BaseException:
|
|
|
|
|
self.output.put((True, traceback.format_exc()))
|
|
|
|
|
break
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def _wait_completed(self) -> None:
|
2019-10-01 12:29:36 +02:00
|
|
|
popen = self._popen
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
popen.wait(JOIN_TIMEOUT)
|
|
|
|
|
except (subprocess.TimeoutExpired, OSError) as exc:
|
|
|
|
|
print_warning(f"Failed to wait for {self} completion "
|
|
|
|
|
f"(timeout={format_duration(JOIN_TIMEOUT)}): "
|
|
|
|
|
f"{exc!r}")
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def wait_stopped(self, start_time: float) -> None:
|
2019-10-08 18:45:43 +02:00
|
|
|
# bpo-38207: MultiprocessTestRunner.stop_workers() called self.stop()
|
|
|
|
|
# which killed the process. Sometimes, killing the process from the
|
|
|
|
|
# main thread does not interrupt popen.communicate() in
|
|
|
|
|
# TestWorkerProcess thread. This loop with a timeout is a workaround
|
|
|
|
|
# for that.
|
|
|
|
|
#
|
|
|
|
|
# Moreover, if this method fails to join the thread, it is likely
|
|
|
|
|
# that Python will hang at exit while calling threading._shutdown()
|
|
|
|
|
# which tries again to join the blocked thread. Regrtest.main()
|
|
|
|
|
# uses EXIT_TIMEOUT to workaround this second bug.
|
2019-10-01 12:29:36 +02:00
|
|
|
while True:
|
|
|
|
|
# Write a message every second
|
|
|
|
|
self.join(1.0)
|
|
|
|
|
if not self.is_alive():
|
|
|
|
|
break
|
|
|
|
|
dt = time.monotonic() - start_time
|
2019-10-03 16:15:16 +02:00
|
|
|
self.regrtest.log(f"Waiting for {self} thread "
|
|
|
|
|
f"for {format_duration(dt)}")
|
2019-10-01 12:29:36 +02:00
|
|
|
if dt > JOIN_TIMEOUT:
|
|
|
|
|
print_warning(f"Failed to join {self} in {format_duration(dt)}")
|
|
|
|
|
break
|
|
|
|
|
|
2019-04-26 08:40:25 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def get_running(workers: list[TestWorkerProcess]) -> list[TestWorkerProcess]:
|
2019-04-26 08:40:25 +02:00
|
|
|
running = []
|
2015-09-29 23:15:38 +02:00
|
|
|
for worker in workers:
|
2019-04-26 08:40:25 +02:00
|
|
|
current_test_name = worker.current_test_name
|
|
|
|
|
if not current_test_name:
|
|
|
|
|
continue
|
|
|
|
|
dt = time.monotonic() - worker.start_time
|
|
|
|
|
if dt >= PROGRESS_MIN_TIME:
|
|
|
|
|
text = '%s (%s)' % (current_test_name, format_duration(dt))
|
|
|
|
|
running.append(text)
|
|
|
|
|
return running
|
|
|
|
|
|
|
|
|
|
|
2019-10-01 12:29:36 +02:00
|
|
|
class MultiprocessTestRunner:
|
2021-07-22 20:25:58 +02:00
|
|
|
def __init__(self, regrtest: Regrtest) -> None:
|
2019-04-26 08:40:25 +02:00
|
|
|
self.regrtest = regrtest
|
2019-10-03 16:15:16 +02:00
|
|
|
self.log = self.regrtest.log
|
2019-04-26 08:40:25 +02:00
|
|
|
self.ns = regrtest.ns
|
2021-07-22 20:25:58 +02:00
|
|
|
self.output: queue.Queue[QueueOutput] = queue.Queue()
|
2019-04-26 08:40:25 +02:00
|
|
|
self.pending = MultiprocessIterator(self.regrtest.tests)
|
|
|
|
|
if self.ns.timeout is not None:
|
2020-04-14 18:29:44 +02:00
|
|
|
# Rely on faulthandler to kill a worker process. This timouet is
|
|
|
|
|
# when faulthandler fails to kill a worker process. Give a maximum
|
|
|
|
|
# of 5 minutes to faulthandler to kill the worker.
|
|
|
|
|
self.worker_timeout = min(self.ns.timeout * 1.5,
|
|
|
|
|
self.ns.timeout + 5 * 60)
|
2019-04-26 08:40:25 +02:00
|
|
|
else:
|
2019-08-14 14:18:51 +02:00
|
|
|
self.worker_timeout = None
|
2019-04-26 08:40:25 +02:00
|
|
|
self.workers = None
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def start_workers(self) -> None:
|
2019-10-03 16:15:16 +02:00
|
|
|
self.workers = [TestWorkerProcess(index, self)
|
2019-10-01 12:29:36 +02:00
|
|
|
for index in range(1, self.ns.use_mp + 1)]
|
2020-04-14 18:29:44 +02:00
|
|
|
msg = f"Run tests in parallel using {len(self.workers)} child processes"
|
|
|
|
|
if self.ns.timeout:
|
|
|
|
|
msg += (" (timeout: %s, worker timeout: %s)"
|
|
|
|
|
% (format_duration(self.ns.timeout),
|
|
|
|
|
format_duration(self.worker_timeout)))
|
|
|
|
|
self.log(msg)
|
2019-04-26 08:40:25 +02:00
|
|
|
for worker in self.workers:
|
|
|
|
|
worker.start()
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def stop_workers(self) -> None:
|
2019-05-14 03:47:32 +02:00
|
|
|
start_time = time.monotonic()
|
2019-04-26 08:40:25 +02:00
|
|
|
for worker in self.workers:
|
2019-10-01 12:29:36 +02:00
|
|
|
worker.stop()
|
2019-04-26 08:40:25 +02:00
|
|
|
for worker in self.workers:
|
2019-10-01 12:29:36 +02:00
|
|
|
worker.wait_stopped(start_time)
|
2019-04-26 08:40:25 +02:00
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def _get_result(self) -> QueueOutput | None:
|
2019-09-17 10:08:19 +02:00
|
|
|
use_faulthandler = (self.ns.timeout is not None)
|
|
|
|
|
timeout = PROGRESS_UPDATE
|
2022-01-10 22:03:09 -05:00
|
|
|
|
|
|
|
|
# bpo-46205: check the status of workers every iteration to avoid
|
|
|
|
|
# waiting forever on an empty queue.
|
|
|
|
|
while any(worker.is_alive() for worker in self.workers):
|
2019-09-17 10:08:19 +02:00
|
|
|
if use_faulthandler:
|
2019-10-08 18:45:43 +02:00
|
|
|
faulthandler.dump_traceback_later(MAIN_PROCESS_TIMEOUT,
|
|
|
|
|
exit=True)
|
2016-03-23 02:04:32 +01:00
|
|
|
|
2019-04-26 08:40:25 +02:00
|
|
|
# wait for a thread
|
2015-09-30 03:05:43 +02:00
|
|
|
try:
|
2019-04-26 08:40:25 +02:00
|
|
|
return self.output.get(timeout=timeout)
|
2015-09-30 03:05:43 +02:00
|
|
|
except queue.Empty:
|
2019-04-26 08:40:25 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# display progress
|
|
|
|
|
running = get_running(self.workers)
|
|
|
|
|
if running and not self.ns.pgo:
|
2019-10-03 16:15:16 +02:00
|
|
|
self.log('running: %s' % ', '.join(running))
|
2019-04-26 08:40:25 +02:00
|
|
|
|
2022-01-10 22:03:09 -05:00
|
|
|
# all worker threads are done: consume pending results
|
|
|
|
|
try:
|
|
|
|
|
return self.output.get(timeout=0)
|
|
|
|
|
except queue.Empty:
|
|
|
|
|
return None
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def display_result(self, mp_result: MultiprocessResult) -> None:
|
2019-04-26 08:40:25 +02:00
|
|
|
result = mp_result.result
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
text = str(result)
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
if mp_result.err_msg:
|
|
|
|
|
# MULTIPROCESSING_ERROR
|
|
|
|
|
text += ' (%s)' % mp_result.err_msg
|
|
|
|
|
elif (result.duration >= PROGRESS_MIN_TIME and not self.ns.pgo):
|
|
|
|
|
text += ' (%s)' % format_duration(result.duration)
|
2019-04-26 08:40:25 +02:00
|
|
|
running = get_running(self.workers)
|
|
|
|
|
if running and not self.ns.pgo:
|
|
|
|
|
text += ' -- running: %s' % ', '.join(running)
|
|
|
|
|
self.regrtest.display_progress(self.test_index, text)
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def _process_result(self, item: QueueOutput) -> bool:
|
|
|
|
|
"""Returns True if test runner must stop."""
|
2019-04-26 08:40:25 +02:00
|
|
|
if item[0]:
|
|
|
|
|
# Thread got an exception
|
|
|
|
|
format_exc = item[1]
|
2019-10-03 16:15:16 +02:00
|
|
|
print_warning(f"regrtest worker thread failed: {format_exc}")
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
result = TestResult("<regrtest worker>", state=State.MULTIPROCESSING_ERROR)
|
2023-06-28 04:58:34 +02:00
|
|
|
self.regrtest.accumulate_result(result)
|
2019-04-26 08:40:25 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
self.test_index += 1
|
|
|
|
|
mp_result = item[1]
|
|
|
|
|
self.regrtest.accumulate_result(mp_result.result)
|
|
|
|
|
self.display_result(mp_result)
|
|
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
if mp_result.worker_stdout:
|
|
|
|
|
print(mp_result.worker_stdout, flush=True)
|
2019-04-26 08:40:25 +02:00
|
|
|
|
2019-05-13 19:17:54 +02:00
|
|
|
if must_stop(mp_result.result, self.ns):
|
2019-04-26 08:40:25 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def run_tests(self) -> None:
|
2019-04-26 08:40:25 +02:00
|
|
|
self.start_workers()
|
|
|
|
|
|
|
|
|
|
self.test_index = 0
|
|
|
|
|
try:
|
|
|
|
|
while True:
|
|
|
|
|
item = self._get_result()
|
|
|
|
|
if item is None:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
stop = self._process_result(item)
|
|
|
|
|
if stop:
|
|
|
|
|
break
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
print()
|
|
|
|
|
self.regrtest.interrupted = True
|
|
|
|
|
finally:
|
2019-09-17 10:08:19 +02:00
|
|
|
if self.ns.timeout is not None:
|
2019-04-26 08:40:25 +02:00
|
|
|
faulthandler.cancel_dump_traceback_later()
|
|
|
|
|
|
2019-10-01 12:29:36 +02:00
|
|
|
# Always ensure that all worker processes are no longer
|
|
|
|
|
# worker when we exit this function
|
|
|
|
|
self.pending.stop()
|
|
|
|
|
self.stop_workers()
|
2019-04-26 08:40:25 +02:00
|
|
|
|
|
|
|
|
|
2021-07-22 20:25:58 +02:00
|
|
|
def run_tests_multiprocess(regrtest: Regrtest) -> None:
|
2019-10-01 12:29:36 +02:00
|
|
|
MultiprocessTestRunner(regrtest).run_tests()
|
2021-07-22 20:25:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class EncodeTestResult(json.JSONEncoder):
|
|
|
|
|
"""Encode a TestResult (sub)class object into a JSON dict."""
|
|
|
|
|
|
|
|
|
|
def default(self, o: Any) -> dict[str, Any]:
|
|
|
|
|
if isinstance(o, TestResult):
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
result = dataclasses.asdict(o)
|
2021-07-22 20:25:58 +02:00
|
|
|
result["__test_result__"] = o.__class__.__name__
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
return super().default(o)
|
|
|
|
|
|
|
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
def decode_test_result(d: dict[str, Any]) -> TestResult | TestStats | dict[str, Any]:
|
2021-07-22 20:25:58 +02:00
|
|
|
"""Decode a TestResult (sub)class object from a JSON dict."""
|
|
|
|
|
|
|
|
|
|
if "__test_result__" not in d:
|
|
|
|
|
return d
|
|
|
|
|
|
[3.11] gh-108822: Backport libregrtest changes from the main branch (#108820)
* Revert "[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)"
This reverts commit d5418e97fc524420011a370ba3c2c3cf6a89a74f.
* Revert "[3.11] bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (GH-30895) (GH-103342)"
This reverts commit ecb09a849689764193e0115d27e220f82b5f6d9f.
* Revert "gh-95027: Fix regrtest stdout encoding on Windows (GH-98492)"
This reverts commit b2aa28eec56d07b9c6777b02b7247cf21839de9f.
* Revert "[3.11] gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253) (GH-94408)"
This reverts commit 0122ab235b5acb52dd99fd05d8802a00f438b828.
* Revert "Run Tools/scripts/reindent.py (GH-94225)"
This reverts commit f0f3a424afb00a15ce8c0140dd218f5b33929be6.
* Revert "gh-94052: Don't re-run failed tests with --python option (GH-94054)"
This reverts commit 1347607db12012f6458ffcba48d8ad797083812e.
* Revert "[3.11] gh-84461: Fix Emscripten umask and permission issues (GH-94002) (GH-94006)"
This reverts commit 10731849184a3101ed18683b0128d689f1671c3f.
* gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process
and mark a test as "environment changed" if a test leaks a temporary
file or directory.
(cherry picked from commit e566ce5496f1bad81c431aaee65e36d5e44771c5)
* gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
(cherry picked from commit 36934a16e86f34d69ba2d41630fb5b4d06d59cff)
* gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files and
directories when using -jN for N >= 2. Use tempfile.mkdtemp() to
create the temporary directory. Skip this check on WASI.
(cherry picked from commit 4f85cec9e2077681b3dacc3108e646d509b720bf)
* gh-84461: Fix Emscripten umask and permission issues (GH-94002)
- Emscripten's default umask is too strict, see
https://github.com/emscripten-core/emscripten/issues/17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
(root). Disable effective uid/gid syscalls and fix tests that use
chmod() current user.
- Cannot drop X bit from directory.
(cherry picked from commit 2702e408fd0e0dd7aec396b4cf8c7ce9caae81d8)
* gh-94052: Don't re-run failed tests with --python option (#94054)
(cherry picked from commit 0ff7b996f5d836e63cdaf652c7aa734285261096)
* Run Tools/scripts/reindent.py (#94225)
Reindent files which were not properly formatted (PEP 8: 4 spaces).
Remove also some trailing spaces.
(cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a)
* gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 199ba233248ab279f445e0809c2077976f0711bc)
* gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
(cherry picked from commit 9c8f3794337457b1d905a9fa0f38c2978fe32abd)
* gh-95027: Fix regrtest stdout encoding on Windows (#98492)
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5f139868dc2c1116a7c7c878c38c668d53)
* gh-98903: Test suite fails with exit code 4 if no tests ran (#98904)
The Python test suite now fails wit exit code 4 if no tests ran. It
should help detecting typos in test names and test methods.
* Add "EXITCODE_" constants to Lib/test/libregrtest/main.py.
* Fix a typo: "NO TEST RUN" becomes "NO TESTS RAN"
(cherry picked from commit c76db37c0d23174cbffd6fa978d39693890ef020)
* gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
(cherry picked from commit 3c892022472eb975360fb3f0caa6f6fcc6fbf220)
* bpo-46523: fix tests rerun when `setUp[Class|Module]` fails (#30895)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 995386071f96e4cfebfa027a71ca9134e4651d2a)
* gh-82054: allow test runner to split test_asyncio to execute in parallel by sharding. (#103927)
This runs test_asyncio sub-tests in parallel using sharding from Cinder. This suite is typically the longest-pole in runs because it is a test package with a lot of further sub-tests otherwise run serially. By breaking out the sub-tests as independent modules we can run a lot more in parallel.
After porting we can see the direct impact on a multicore system.
Without this change:
Running make test is 5 min 26 seconds
With this change:
Running make test takes 3 min 39 seconds
That'll vary based on system and parallelism. On a `-j 4` run similar to what CI and buildbot systems often do, it reduced the overall test suite completion latency by 10%.
The drawbacks are that this implementation is hacky and due to the sorting of the tests it obscures when the asyncio tests occur and involves changing CPython test infrastructure but, the wall time saved it is worth it, especially in low-core count CI runs as it pulls a long tail. The win for productivity and reserved CI resource usage is significant.
Future tests that deserve to be refactored into split up suites to benefit from are test_concurrent_futures and the way the _test_multiprocessing suite gets run for all start methods. As exposed by passing the -o flag to python -m test to get a list of the 10 longest running tests.
---------
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google, LLC]
(cherry picked from commit 9e011e7c77dad7d0bbb944c44891531606caeb21)
* Display the sanitizer config in the regrtest header. (#105301)
Display the sanitizers present in libregrtest.
Having this in the CI output for tests with the relevant environment
variable displayed will help make it easier to do what we need to
create an equivalent local test run.
(cherry picked from commit 852348ab65783601e0844b6647ea033668b45c11)
* gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdout
cannot be decoded from the locale encoding report a failed testn so the
exitcode is non-zero.
(cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
* gh-108223: test.pythoninfo and libregrtest log Py_NOGIL (#108238)
Enable with --disable-gil --without-pydebug:
$ make pythoninfo|grep NOGIL
sysconfig[Py_NOGIL]: 1
$ ./python -m test
...
== Python build: nogil debug
...
(cherry picked from commit 5afe0c17ca14df430736e549542a4b85e7e7c7ac)
* gh-90791: test.pythoninfo logs ASAN_OPTIONS env var (#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS.
* Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
(cherry picked from commit 3a1ac87f8f89d3206b46a0df4908afae629d669d)
* gh-108388: regrtest splits test_asyncio package (#108393)
Currently, test_asyncio package is only splitted into sub-tests when
using command "./python -m test". With this change, it's also
splitted when passing it on the command line:
"./python -m test test_asyncio".
Remove the concept of "STDTESTS". Python is now mature enough to not
have to bother with that anymore. Removing STDTESTS simplify the
code.
(cherry picked from commit 174e9da0836844a2138cc8915dd305cb2cd7a583)
* regrtest computes statistics (#108793)
test_netrc, test_pep646_syntax and test_xml_etree now return results
in the test_main() function.
Changes:
* Rewrite TestResult as a dataclass with a new State class.
* Add test.support.TestStats class and Regrtest.stats_dict attribute.
* libregrtest.runtest functions now modify a TestResult instance
in-place.
* libregrtest summary lists the number of run tests and skipped
tests, and denied resources.
* Add TestResult.has_meaningful_duration() method.
* Compute TestResult duration in the upper function.
* Use time.perf_counter() instead of time.monotonic().
* Regrtest: rename 'resource_denieds' attribute to 'resource_denied'.
* Rename CHILD_ERROR to MULTIPROCESSING_ERROR.
* Use match/case syntadx to have different code depending on the
test state.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit d4e534cbb35678c82b3a1276826af55d7bfc23b6)
* gh-108822: Add Changelog entry for regrtest statistics (#108821)
---------
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Joshua Herman <zitterbewegung@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-09-03 19:21:53 +02:00
|
|
|
d.pop('__test_result__')
|
|
|
|
|
if d['stats'] is not None:
|
|
|
|
|
d['stats'] = TestStats(**d['stats'])
|
|
|
|
|
return TestResult(**d)
|