diff options
author | Christian Heimes <christian@python.org> | 2022-06-11 06:42:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-11 06:42:23 (GMT) |
commit | dc5e02b2f44dada145a3743ef77b07dbcf3e4a4a (patch) | |
tree | 1cf9766732d397987f482db5ced7eec441ae9709 /Tools/scripts | |
parent | 4c496f1f115a7910d4606b4de233d14874c77bfa (diff) | |
download | cpython-dc5e02b2f44dada145a3743ef77b07dbcf3e4a4a.zip cpython-dc5e02b2f44dada145a3743ef77b07dbcf3e4a4a.tar.gz cpython-dc5e02b2f44dada145a3743ef77b07dbcf3e4a4a.tar.bz2 |
gh-84461: Use HOSTRUNNER to run regression tests (GH-93694)
Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Tools/scripts')
-rw-r--r-- | Tools/scripts/run_tests.py | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/Tools/scripts/run_tests.py b/Tools/scripts/run_tests.py index 48feb3f..8dbcade 100644 --- a/Tools/scripts/run_tests.py +++ b/Tools/scripts/run_tests.py @@ -8,7 +8,9 @@ simply passing a -u option to this script. """ import os +import shlex import sys +import sysconfig import test.support @@ -19,15 +21,37 @@ def is_multiprocess_flag(arg): def is_resource_use_flag(arg): return arg.startswith('-u') or arg.startswith('--use') +def is_python_flag(arg): + return arg.startswith('-p') or arg.startswith('--python') + def main(regrtest_args): args = [sys.executable, '-u', # Unbuffered stdout and stderr '-W', 'default', # Warnings set to 'default' '-bb', # Warnings about bytes/bytearray - '-E', # Ignore environment variables ] + cross_compile = '_PYTHON_HOST_PLATFORM' in os.environ + if (hostrunner := os.environ.get("_PYTHON_HOSTRUNNER")) is None: + hostrunner = sysconfig.get_config_var("HOSTRUNNER") + if cross_compile: + # emulate -E, but keep PYTHONPATH + cross compile env vars, so + # test executable can load correct sysconfigdata file. + keep = { + '_PYTHON_PROJECT_BASE', + '_PYTHON_HOST_PLATFORM', + '_PYTHON_SYSCONFIGDATA_NAME', + 'PYTHONPATH' + } + environ = { + name: value for name, value in os.environ.items() + if not name.startswith(('PYTHON', '_PYTHON')) or name in keep + } + else: + environ = os.environ.copy() + args.append("-E") + # Allow user-specified interpreter options to override our defaults. args.extend(test.support.args_from_interpreter_flags()) @@ -38,16 +62,30 @@ def main(regrtest_args): if sys.platform == 'win32': args.append('-n') # Silence alerts under Windows if not any(is_multiprocess_flag(arg) for arg in regrtest_args): - args.extend(['-j', '0']) # Use all CPU cores + if cross_compile and hostrunner: + # For now use only one core for cross-compiled builds; + # hostrunner can be expensive. + args.extend(['-j', '1']) + else: + args.extend(['-j', '0']) # Use all CPU cores if not any(is_resource_use_flag(arg) for arg in regrtest_args): args.extend(['-u', 'all,-largefile,-audio,-gui']) + + if cross_compile and hostrunner: + # If HOSTRUNNER is set and -p/--python option is not given, then + # use hostrunner to execute python binary for tests. + if not any(is_python_flag(arg) for arg in regrtest_args): + buildpython = sysconfig.get_config_var("BUILDPYTHON") + args.extend(["--python", f"{hostrunner} {buildpython}"]) + args.extend(regrtest_args) - print(' '.join(args)) + + print(shlex.join(args)) if sys.platform == 'win32': from subprocess import call sys.exit(call(args)) else: - os.execv(sys.executable, args) + os.execve(sys.executable, args, environ) if __name__ == '__main__': |