Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53eb9a6

Browse files
authored
gh-110152: regrtest handles cross compilation and HOSTRUNNER (#110156)
* _add_python_opts() now handles cross compilation and HOSTRUNNER.* display_header() now tells if Python is cross-compiled, display HOSTRUNNER, and get the host platform.* Remove Tools/scripts/run_tests.py script.* Remove "make hostrunnertest": use "make buildbottest" or "make test" instead.
1 parentd3728dd commit53eb9a6

File tree

6 files changed

+125
-110
lines changed

6 files changed

+125
-110
lines changed

‎Lib/test/libregrtest/main.py‎

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
importre
44
importshlex
55
importsys
6+
importsysconfig
67
importtime
78

89
fromtestimportsupport
@@ -22,6 +23,7 @@
2223
strip_py_suffix,count,format_duration,
2324
printlist,get_temp_dir,get_work_dir,exit_timeout,
2425
display_header,cleanup_temp_dir,print_warning,
26+
is_cross_compiled,get_host_runner,
2527
MS_WINDOWS,EXIT_TIMEOUT)
2628

2729

@@ -71,10 +73,9 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
7173
self.want_rerun:bool=ns.rerun
7274
self.want_run_leaks:bool=ns.runleaks
7375

74-
ci_mode= (ns.fast_ciorns.slow_ci)
76+
self.ci_mode:bool= (ns.fast_ciorns.slow_ci)
7577
self.want_add_python_opts:bool= (_add_python_opts
76-
andns._add_python_opts
77-
andci_mode)
78+
andns._add_python_opts)
7879

7980
# Select tests
8081
ifns.match_tests:
@@ -431,7 +432,7 @@ def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
431432
if (self.want_header
432433
ornot(self.pgoorself.quietorself.single_test_run
433434
ortestsorself.cmdline_args)):
434-
display_header(self.use_resources)
435+
display_header(self.use_resources,self.python_cmd)
435436

436437
ifself.randomize:
437438
print("Using random seed",self.random_seed)
@@ -489,8 +490,56 @@ def run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
489490
# processes.
490491
returnself._run_tests(selected,tests)
491492

492-
def_add_python_opts(self):
493-
python_opts= []
493+
def_add_cross_compile_opts(self,regrtest_opts):
494+
# WASM/WASI buildbot builders pass multiple PYTHON environment
495+
# variables such as PYTHONPATH and _PYTHON_HOSTRUNNER.
496+
keep_environ=bool(self.python_cmd)
497+
environ=None
498+
499+
# Are we using cross-compilation?
500+
cross_compile=is_cross_compiled()
501+
502+
# Get HOSTRUNNER
503+
hostrunner=get_host_runner()
504+
505+
ifcross_compile:
506+
# emulate -E, but keep PYTHONPATH + cross compile env vars,
507+
# so test executable can load correct sysconfigdata file.
508+
keep= {
509+
'_PYTHON_PROJECT_BASE',
510+
'_PYTHON_HOST_PLATFORM',
511+
'_PYTHON_SYSCONFIGDATA_NAME',
512+
'PYTHONPATH'
513+
}
514+
old_environ=os.environ
515+
new_environ= {
516+
name:valueforname,valueinos.environ.items()
517+
ifnotname.startswith(('PYTHON','_PYTHON'))ornameinkeep
518+
}
519+
# Only set environ if at least one variable was removed
520+
ifnew_environ!=old_environ:
521+
environ=new_environ
522+
keep_environ=True
523+
524+
ifcross_compileandhostrunner:
525+
ifself.num_workers==0:
526+
# For now use only two cores for cross-compiled builds;
527+
# hostrunner can be expensive.
528+
regrtest_opts.extend(['-j','2'])
529+
530+
# If HOSTRUNNER is set and -p/--python option is not given, then
531+
# use hostrunner to execute python binary for tests.
532+
ifnotself.python_cmd:
533+
buildpython=sysconfig.get_config_var("BUILDPYTHON")
534+
python_cmd=f"{hostrunner}{buildpython}"
535+
regrtest_opts.extend(["--python",python_cmd])
536+
keep_environ=True
537+
538+
return (environ,keep_environ)
539+
540+
def_add_ci_python_opts(self,python_opts,keep_environ):
541+
# --fast-ci and --slow-ci add options to Python:
542+
# "-u -W default -bb -E"
494543

495544
# Unbuffered stdout and stderr
496545
ifnotsys.stdout.write_through:
@@ -504,32 +553,27 @@ def _add_python_opts(self):
504553
ifsys.flags.bytes_warning<2:
505554
python_opts.append('-bb')
506555

507-
# WASM/WASI buildbot builders pass multiple PYTHON environment
508-
# variables such as PYTHONPATH and _PYTHON_HOSTRUNNER.
509-
ifnotself.python_cmd:
556+
ifnotkeep_environ:
510557
# Ignore PYTHON* environment variables
511558
ifnotsys.flags.ignore_environment:
512559
python_opts.append('-E')
513560

514-
ifnotpython_opts:
515-
return
516-
517-
cmd= [*sys.orig_argv,"--dont-add-python-opts"]
518-
cmd[1:1]=python_opts
519-
561+
def_execute_python(self,cmd,environ):
520562
# Make sure that messages before execv() are logged
521563
sys.stdout.flush()
522564
sys.stderr.flush()
523565

524566
cmd_text=shlex.join(cmd)
525567
try:
568+
print(f"+{cmd_text}",flush=True)
569+
526570
ifhasattr(os,'execv')andnotMS_WINDOWS:
527571
os.execv(cmd[0],cmd)
528572
# On success, execv() do no return.
529573
# On error, it raises an OSError.
530574
else:
531575
importsubprocess
532-
withsubprocess.Popen(cmd)asproc:
576+
withsubprocess.Popen(cmd,env=environ)asproc:
533577
try:
534578
proc.wait()
535579
exceptKeyboardInterrupt:
@@ -548,6 +592,28 @@ def _add_python_opts(self):
548592
f"Command:{cmd_text}")
549593
# continue executing main()
550594

595+
def_add_python_opts(self):
596+
python_opts= []
597+
regrtest_opts= []
598+
599+
environ,keep_environ=self._add_cross_compile_opts(regrtest_opts)
600+
ifself.ci_mode:
601+
self._add_ci_python_opts(python_opts,keep_environ)
602+
603+
if (notpython_opts)and (notregrtest_opts)and (environisNone):
604+
# Nothing changed: nothing to do
605+
return
606+
607+
# Create new command line
608+
cmd=list(sys.orig_argv)
609+
ifpython_opts:
610+
cmd[1:1]=python_opts
611+
ifregrtest_opts:
612+
cmd.extend(regrtest_opts)
613+
cmd.append("--dont-add-python-opts")
614+
615+
self._execute_python(cmd,environ)
616+
551617
def_init(self):
552618
# Set sys.stdout encoder error handler to backslashreplace,
553619
# similar to sys.stderr error handler, to avoid UnicodeEncodeError

‎Lib/test/libregrtest/utils.py‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
importos.path
66
importplatform
77
importrandom
8+
importshlex
89
importsignal
10+
importsubprocess
911
importsys
1012
importsysconfig
1113
importtempfile
@@ -523,7 +525,18 @@ def adjust_rlimit_nofile():
523525
f"{new_fd_limit}:{err}.")
524526

525527

526-
defdisplay_header(use_resources:tuple[str, ...]):
528+
defget_host_runner():
529+
if (hostrunner:=os.environ.get("_PYTHON_HOSTRUNNER"))isNone:
530+
hostrunner=sysconfig.get_config_var("HOSTRUNNER")
531+
returnhostrunner
532+
533+
534+
defis_cross_compiled():
535+
return ('_PYTHON_HOST_PLATFORM'inos.environ)
536+
537+
538+
defdisplay_header(use_resources:tuple[str, ...],
539+
python_cmd:tuple[str, ...]|None):
527540
# Print basic platform information
528541
print("==",platform.python_implementation(),*sys.version.split())
529542
print("==",platform.platform(aliased=True),
@@ -537,13 +550,35 @@ def display_header(use_resources: tuple[str, ...]):
537550
print("== encodings: locale=%s, FS=%s"
538551
% (locale.getencoding(),sys.getfilesystemencoding()))
539552

540-
541553
ifuse_resources:
542554
print(f"== resources ({len(use_resources)}): "
543555
f"{', '.join(sorted(use_resources))}")
544556
else:
545557
print("== resources: (all disabled, use -u option)")
546558

559+
cross_compile=is_cross_compiled()
560+
ifcross_compile:
561+
print("== cross compiled: Yes")
562+
ifpython_cmd:
563+
cmd=shlex.join(python_cmd)
564+
print(f"== host python:{cmd}")
565+
566+
get_cmd= [*python_cmd,'-m','platform']
567+
proc=subprocess.run(
568+
get_cmd,
569+
stdout=subprocess.PIPE,
570+
text=True,
571+
cwd=os_helper.SAVEDCWD)
572+
stdout=proc.stdout.replace('\n',' ').strip()
573+
ifstdout:
574+
print(f"== host platform:{stdout}")
575+
elifproc.returncode:
576+
print(f"== host platform: <command failed with exit code{proc.returncode}>")
577+
else:
578+
hostrunner=get_host_runner()
579+
ifhostrunner:
580+
print(f"== host runner:{hostrunner}")
581+
547582
# This makes it easier to remember what to set in your local
548583
# environment when trying to reproduce a sanitizer failure.
549584
asan=support.check_sanitizer(address=True)

‎Lib/test/test_regrtest.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -788,14 +788,6 @@ def test_script_autotest(self):
788788
args= [*self.python_args,script,*self.regrtest_args,*self.tests]
789789
self.run_tests(args)
790790

791-
@unittest.skipUnless(sysconfig.is_python_build(),
792-
'run_tests.py script is not installed')
793-
deftest_tools_script_run_tests(self):
794-
# Tools/scripts/run_tests.py
795-
script=os.path.join(ROOT_DIR,'Tools','scripts','run_tests.py')
796-
args= [script,*self.regrtest_args,*self.tests]
797-
self.run_tests(args)
798-
799791
defrun_batch(self,*args):
800792
proc=self.run_command(args)
801793
self.check_output(proc.stdout)

‎Makefile.pre.in‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ $(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)
18371837

18381838
TESTOPTS=$(EXTRATESTOPTS)
18391839
TESTPYTHON=$(RUNSHARED) $(PYTHON_FOR_BUILD) $(TESTPYTHONOPTS)
1840-
TESTRUNNER=$(TESTPYTHON)$(srcdir)/Tools/scripts/run_tests.py
1840+
TESTRUNNER=$(TESTPYTHON)-m test
18411841
TESTTIMEOUT=
18421842

18431843
# Remove "test_python_*" directories of previous failed test jobs.
@@ -1875,11 +1875,6 @@ buildbottest: all
18751875
fi
18761876
$(TESTRUNNER) --slow-ci --timeout=$(TESTTIMEOUT) $(TESTOPTS)
18771877

1878-
# Like buildbottest, but run Python tests with HOSTRUNNER directly.
1879-
.PHONY: hostrunnertest
1880-
hostrunnertest: all
1881-
$(RUNSHARED) $(HOSTRUNNER) ./$(BUILDPYTHON) -m test --slow-ci --timeout=$(TESTTIMEOUT) $(TESTOPTS)
1882-
18831878
.PHONY: pythoninfo
18841879
pythoninfo: all
18851880
$(RUNSHARED) $(HOSTRUNNER) ./$(BUILDPYTHON) -m test.pythoninfo
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Remove ``Tools/scripts/run_tests.py`` and ``make hostrunnertest``. Just run
2+
``./python -m test --slow-ci``, ``make buildbottest`` or ``make test`` instead.
3+
Python test runner (regrtest) now handles cross-compilation and HOSTRUNNER. It
4+
also adds options to Python such fast ``-u -E -W default -bb`` when
5+
``--fast-ci`` or ``--slow-ci`` option is used. Patch by Victor Stinner.

‎Tools/scripts/run_tests.py‎

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp