2015-10-02 19:21:12 -03:00
|
|
|
import faulthandler
|
2016-09-09 01:46:56 -03:00
|
|
|
import locale
|
2015-09-26 05:38:01 -03:00
|
|
|
import os
|
2015-09-29 17:48:52 -03:00
|
|
|
import platform
|
|
|
|
import random
|
2015-09-26 05:38:01 -03:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import sysconfig
|
2015-09-29 17:48:52 -03:00
|
|
|
import tempfile
|
2016-03-22 11:14:09 -03:00
|
|
|
import time
|
2017-06-16 06:36:19 -03:00
|
|
|
import unittest
|
2023-09-08 19:41:26 -03:00
|
|
|
from test.libregrtest.cmdline import _parse_args, Namespace
|
2015-09-26 05:38:01 -03:00
|
|
|
from test.libregrtest.runtest import (
|
2023-09-08 22:37:48 -03:00
|
|
|
findtests, split_test_packages, run_single_test, abs_module_name,
|
2023-09-08 20:48:54 -03:00
|
|
|
PROGRESS_MIN_TIME, State, RunTests, TestResult,
|
|
|
|
FilterTuple, FilterDict, TestList)
|
2023-09-08 22:37:48 -03:00
|
|
|
from test.libregrtest.setup import setup_tests, setup_test_dir
|
2019-07-22 16:54:25 -03:00
|
|
|
from test.libregrtest.pgo import setup_pgo_tests
|
2023-09-03 18:37:15 -03:00
|
|
|
from test.libregrtest.utils import (strip_py_suffix, count, format_duration,
|
2022-12-07 20:38:47 -04:00
|
|
|
printlist, get_build_info)
|
2015-09-26 05:38:01 -03:00
|
|
|
from test import support
|
2023-09-02 13:09:36 -03:00
|
|
|
from test.support import TestStats
|
2020-06-25 07:38:51 -03:00
|
|
|
from test.support import os_helper
|
2022-04-07 04:22:47 -03:00
|
|
|
from test.support import threading_helper
|
2015-09-26 05:38:01 -03:00
|
|
|
|
|
|
|
|
2019-09-18 03:29:25 -03:00
|
|
|
# bpo-38203: Maximum delay in seconds to exit Python (call Py_Finalize()).
|
|
|
|
# Used to protect against threading._shutdown() hang.
|
|
|
|
# Must be smaller than buildbot "1200 seconds without output" limit.
|
|
|
|
EXIT_TIMEOUT = 120.0
|
|
|
|
|
2022-11-02 11:37:40 -03:00
|
|
|
EXITCODE_BAD_TEST = 2
|
|
|
|
EXITCODE_ENV_CHANGED = 3
|
|
|
|
EXITCODE_NO_TESTS_RAN = 4
|
2023-09-04 22:09:42 -03:00
|
|
|
EXITCODE_RERUN_FAIL = 5
|
|
|
|
EXITCODE_INTERRUPTED = 130
|
2022-11-02 11:37:40 -03:00
|
|
|
|
2019-09-18 03:29:25 -03:00
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
class Regrtest:
|
2015-09-26 05:38:01 -03:00
|
|
|
"""Execute a test suite.
|
|
|
|
|
|
|
|
This also parses command-line options and modifies its behavior
|
|
|
|
accordingly.
|
|
|
|
|
|
|
|
tests -- a list of strings containing test names (optional)
|
|
|
|
testdir -- the directory in which to look for tests (optional)
|
|
|
|
|
|
|
|
Users other than the Python test suite will certainly want to
|
|
|
|
specify testdir; if it's omitted, the directory containing the
|
|
|
|
Python test suite is searched for.
|
|
|
|
|
|
|
|
If the tests argument is omitted, the tests listed on the
|
|
|
|
command-line will be used. If that's empty, too, then all *.py
|
|
|
|
files beginning with test_ will be used.
|
|
|
|
|
|
|
|
The other default arguments (verbose, quiet, exclude,
|
2021-11-12 11:19:09 -04:00
|
|
|
single, randomize, use_resources, trace, coverdir,
|
2015-09-26 05:38:01 -03:00
|
|
|
print_slow, and random_seed) allow programmers calling main()
|
|
|
|
directly to set the values that would normally be set by flags
|
|
|
|
on the command line.
|
|
|
|
"""
|
2023-09-08 19:41:26 -03:00
|
|
|
def __init__(self, ns: Namespace):
|
2015-09-29 17:48:52 -03:00
|
|
|
# Namespace of command line options
|
2023-09-08 19:41:26 -03:00
|
|
|
self.ns: Namespace = ns
|
2015-09-29 17:48:52 -03:00
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
# Actions
|
2023-09-08 22:37:48 -03:00
|
|
|
self.want_header: bool = ns.header
|
|
|
|
self.want_list_tests: bool = ns.list_tests
|
|
|
|
self.want_list_cases: bool = ns.list_cases
|
|
|
|
self.want_wait: bool = ns.wait
|
|
|
|
self.want_cleanup: bool = ns.cleanup
|
2023-09-08 20:48:54 -03:00
|
|
|
|
|
|
|
# Select tests
|
|
|
|
if ns.match_tests:
|
|
|
|
self.match_tests: FilterTuple = tuple(ns.match_tests)
|
|
|
|
else:
|
|
|
|
self.match_tests = None
|
|
|
|
if ns.ignore_tests:
|
|
|
|
self.ignore_tests: FilterTuple = tuple(ns.ignore_tests)
|
|
|
|
else:
|
|
|
|
self.ignore_tests = None
|
2023-09-08 22:37:48 -03:00
|
|
|
self.exclude: bool = ns.exclude
|
|
|
|
self.fromfile: str | None = ns.fromfile
|
|
|
|
self.starting_test: str | None = ns.start
|
2023-09-08 20:48:54 -03:00
|
|
|
|
|
|
|
# Options to run tests
|
2023-09-08 22:37:48 -03:00
|
|
|
self.fail_fast: bool = ns.failfast
|
|
|
|
self.forever: bool = ns.forever
|
|
|
|
self.randomize: bool = ns.randomize
|
|
|
|
self.random_seed: int | None = ns.random_seed
|
|
|
|
self.pgo: bool = ns.pgo
|
|
|
|
self.pgo_extended: bool = ns.pgo_extended
|
|
|
|
self.output_on_failure: bool = ns.verbose3
|
|
|
|
self.timeout: float | None = ns.timeout
|
2023-09-08 20:48:54 -03:00
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
# tests
|
|
|
|
self.tests = []
|
|
|
|
self.selected = []
|
2023-09-08 20:48:54 -03:00
|
|
|
self.first_runtests: RunTests | None = None
|
2015-09-29 17:48:52 -03:00
|
|
|
|
|
|
|
# test results
|
2023-09-08 19:41:26 -03:00
|
|
|
self.good: TestList = []
|
|
|
|
self.bad: TestList = []
|
|
|
|
self.rerun_bad: TestList = []
|
|
|
|
self.skipped: TestList = []
|
|
|
|
self.resource_denied: TestList = []
|
|
|
|
self.environment_changed: TestList = []
|
|
|
|
self.run_no_tests: TestList = []
|
|
|
|
self.rerun: TestList = []
|
2023-09-03 18:37:15 -03:00
|
|
|
|
|
|
|
self.need_rerun: list[TestResult] = []
|
|
|
|
self.first_state: str | None = None
|
2015-09-29 17:48:52 -03:00
|
|
|
self.interrupted = False
|
2023-09-03 18:37:15 -03:00
|
|
|
self.total_stats = TestStats()
|
2015-09-26 05:38:01 -03:00
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
# used by --slow
|
|
|
|
self.test_times = []
|
2015-09-26 05:38:01 -03:00
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
# used to display the progress bar "[ 3/100]"
|
2023-09-02 13:09:36 -03:00
|
|
|
self.start_time = time.perf_counter()
|
2023-09-03 18:37:15 -03:00
|
|
|
self.test_count_text = ''
|
2015-09-29 17:48:52 -03:00
|
|
|
self.test_count_width = 1
|
2015-09-26 05:38:01 -03:00
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
# used by --single
|
|
|
|
self.next_single_test = None
|
|
|
|
self.next_single_filename = None
|
2015-09-26 05:38:01 -03:00
|
|
|
|
2018-09-18 13:10:26 -03:00
|
|
|
# used by --junit-xml
|
|
|
|
self.testsuite_xml = None
|
|
|
|
|
2019-05-14 10:49:16 -03:00
|
|
|
# misc
|
2019-04-26 06:12:26 -03:00
|
|
|
self.win_load_tracker = None
|
2019-05-14 10:49:16 -03:00
|
|
|
self.tmp_dir = None
|
2019-04-26 06:12:26 -03:00
|
|
|
|
2019-04-26 03:40:25 -03:00
|
|
|
def get_executed(self):
|
|
|
|
return (set(self.good) | set(self.bad) | set(self.skipped)
|
2023-09-02 13:09:36 -03:00
|
|
|
| set(self.resource_denied) | set(self.environment_changed)
|
2019-04-26 03:40:25 -03:00
|
|
|
| set(self.run_no_tests))
|
|
|
|
|
2019-04-26 04:56:37 -03:00
|
|
|
def accumulate_result(self, result, rerun=False):
|
2023-09-03 18:37:15 -03:00
|
|
|
fail_env_changed = self.ns.fail_env_changed
|
2023-09-02 13:09:36 -03:00
|
|
|
test_name = result.test_name
|
|
|
|
|
|
|
|
match result.state:
|
|
|
|
case State.PASSED:
|
|
|
|
self.good.append(test_name)
|
|
|
|
case State.ENV_CHANGED:
|
|
|
|
self.environment_changed.append(test_name)
|
|
|
|
case State.SKIPPED:
|
|
|
|
self.skipped.append(test_name)
|
|
|
|
case State.RESOURCE_DENIED:
|
|
|
|
self.resource_denied.append(test_name)
|
|
|
|
case State.INTERRUPTED:
|
|
|
|
self.interrupted = True
|
|
|
|
case State.DID_NOT_RUN:
|
|
|
|
self.run_no_tests.append(test_name)
|
|
|
|
case _:
|
2023-09-03 18:37:15 -03:00
|
|
|
if result.is_failed(fail_env_changed):
|
|
|
|
self.bad.append(test_name)
|
|
|
|
self.need_rerun.append(result)
|
2023-09-02 13:09:36 -03:00
|
|
|
else:
|
2023-09-03 18:37:15 -03:00
|
|
|
raise ValueError(f"invalid test state: {result.state!r}")
|
2023-09-02 13:09:36 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
if result.has_meaningful_duration() and not rerun:
|
|
|
|
self.test_times.append((result.duration, test_name))
|
2023-09-02 13:09:36 -03:00
|
|
|
if result.stats is not None:
|
2023-09-03 18:37:15 -03:00
|
|
|
self.total_stats.accumulate(result.stats)
|
|
|
|
if rerun:
|
|
|
|
self.rerun.append(test_name)
|
2019-04-26 04:56:37 -03:00
|
|
|
|
2019-04-25 23:08:53 -03:00
|
|
|
xml_data = result.xml_data
|
2018-09-18 13:10:26 -03:00
|
|
|
if xml_data:
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
for e in xml_data:
|
|
|
|
try:
|
|
|
|
self.testsuite_xml.append(ET.fromstring(e))
|
|
|
|
except ET.ParseError:
|
|
|
|
print(xml_data, file=sys.__stderr__)
|
|
|
|
raise
|
|
|
|
|
2019-10-03 11:15:16 -03:00
|
|
|
def log(self, line=''):
|
|
|
|
empty = not line
|
2017-05-04 10:21:12 -03:00
|
|
|
|
|
|
|
# add the system load prefix: "load avg: 1.80 "
|
2019-04-26 06:12:26 -03:00
|
|
|
load_avg = self.getloadavg()
|
|
|
|
if load_avg is not None:
|
|
|
|
line = f"load avg: {load_avg:.2f} {line}"
|
2017-05-04 10:21:12 -03:00
|
|
|
|
|
|
|
# add the timestamp prefix: "0:01:05 "
|
2023-09-02 13:09:36 -03:00
|
|
|
test_time = time.perf_counter() - self.start_time
|
2019-10-03 11:15:16 -03:00
|
|
|
|
2021-03-22 21:40:31 -03:00
|
|
|
mins, secs = divmod(int(test_time), 60)
|
|
|
|
hours, mins = divmod(mins, 60)
|
|
|
|
test_time = "%d:%02d:%02d" % (hours, mins, secs)
|
|
|
|
|
|
|
|
line = f"{test_time} {line}"
|
2019-10-03 11:15:16 -03:00
|
|
|
if empty:
|
|
|
|
line = line[:-1]
|
|
|
|
|
2016-03-22 11:14:09 -03:00
|
|
|
print(line, flush=True)
|
2015-09-29 17:48:52 -03:00
|
|
|
|
2019-10-03 11:15:16 -03:00
|
|
|
def display_progress(self, test_index, text):
|
2023-09-03 18:37:15 -03:00
|
|
|
quiet = self.ns.quiet
|
|
|
|
if quiet:
|
2019-10-03 11:15:16 -03:00
|
|
|
return
|
|
|
|
|
|
|
|
# "[ 51/405/1] test_tcl passed"
|
2023-09-03 18:37:15 -03:00
|
|
|
line = f"{test_index:{self.test_count_width}}{self.test_count_text}"
|
2019-10-03 11:15:16 -03:00
|
|
|
fails = len(self.bad) + len(self.environment_changed)
|
2023-09-08 22:37:48 -03:00
|
|
|
if fails and not self.pgo:
|
2019-10-03 11:15:16 -03:00
|
|
|
line = f"{line}/{fails}"
|
|
|
|
self.log(f"[{line}] {text}")
|
|
|
|
|
2023-09-08 19:41:26 -03:00
|
|
|
def find_tests(self):
|
2023-09-03 18:37:15 -03:00
|
|
|
ns = self.ns
|
|
|
|
single = ns.single
|
|
|
|
test_dir = ns.testdir
|
|
|
|
|
|
|
|
if single:
|
2019-05-14 10:49:16 -03:00
|
|
|
self.next_single_filename = os.path.join(self.tmp_dir, 'pynexttest')
|
2015-09-29 17:48:52 -03:00
|
|
|
try:
|
|
|
|
with open(self.next_single_filename, 'r') as fp:
|
|
|
|
next_test = fp.read().strip()
|
|
|
|
self.tests = [next_test]
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
if self.fromfile:
|
2015-09-29 17:48:52 -03:00
|
|
|
self.tests = []
|
2016-03-24 05:43:00 -03:00
|
|
|
# regex to match 'test_builtin' in line:
|
|
|
|
# '0:00:00 [ 4/400] test_builtin -- test_dict took 1 sec'
|
2017-01-02 20:38:58 -04:00
|
|
|
regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b')
|
2023-09-08 20:48:54 -03:00
|
|
|
with open(os.path.join(os_helper.SAVEDCWD, self.fromfile)) as fp:
|
2015-09-29 17:48:52 -03:00
|
|
|
for line in fp:
|
2016-12-09 11:05:51 -04:00
|
|
|
line = line.split('#', 1)[0]
|
2016-03-24 05:43:00 -03:00
|
|
|
line = line.strip()
|
2016-12-09 11:05:51 -04:00
|
|
|
match = regex.search(line)
|
|
|
|
if match is not None:
|
2017-01-02 20:38:58 -04:00
|
|
|
self.tests.append(match.group())
|
2015-09-29 17:48:52 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
strip_py_suffix(self.tests)
|
2015-09-29 17:48:52 -03:00
|
|
|
|
2023-09-08 22:37:48 -03:00
|
|
|
if self.pgo:
|
2019-07-24 01:33:48 -03:00
|
|
|
# add default PGO tests if no tests are specified
|
2023-09-03 18:37:15 -03:00
|
|
|
setup_pgo_tests(ns)
|
2019-07-22 16:54:25 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
exclude_tests = set()
|
2023-09-08 20:48:54 -03:00
|
|
|
if self.exclude:
|
2023-09-03 18:37:15 -03:00
|
|
|
for arg in ns.args:
|
|
|
|
exclude_tests.add(arg)
|
|
|
|
ns.args = []
|
2015-09-29 17:48:52 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
alltests = findtests(testdir=test_dir, exclude=exclude_tests)
|
2015-09-29 17:48:52 -03:00
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
if not self.fromfile:
|
2023-09-03 18:37:15 -03:00
|
|
|
self.selected = self.tests or ns.args
|
2023-08-23 23:44:58 -03:00
|
|
|
if self.selected:
|
|
|
|
self.selected = split_test_packages(self.selected)
|
|
|
|
else:
|
|
|
|
self.selected = alltests
|
2016-03-24 05:43:00 -03:00
|
|
|
else:
|
|
|
|
self.selected = self.tests
|
2023-08-23 23:44:58 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
if single:
|
2015-09-29 17:48:52 -03:00
|
|
|
self.selected = self.selected[:1]
|
|
|
|
try:
|
|
|
|
pos = alltests.index(self.selected[0])
|
|
|
|
self.next_single_test = alltests[pos + 1]
|
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
|
2015-09-29 19:59:35 -03:00
|
|
|
# Remove all the selected tests that precede start if it's set.
|
2023-09-08 20:48:54 -03:00
|
|
|
if self.starting_test:
|
2015-09-29 17:48:52 -03:00
|
|
|
try:
|
2023-09-08 20:48:54 -03:00
|
|
|
del self.selected[:self.selected.index(self.starting_test)]
|
2015-09-29 17:48:52 -03:00
|
|
|
except ValueError:
|
2023-09-08 20:48:54 -03:00
|
|
|
print(f"Cannot find starting test: {self.starting_test}")
|
2023-09-03 18:37:15 -03:00
|
|
|
sys.exit(1)
|
2015-09-29 17:48:52 -03:00
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
if self.randomize:
|
|
|
|
if self.random_seed is None:
|
|
|
|
self.random_seed = random.randrange(100_000_000)
|
|
|
|
random.seed(self.random_seed)
|
2015-09-29 17:48:52 -03:00
|
|
|
random.shuffle(self.selected)
|
|
|
|
|
2015-10-02 19:21:12 -03:00
|
|
|
def list_tests(self):
|
|
|
|
for name in self.selected:
|
|
|
|
print(name)
|
|
|
|
|
2017-06-16 06:36:19 -03:00
|
|
|
def _list_cases(self, suite):
|
|
|
|
for test in suite:
|
|
|
|
if isinstance(test, unittest.loader._FailedTest):
|
|
|
|
continue
|
|
|
|
if isinstance(test, unittest.TestSuite):
|
|
|
|
self._list_cases(test)
|
|
|
|
elif isinstance(test, unittest.TestCase):
|
2017-11-21 19:34:02 -04:00
|
|
|
if support.match_test(test):
|
2017-06-26 09:18:51 -03:00
|
|
|
print(test.id())
|
2017-06-16 06:36:19 -03:00
|
|
|
|
|
|
|
def list_cases(self):
|
2023-09-03 18:37:15 -03:00
|
|
|
ns = self.ns
|
|
|
|
test_dir = ns.testdir
|
2017-06-26 09:18:51 -03:00
|
|
|
support.verbose = False
|
2023-09-08 20:48:54 -03:00
|
|
|
support.set_match_tests(self.match_tests, self.ignore_tests)
|
2017-06-26 09:18:51 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
skipped = []
|
2019-04-25 23:08:53 -03:00
|
|
|
for test_name in self.selected:
|
2023-09-03 18:37:15 -03:00
|
|
|
module_name = abs_module_name(test_name, test_dir)
|
2017-06-16 06:36:19 -03:00
|
|
|
try:
|
2023-09-03 18:37:15 -03:00
|
|
|
suite = unittest.defaultTestLoader.loadTestsFromName(module_name)
|
2017-06-16 06:36:19 -03:00
|
|
|
self._list_cases(suite)
|
|
|
|
except unittest.SkipTest:
|
2023-09-03 18:37:15 -03:00
|
|
|
skipped.append(test_name)
|
2017-06-16 06:36:19 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
if skipped:
|
|
|
|
sys.stdout.flush()
|
|
|
|
stderr = sys.stderr
|
|
|
|
print(file=stderr)
|
|
|
|
print(count(len(skipped), "test"), "skipped:", file=stderr)
|
|
|
|
printlist(skipped, file=stderr)
|
2017-06-16 06:36:19 -03:00
|
|
|
|
2023-09-08 19:41:26 -03:00
|
|
|
def get_rerun_match(self, rerun_list) -> FilterDict:
|
2023-09-03 18:37:15 -03:00
|
|
|
rerun_match_tests = {}
|
|
|
|
for result in rerun_list:
|
|
|
|
match_tests = result.get_rerun_match_tests()
|
|
|
|
# ignore empty match list
|
|
|
|
if match_tests:
|
|
|
|
rerun_match_tests[result.test_name] = match_tests
|
|
|
|
return rerun_match_tests
|
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
def _rerun_failed_tests(self, need_rerun, runtests: RunTests):
|
2023-09-03 18:37:15 -03:00
|
|
|
# Configure the runner to re-run tests
|
|
|
|
ns = self.ns
|
|
|
|
ns.verbose = True
|
|
|
|
if ns.use_mp is None:
|
|
|
|
ns.use_mp = 1
|
|
|
|
|
|
|
|
# Get tests to re-run
|
|
|
|
tests = [result.test_name for result in need_rerun]
|
2023-09-08 22:03:39 -03:00
|
|
|
match_tests_dict = self.get_rerun_match(need_rerun)
|
2023-09-03 18:37:15 -03:00
|
|
|
|
|
|
|
# Clear previously failed tests
|
|
|
|
self.rerun_bad.extend(self.bad)
|
|
|
|
self.bad.clear()
|
|
|
|
self.need_rerun.clear()
|
|
|
|
|
|
|
|
# Re-run failed tests
|
|
|
|
self.log(f"Re-running {len(tests)} failed tests in verbose mode in subprocesses")
|
2023-09-08 22:37:48 -03:00
|
|
|
runtests = runtests.copy(
|
|
|
|
tests=tuple(tests),
|
|
|
|
rerun=True,
|
|
|
|
forever=False,
|
|
|
|
fail_fast=False,
|
|
|
|
match_tests_dict=match_tests_dict,
|
|
|
|
output_on_failure=False)
|
2023-09-08 20:48:54 -03:00
|
|
|
self.set_tests(runtests)
|
2023-09-03 18:37:15 -03:00
|
|
|
self._run_tests_mp(runtests)
|
2023-09-08 22:37:48 -03:00
|
|
|
return runtests
|
2022-06-21 09:42:32 -03:00
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
def rerun_failed_tests(self, need_rerun, runtests: RunTests):
|
2022-06-21 09:42:32 -03:00
|
|
|
if self.ns.python:
|
|
|
|
# Temp patch for https://github.com/python/cpython/issues/94052
|
|
|
|
self.log(
|
|
|
|
"Re-running failed tests is not supported with --python "
|
|
|
|
"host runner option."
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
self.first_state = self.get_tests_state()
|
2021-09-07 13:21:00 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
print()
|
2023-09-08 22:37:48 -03:00
|
|
|
rerun_runtests = self._rerun_failed_tests(need_rerun, runtests)
|
2019-04-26 04:28:53 -03:00
|
|
|
|
|
|
|
if self.bad:
|
|
|
|
print(count(len(self.bad), 'test'), "failed again:")
|
|
|
|
printlist(self.bad)
|
2015-09-29 21:32:11 -03:00
|
|
|
|
2023-09-08 22:37:48 -03:00
|
|
|
self.display_result(rerun_runtests)
|
2018-05-28 16:03:43 -03:00
|
|
|
|
2023-09-08 22:37:48 -03:00
|
|
|
def display_result(self, runtests):
|
|
|
|
pgo = runtests.pgo
|
2023-09-03 18:37:15 -03:00
|
|
|
quiet = self.ns.quiet
|
|
|
|
print_slow = self.ns.print_slow
|
|
|
|
|
2018-05-28 16:03:43 -03:00
|
|
|
# If running the test suite for PGO then no one cares about results.
|
2023-09-03 18:37:15 -03:00
|
|
|
if pgo:
|
2018-05-28 16:03:43 -03:00
|
|
|
return
|
|
|
|
|
|
|
|
print()
|
2023-09-03 18:37:15 -03:00
|
|
|
print("== Tests result: %s ==" % self.get_tests_state())
|
2018-05-28 16:03:43 -03:00
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
if self.interrupted:
|
|
|
|
print("Test suite interrupted by signal SIGINT.")
|
2019-04-26 03:40:25 -03:00
|
|
|
|
|
|
|
omitted = set(self.selected) - self.get_executed()
|
|
|
|
if omitted:
|
|
|
|
print()
|
2015-09-29 17:48:52 -03:00
|
|
|
print(count(len(omitted), "test"), "omitted:")
|
|
|
|
printlist(omitted)
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
if self.good and not quiet:
|
2018-05-28 16:03:43 -03:00
|
|
|
print()
|
2015-09-29 18:43:33 -03:00
|
|
|
if (not self.bad
|
|
|
|
and not self.skipped
|
|
|
|
and not self.interrupted
|
|
|
|
and len(self.good) > 1):
|
2015-09-29 17:48:52 -03:00
|
|
|
print("All", end=' ')
|
|
|
|
print(count(len(self.good), "test"), "OK.")
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
if print_slow:
|
2015-09-29 17:48:52 -03:00
|
|
|
self.test_times.sort(reverse=True)
|
2016-08-17 07:22:52 -03:00
|
|
|
print()
|
2015-09-29 17:48:52 -03:00
|
|
|
print("10 slowest tests:")
|
2019-04-25 23:08:53 -03:00
|
|
|
for test_time, test in self.test_times[:10]:
|
|
|
|
print("- %s: %s" % (test, format_duration(test_time)))
|
2015-09-29 17:48:52 -03:00
|
|
|
|
|
|
|
if self.bad:
|
2016-08-17 10:42:21 -03:00
|
|
|
print()
|
2015-09-29 17:48:52 -03:00
|
|
|
print(count(len(self.bad), "test"), "failed:")
|
|
|
|
printlist(self.bad)
|
|
|
|
|
|
|
|
if self.environment_changed:
|
2016-08-17 10:42:21 -03:00
|
|
|
print()
|
2015-09-29 17:48:52 -03:00
|
|
|
print("{} altered the execution environment:".format(
|
|
|
|
count(len(self.environment_changed), "test")))
|
|
|
|
printlist(self.environment_changed)
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
if self.skipped and not quiet:
|
2016-08-17 10:42:21 -03:00
|
|
|
print()
|
2015-09-29 17:48:52 -03:00
|
|
|
print(count(len(self.skipped), "test"), "skipped:")
|
|
|
|
printlist(self.skipped)
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
if self.resource_denied and not quiet:
|
|
|
|
print()
|
|
|
|
print(count(len(self.resource_denied), "test"), "skipped (resource denied):")
|
|
|
|
printlist(self.resource_denied)
|
|
|
|
|
2018-05-31 19:48:57 -03:00
|
|
|
if self.rerun:
|
|
|
|
print()
|
|
|
|
print("%s:" % count(len(self.rerun), "re-run test"))
|
2021-09-07 13:21:00 -03:00
|
|
|
printlist(self.rerun)
|
2018-05-31 19:48:57 -03:00
|
|
|
|
2018-11-29 13:17:44 -04:00
|
|
|
if self.run_no_tests:
|
|
|
|
print()
|
|
|
|
print(count(len(self.run_no_tests), "test"), "run no tests:")
|
|
|
|
printlist(self.run_no_tests)
|
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
def run_test(self, test_name: str, runtests: RunTests, tracer):
|
|
|
|
if tracer is not None:
|
2023-09-03 18:37:15 -03:00
|
|
|
# If we're tracing code coverage, then we don't exit with status
|
|
|
|
# if on a false return value from main.
|
2023-09-08 22:37:48 -03:00
|
|
|
cmd = ('result = run_single_test(test_name, runtests, self.ns)')
|
2023-09-03 18:37:15 -03:00
|
|
|
ns = dict(locals())
|
2023-09-08 21:30:28 -03:00
|
|
|
tracer.runctx(cmd, globals=globals(), locals=ns)
|
2023-09-03 18:37:15 -03:00
|
|
|
result = ns['result']
|
|
|
|
else:
|
2023-09-08 22:37:48 -03:00
|
|
|
result = run_single_test(test_name, runtests, self.ns)
|
2023-09-03 18:37:15 -03:00
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
self.accumulate_result(result)
|
2023-09-03 18:37:15 -03:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
def run_tests_sequentially(self, runtests):
|
|
|
|
ns = self.ns
|
|
|
|
coverage = ns.trace
|
|
|
|
fail_env_changed = ns.fail_env_changed
|
|
|
|
|
|
|
|
if coverage:
|
2015-09-29 19:59:35 -03:00
|
|
|
import trace
|
2023-09-08 21:30:28 -03:00
|
|
|
tracer = trace.Trace(trace=False, count=True)
|
|
|
|
else:
|
|
|
|
tracer = None
|
2015-09-29 19:59:35 -03:00
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
save_modules = sys.modules.keys()
|
|
|
|
|
2020-04-14 13:29:44 -03:00
|
|
|
msg = "Run tests sequentially"
|
2023-09-08 22:37:48 -03:00
|
|
|
if runtests.timeout:
|
|
|
|
msg += " (timeout: %s)" % format_duration(runtests.timeout)
|
2020-04-14 13:29:44 -03:00
|
|
|
self.log(msg)
|
2016-03-24 07:55:29 -03:00
|
|
|
|
2016-03-23 08:14:10 -03:00
|
|
|
previous_test = None
|
2023-09-03 18:37:15 -03:00
|
|
|
tests_iter = runtests.iter_tests()
|
|
|
|
for test_index, test_name in enumerate(tests_iter, 1):
|
2023-09-02 13:09:36 -03:00
|
|
|
start_time = time.perf_counter()
|
2016-03-23 08:14:10 -03:00
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
text = test_name
|
|
|
|
if previous_test:
|
|
|
|
text = '%s -- %s' % (text, previous_test)
|
|
|
|
self.display_progress(test_index, text)
|
|
|
|
|
|
|
|
result = self.run_test(test_name, runtests, tracer)
|
|
|
|
|
|
|
|
# Unload the newly imported modules (best effort finalization)
|
|
|
|
for module in sys.modules.keys():
|
|
|
|
if module not in save_modules and module.startswith("test."):
|
|
|
|
support.unload(module)
|
2019-04-25 23:08:53 -03:00
|
|
|
|
2023-09-08 22:37:48 -03:00
|
|
|
if result.must_stop(self.fail_fast, fail_env_changed):
|
2019-04-25 23:08:53 -03:00
|
|
|
break
|
|
|
|
|
2021-07-22 15:25:58 -03:00
|
|
|
previous_test = str(result)
|
2023-09-02 13:09:36 -03:00
|
|
|
test_time = time.perf_counter() - start_time
|
2016-03-23 08:14:10 -03:00
|
|
|
if test_time >= PROGRESS_MIN_TIME:
|
2016-08-17 07:22:52 -03:00
|
|
|
previous_test = "%s in %s" % (previous_test, format_duration(test_time))
|
2023-09-02 13:09:36 -03:00
|
|
|
elif result.state == State.PASSED:
|
2016-05-20 08:37:40 -03:00
|
|
|
# be quiet: say nothing if the test passed shortly
|
2016-03-23 08:14:10 -03:00
|
|
|
previous_test = None
|
|
|
|
|
|
|
|
if previous_test:
|
|
|
|
print(previous_test)
|
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
return tracer
|
|
|
|
|
2017-05-04 10:21:12 -03:00
|
|
|
def display_header(self):
|
|
|
|
# Print basic platform information
|
|
|
|
print("==", platform.python_implementation(), *sys.version.split())
|
|
|
|
print("==", platform.platform(aliased=True),
|
|
|
|
"%s-endian" % sys.byteorder)
|
2022-12-07 20:38:47 -04:00
|
|
|
print("== Python build:", ' '.join(get_build_info()))
|
2017-05-04 10:21:12 -03:00
|
|
|
print("== cwd:", os.getcwd())
|
|
|
|
cpu_count = os.cpu_count()
|
|
|
|
if cpu_count:
|
|
|
|
print("== CPU count:", cpu_count)
|
|
|
|
print("== encodings: locale=%s, FS=%s"
|
2022-04-21 22:39:24 -03:00
|
|
|
% (locale.getencoding(), sys.getfilesystemencoding()))
|
2023-08-22 20:39:50 -03:00
|
|
|
self.display_sanitizers()
|
|
|
|
|
|
|
|
def display_sanitizers(self):
|
|
|
|
# This makes it easier to remember what to set in your local
|
|
|
|
# environment when trying to reproduce a sanitizer failure.
|
2023-06-06 03:36:36 -03:00
|
|
|
asan = support.check_sanitizer(address=True)
|
|
|
|
msan = support.check_sanitizer(memory=True)
|
|
|
|
ubsan = support.check_sanitizer(ub=True)
|
2023-08-22 20:39:50 -03:00
|
|
|
sanitizers = []
|
|
|
|
if asan:
|
|
|
|
sanitizers.append("address")
|
|
|
|
if msan:
|
|
|
|
sanitizers.append("memory")
|
|
|
|
if ubsan:
|
|
|
|
sanitizers.append("undefined behavior")
|
|
|
|
if not sanitizers:
|
|
|
|
return
|
|
|
|
|
|
|
|
print(f"== sanitizers: {', '.join(sanitizers)}")
|
|
|
|
for sanitizer, env_var in (
|
|
|
|
(asan, "ASAN_OPTIONS"),
|
|
|
|
(msan, "MSAN_OPTIONS"),
|
|
|
|
(ubsan, "UBSAN_OPTIONS"),
|
|
|
|
):
|
|
|
|
options= os.environ.get(env_var)
|
|
|
|
if sanitizer and options is not None:
|
|
|
|
print(f"== {env_var}={options!r}")
|
2017-05-04 10:21:12 -03:00
|
|
|
|
2022-11-02 11:37:40 -03:00
|
|
|
def no_tests_run(self):
|
|
|
|
return not any((self.good, self.bad, self.skipped, self.interrupted,
|
|
|
|
self.environment_changed))
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
def get_tests_state(self):
|
|
|
|
fail_env_changed = self.ns.fail_env_changed
|
|
|
|
|
2018-05-31 19:48:57 -03:00
|
|
|
result = []
|
|
|
|
if self.bad:
|
|
|
|
result.append("FAILURE")
|
2023-09-03 18:37:15 -03:00
|
|
|
elif fail_env_changed and self.environment_changed:
|
2018-05-31 19:48:57 -03:00
|
|
|
result.append("ENV CHANGED")
|
2022-11-02 11:37:40 -03:00
|
|
|
elif self.no_tests_run():
|
|
|
|
result.append("NO TESTS RAN")
|
2018-05-31 19:48:57 -03:00
|
|
|
|
|
|
|
if self.interrupted:
|
|
|
|
result.append("INTERRUPTED")
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
result.append("SUCCESS")
|
|
|
|
|
2018-06-08 04:53:51 -03:00
|
|
|
result = ', '.join(result)
|
2023-09-03 18:37:15 -03:00
|
|
|
if self.first_state:
|
|
|
|
result = '%s then %s' % (self.first_state, result)
|
2018-06-08 04:53:51 -03:00
|
|
|
return result
|
2018-05-31 19:48:57 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
def _run_tests_mp(self, runtests: RunTests) -> None:
|
|
|
|
from test.libregrtest.runtest_mp import run_tests_multiprocess
|
|
|
|
# If we're on windows and this is the parent runner (not a worker),
|
|
|
|
# track the load average.
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
from test.libregrtest.win_utils import WindowsLoadTracker
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.win_load_tracker = WindowsLoadTracker()
|
|
|
|
except PermissionError as error:
|
|
|
|
# Standard accounts may not have access to the performance
|
|
|
|
# counters.
|
|
|
|
print(f'Failed to create WindowsLoadTracker: {error}')
|
|
|
|
|
|
|
|
try:
|
|
|
|
run_tests_multiprocess(self, runtests)
|
|
|
|
finally:
|
|
|
|
if self.win_load_tracker is not None:
|
|
|
|
self.win_load_tracker.close()
|
|
|
|
self.win_load_tracker = None
|
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
def set_tests(self, runtests: RunTests):
|
|
|
|
self.tests = runtests.tests
|
|
|
|
if runtests.forever:
|
2023-09-03 18:37:15 -03:00
|
|
|
self.test_count_text = ''
|
|
|
|
self.test_count_width = 3
|
|
|
|
else:
|
|
|
|
self.test_count_text = '/{}'.format(len(self.tests))
|
|
|
|
self.test_count_width = len(self.test_count_text) - 1
|
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
def run_tests(self, runtests: RunTests):
|
2023-09-08 20:48:54 -03:00
|
|
|
self.first_runtests = runtests
|
|
|
|
self.set_tests(runtests)
|
2015-09-29 17:48:52 -03:00
|
|
|
if self.ns.use_mp:
|
2023-09-03 18:37:15 -03:00
|
|
|
self._run_tests_mp(runtests)
|
2023-09-08 21:30:28 -03:00
|
|
|
tracer = None
|
2015-09-29 17:48:52 -03:00
|
|
|
else:
|
2023-09-08 21:30:28 -03:00
|
|
|
tracer = self.run_tests_sequentially(runtests)
|
|
|
|
return tracer
|
2015-09-26 05:38:01 -03:00
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
def finalize_tests(self, tracer):
|
2015-09-29 17:48:52 -03:00
|
|
|
if self.next_single_filename:
|
|
|
|
if self.next_single_test:
|
|
|
|
with open(self.next_single_filename, 'w') as fp:
|
|
|
|
fp.write(self.next_single_test + '\n')
|
|
|
|
else:
|
|
|
|
os.unlink(self.next_single_filename)
|
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
if tracer is not None:
|
|
|
|
results = tracer.results()
|
|
|
|
results.write_results(show_missing=True, summary=True,
|
|
|
|
coverdir=self.ns.coverdir)
|
2015-09-29 17:48:52 -03:00
|
|
|
|
|
|
|
if self.ns.runleaks:
|
|
|
|
os.system("leaks %d" % os.getpid())
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
self.save_xml_result()
|
|
|
|
|
2023-09-02 13:09:36 -03:00
|
|
|
def display_summary(self):
|
|
|
|
duration = time.perf_counter() - self.start_time
|
2023-09-08 20:48:54 -03:00
|
|
|
filtered = bool(self.match_tests) or bool(self.ignore_tests)
|
2023-09-02 13:09:36 -03:00
|
|
|
|
|
|
|
# Total duration
|
2023-09-03 18:37:15 -03:00
|
|
|
print()
|
2023-09-02 13:09:36 -03:00
|
|
|
print("Total duration: %s" % format_duration(duration))
|
|
|
|
|
|
|
|
# Total tests
|
2023-09-03 18:37:15 -03:00
|
|
|
total = self.total_stats
|
|
|
|
text = f'run={total.tests_run:,}'
|
|
|
|
if filtered:
|
|
|
|
text = f"{text} (filtered)"
|
|
|
|
stats = [text]
|
2023-09-02 13:09:36 -03:00
|
|
|
if total.failures:
|
|
|
|
stats.append(f'failures={total.failures:,}')
|
|
|
|
if total.skipped:
|
|
|
|
stats.append(f'skipped={total.skipped:,}')
|
|
|
|
print(f"Total tests: {' '.join(stats)}")
|
|
|
|
|
|
|
|
# Total test files
|
2023-09-03 18:37:15 -03:00
|
|
|
all_tests = [self.good, self.bad, self.rerun,
|
|
|
|
self.skipped,
|
|
|
|
self.environment_changed, self.run_no_tests]
|
|
|
|
run = sum(map(len, all_tests))
|
|
|
|
text = f'run={run}'
|
2023-09-08 20:48:54 -03:00
|
|
|
if not self.first_runtests.forever:
|
|
|
|
ntest = len(self.first_runtests.tests)
|
2023-09-03 18:37:15 -03:00
|
|
|
text = f"{text}/{ntest}"
|
|
|
|
if filtered:
|
|
|
|
text = f"{text} (filtered)"
|
|
|
|
report = [text]
|
|
|
|
for name, tests in (
|
|
|
|
('failed', self.bad),
|
|
|
|
('env_changed', self.environment_changed),
|
|
|
|
('skipped', self.skipped),
|
|
|
|
('resource_denied', self.resource_denied),
|
|
|
|
('rerun', self.rerun),
|
|
|
|
('run_no_tests', self.run_no_tests),
|
|
|
|
):
|
|
|
|
if tests:
|
|
|
|
report.append(f'{name}={len(tests)}')
|
2023-09-02 13:09:36 -03:00
|
|
|
print(f"Total test files: {' '.join(report)}")
|
|
|
|
|
|
|
|
# Result
|
2023-09-03 18:37:15 -03:00
|
|
|
result = self.get_tests_state()
|
2023-09-02 13:09:36 -03:00
|
|
|
print(f"Result: {result}")
|
|
|
|
|
2018-09-18 13:10:26 -03:00
|
|
|
def save_xml_result(self):
|
|
|
|
if not self.ns.xmlpath and not self.testsuite_xml:
|
|
|
|
return
|
|
|
|
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
root = ET.Element("testsuites")
|
|
|
|
|
|
|
|
# Manually count the totals for the overall summary
|
|
|
|
totals = {'tests': 0, 'errors': 0, 'failures': 0}
|
|
|
|
for suite in self.testsuite_xml:
|
|
|
|
root.append(suite)
|
|
|
|
for k in totals:
|
|
|
|
try:
|
|
|
|
totals[k] += int(suite.get(k, 0))
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
for k, v in totals.items():
|
|
|
|
root.set(k, str(v))
|
|
|
|
|
2020-06-30 10:46:06 -03:00
|
|
|
xmlpath = os.path.join(os_helper.SAVEDCWD, self.ns.xmlpath)
|
2018-09-18 13:10:26 -03:00
|
|
|
with open(xmlpath, 'wb') as f:
|
|
|
|
for s in ET.tostringlist(root):
|
|
|
|
f.write(s)
|
|
|
|
|
2022-06-19 13:28:55 -03:00
|
|
|
def fix_umask(self):
|
|
|
|
if support.is_emscripten:
|
|
|
|
# Emscripten has default umask 0o777, which breaks some tests.
|
|
|
|
# see https://github.com/emscripten-core/emscripten/issues/17269
|
|
|
|
old_mask = os.umask(0)
|
|
|
|
if old_mask == 0o777:
|
|
|
|
os.umask(0o027)
|
|
|
|
else:
|
|
|
|
os.umask(old_mask)
|
|
|
|
|
2019-06-24 07:03:00 -03:00
|
|
|
def set_temp_dir(self):
|
2023-09-08 19:41:26 -03:00
|
|
|
ns = self.ns
|
|
|
|
if ns.tempdir:
|
|
|
|
ns.tempdir = os.path.expanduser(ns.tempdir)
|
|
|
|
|
|
|
|
if ns.tempdir:
|
|
|
|
self.tmp_dir = ns.tempdir
|
2019-05-14 10:49:16 -03:00
|
|
|
|
|
|
|
if not self.tmp_dir:
|
|
|
|
# When tests are run from the Python build directory, it is best practice
|
|
|
|
# to keep the test files in a subfolder. This eases the cleanup of leftover
|
|
|
|
# files using the "make distclean" command.
|
|
|
|
if sysconfig.is_python_build():
|
|
|
|
self.tmp_dir = sysconfig.get_config_var('abs_builddir')
|
|
|
|
if self.tmp_dir is None:
|
|
|
|
# bpo-30284: On Windows, only srcdir is available. Using
|
|
|
|
# abs_builddir mostly matters on UNIX when building Python
|
|
|
|
# out of the source tree, especially when the source tree
|
|
|
|
# is read only.
|
|
|
|
self.tmp_dir = sysconfig.get_config_var('srcdir')
|
|
|
|
self.tmp_dir = os.path.join(self.tmp_dir, 'build')
|
|
|
|
else:
|
|
|
|
self.tmp_dir = tempfile.gettempdir()
|
2018-11-17 08:14:36 -04:00
|
|
|
|
2019-05-14 10:49:16 -03:00
|
|
|
self.tmp_dir = os.path.abspath(self.tmp_dir)
|
2019-06-24 07:03:00 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
def is_worker(self):
|
2023-09-08 22:03:39 -03:00
|
|
|
return (self.ns.worker_json is not None)
|
2023-09-03 18:37:15 -03:00
|
|
|
|
2019-06-24 07:03:00 -03:00
|
|
|
def create_temp_dir(self):
|
2019-05-14 10:49:16 -03:00
|
|
|
os.makedirs(self.tmp_dir, exist_ok=True)
|
2016-03-24 13:53:20 -03:00
|
|
|
|
|
|
|
# Define a writable temp dir that will be used as cwd while running
|
|
|
|
# the tests. The name of the dir includes the pid to allow parallel
|
|
|
|
# testing (see the -j option).
|
2022-06-13 14:51:04 -03:00
|
|
|
# Emscripten and WASI have stubbed getpid(), Emscripten has only
|
|
|
|
# milisecond clock resolution. Use randint() instead.
|
|
|
|
if sys.platform in {"emscripten", "wasi"}:
|
|
|
|
nounce = random.randint(0, 1_000_000)
|
|
|
|
else:
|
|
|
|
nounce = os.getpid()
|
2023-09-03 18:37:15 -03:00
|
|
|
|
|
|
|
if self.is_worker():
|
2022-06-13 14:51:04 -03:00
|
|
|
test_cwd = 'test_python_worker_{}'.format(nounce)
|
2019-05-14 10:49:16 -03:00
|
|
|
else:
|
2022-06-13 14:51:04 -03:00
|
|
|
test_cwd = 'test_python_{}'.format(nounce)
|
2020-06-30 10:46:06 -03:00
|
|
|
test_cwd += os_helper.FS_NONASCII
|
2019-05-14 10:49:16 -03:00
|
|
|
test_cwd = os.path.join(self.tmp_dir, test_cwd)
|
|
|
|
return test_cwd
|
|
|
|
|
2019-06-24 07:03:00 -03:00
|
|
|
def cleanup(self):
|
|
|
|
import glob
|
|
|
|
|
2020-06-20 05:10:31 -03:00
|
|
|
path = os.path.join(glob.escape(self.tmp_dir), 'test_python_*')
|
2019-06-24 07:03:00 -03:00
|
|
|
print("Cleanup %s directory" % self.tmp_dir)
|
|
|
|
for name in glob.glob(path):
|
|
|
|
if os.path.isdir(name):
|
2019-06-24 08:19:48 -03:00
|
|
|
print("Remove directory: %s" % name)
|
2020-06-30 10:46:06 -03:00
|
|
|
os_helper.rmtree(name)
|
2019-06-24 07:03:00 -03:00
|
|
|
else:
|
|
|
|
print("Remove file: %s" % name)
|
2020-06-30 10:46:06 -03:00
|
|
|
os_helper.unlink(name)
|
2019-06-24 07:03:00 -03:00
|
|
|
|
2023-09-08 19:41:26 -03:00
|
|
|
def main(self, tests: TestList | None = None):
|
|
|
|
ns = self.ns
|
|
|
|
self.tests = tests
|
|
|
|
|
|
|
|
if ns.xmlpath:
|
|
|
|
support.junit_xml_list = self.testsuite_xml = []
|
|
|
|
|
|
|
|
strip_py_suffix(ns.args)
|
2019-06-24 07:03:00 -03:00
|
|
|
|
|
|
|
self.set_temp_dir()
|
|
|
|
|
2022-06-19 13:28:55 -03:00
|
|
|
self.fix_umask()
|
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
if self.want_cleanup:
|
2019-06-24 07:03:00 -03:00
|
|
|
self.cleanup()
|
|
|
|
sys.exit(0)
|
2019-05-14 10:49:16 -03:00
|
|
|
|
|
|
|
test_cwd = self.create_temp_dir()
|
2016-03-24 13:53:20 -03:00
|
|
|
|
2019-09-18 03:29:25 -03:00
|
|
|
try:
|
|
|
|
# Run the tests in a context manager that temporarily changes the CWD
|
|
|
|
# to a temporary and writable directory. If it's not possible to
|
|
|
|
# create or change the CWD, the original CWD will be used.
|
2020-06-30 10:46:06 -03:00
|
|
|
# The original CWD is available from os_helper.SAVEDCWD.
|
2020-06-25 07:38:51 -03:00
|
|
|
with os_helper.temp_cwd(test_cwd, quiet=True):
|
2019-09-18 03:29:25 -03:00
|
|
|
# When using multiprocessing, worker processes will use test_cwd
|
|
|
|
# as their parent temporary directory. So when the main process
|
|
|
|
# exit, it removes also subdirectories of worker processes.
|
2023-09-08 19:41:26 -03:00
|
|
|
ns.tempdir = test_cwd
|
2019-09-18 03:29:25 -03:00
|
|
|
|
2023-09-08 19:41:26 -03:00
|
|
|
self._main()
|
2019-09-18 03:29:25 -03:00
|
|
|
except SystemExit as exc:
|
|
|
|
# bpo-38203: Python can hang at exit in Py_Finalize(), especially
|
|
|
|
# on threading._shutdown() call: put a timeout
|
2022-04-07 04:22:47 -03:00
|
|
|
if threading_helper.can_start_thread:
|
|
|
|
faulthandler.dump_traceback_later(EXIT_TIMEOUT, exit=True)
|
2019-09-18 03:29:25 -03:00
|
|
|
|
|
|
|
sys.exit(exc.code)
|
2016-03-24 13:53:20 -03:00
|
|
|
|
2019-04-26 06:12:26 -03:00
|
|
|
def getloadavg(self):
|
|
|
|
if self.win_load_tracker is not None:
|
|
|
|
return self.win_load_tracker.getloadavg()
|
|
|
|
|
|
|
|
if hasattr(os, 'getloadavg'):
|
|
|
|
return os.getloadavg()[0]
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
def get_exitcode(self):
|
|
|
|
exitcode = 0
|
|
|
|
if self.bad:
|
|
|
|
exitcode = EXITCODE_BAD_TEST
|
|
|
|
elif self.interrupted:
|
|
|
|
exitcode = EXITCODE_INTERRUPTED
|
|
|
|
elif self.ns.fail_env_changed and self.environment_changed:
|
|
|
|
exitcode = EXITCODE_ENV_CHANGED
|
|
|
|
elif self.no_tests_run():
|
|
|
|
exitcode = EXITCODE_NO_TESTS_RAN
|
|
|
|
elif self.rerun and self.ns.fail_rerun:
|
2023-09-04 22:09:42 -03:00
|
|
|
exitcode = EXITCODE_RERUN_FAIL
|
2023-09-03 18:37:15 -03:00
|
|
|
return exitcode
|
|
|
|
|
|
|
|
def action_run_tests(self):
|
2023-09-08 21:30:28 -03:00
|
|
|
if self.ns.huntrleaks:
|
|
|
|
warmup, repetitions, _ = self.ns.huntrleaks
|
|
|
|
if warmup < 3:
|
|
|
|
msg = ("WARNING: Running tests with --huntrleaks/-R and less than "
|
|
|
|
"3 warmup repetitions can give false positives!")
|
|
|
|
print(msg, file=sys.stdout, flush=True)
|
|
|
|
|
|
|
|
# For a partial run, we do not need to clutter the output.
|
|
|
|
if (self.want_header
|
2023-09-08 22:37:48 -03:00
|
|
|
or not(self.pgo or self.ns.quiet or self.ns.single
|
2023-09-08 21:30:28 -03:00
|
|
|
or self.tests or self.ns.args)):
|
|
|
|
self.display_header()
|
|
|
|
|
|
|
|
if self.randomize:
|
|
|
|
print("Using random seed", self.random_seed)
|
|
|
|
|
2023-09-08 22:37:48 -03:00
|
|
|
runtests = RunTests(
|
|
|
|
tuple(self.selected),
|
|
|
|
fail_fast=self.fail_fast,
|
|
|
|
match_tests=self.match_tests,
|
|
|
|
ignore_tests=self.ignore_tests,
|
|
|
|
forever=self.forever,
|
|
|
|
pgo=self.pgo,
|
|
|
|
pgo_extended=self.pgo_extended,
|
|
|
|
output_on_failure=self.output_on_failure,
|
|
|
|
timeout=self.timeout)
|
|
|
|
|
|
|
|
setup_tests(runtests, self.ns)
|
|
|
|
|
2023-09-08 21:30:28 -03:00
|
|
|
tracer = self.run_tests(runtests)
|
2023-09-08 22:37:48 -03:00
|
|
|
self.display_result(runtests)
|
2023-09-03 18:37:15 -03:00
|
|
|
|
|
|
|
need_rerun = self.need_rerun
|
|
|
|
if self.ns.rerun and need_rerun:
|
2023-09-08 20:48:54 -03:00
|
|
|
self.rerun_failed_tests(need_rerun, runtests)
|
2023-09-03 18:37:15 -03:00
|
|
|
|
|
|
|
self.display_summary()
|
2023-09-08 21:30:28 -03:00
|
|
|
self.finalize_tests(tracer)
|
2023-09-03 18:37:15 -03:00
|
|
|
|
2023-09-08 19:41:26 -03:00
|
|
|
def _main(self):
|
2023-09-03 18:37:15 -03:00
|
|
|
if self.is_worker():
|
2023-09-08 22:03:39 -03:00
|
|
|
from test.libregrtest.runtest_mp import worker_process
|
|
|
|
worker_process(self.ns.worker_json)
|
2023-09-03 18:37:15 -03:00
|
|
|
return
|
2015-09-29 20:39:28 -03:00
|
|
|
|
2023-09-08 20:48:54 -03:00
|
|
|
if self.want_wait:
|
2015-09-29 19:59:35 -03:00
|
|
|
input("Press any key to continue...")
|
|
|
|
|
2023-09-08 22:37:48 -03:00
|
|
|
setup_test_dir(self.ns.testdir)
|
2023-09-08 19:41:26 -03:00
|
|
|
self.find_tests()
|
2015-09-29 19:59:35 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
exitcode = 0
|
2023-09-08 20:48:54 -03:00
|
|
|
if self.want_list_tests:
|
2015-10-02 19:21:12 -03:00
|
|
|
self.list_tests()
|
2023-09-08 20:48:54 -03:00
|
|
|
elif self.want_list_cases:
|
2017-06-16 06:36:19 -03:00
|
|
|
self.list_cases()
|
2023-09-03 18:37:15 -03:00
|
|
|
else:
|
|
|
|
self.action_run_tests()
|
|
|
|
exitcode = self.get_exitcode()
|
2018-09-18 13:10:26 -03:00
|
|
|
|
2023-09-03 18:37:15 -03:00
|
|
|
sys.exit(exitcode)
|
2015-09-26 05:38:01 -03:00
|
|
|
|
|
|
|
|
2015-09-29 17:48:52 -03:00
|
|
|
def main(tests=None, **kwargs):
|
2016-03-24 13:53:20 -03:00
|
|
|
"""Run the Python suite."""
|
2023-09-08 19:41:26 -03:00
|
|
|
ns = _parse_args(sys.argv[1:], **kwargs)
|
|
|
|
Regrtest(ns).main(tests=tests)
|