Skip to content

Commit c086a9d

Browse files
committed
windows: refactor how test harness is run
.pgc files weren't being created when invoking the test harness with default options. I suspect it has to do with existence of multiple processes or something. After some experimentation, running each test individually does result in the creation of hundreds of .pgc files (at least 1 for every test invocation). So this commit changes our test harness execution strategy to run 1 test at a time.
1 parent 9745acb commit c086a9d

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

cpython-windows/build.py

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,40 +1555,49 @@ def build_cpython(arch: str, pgo=False, build_mode="static"):
15551555
env["PATH"] = ";".join(paths)
15561556
del env["PYTHONPATH"]
15571557

1558-
exec_and_log(
1559-
[
1560-
str(cpython_source_path / "python.bat"),
1561-
"-m",
1562-
"test",
1563-
# --pgo simply disables some tests, quiets output, and ignores the
1564-
# exit code. We could disable it if we wanted more verbose test
1565-
# output...
1566-
"--pgo",
1567-
"-j",
1568-
"%d" % max(1, multiprocessing.cpu_count() / 2 - 1),
1569-
# test_regrtest hangs for some reason. It is the test for the
1570-
# test harness itself and isn't exercising useful code. Skip it.
1571-
"--exclude",
1572-
"test_regrtest",
1573-
],
1574-
str(pcbuild_path),
1575-
env,
1576-
exit_on_error=False,
1558+
env["PYTHONHOME"] = str(cpython_source_path)
1559+
1560+
# For some reason, .pgc files aren't being created if we invoke the
1561+
# test harness normally (all tests) or with -j to perform parallel
1562+
# test execution. We work around this by invoking the test harness
1563+
# separately for each test.
1564+
instrumented_python = (
1565+
pcbuild_path / build_directory / "instrumented" / "python.exe"
15771566
)
15781567

1579-
exec_and_log(
1580-
[
1581-
str(msbuild),
1582-
str(pcbuild_path / "pythoncore.vcxproj"),
1583-
"/target:KillPython",
1584-
"/verbosity:normal",
1585-
"/property:Configuration=PGInstrument",
1586-
"/property:Platform=%s" % build_platform,
1587-
"/property:KillPython=true",
1588-
],
1589-
pcbuild_path,
1590-
os.environ,
1591-
)
1568+
tests = subprocess.run(
1569+
[str(instrumented_python), "-m", "test", "--list-tests"],
1570+
cwd=cpython_source_path,
1571+
env=env,
1572+
check=False,
1573+
stdout=subprocess.PIPE,
1574+
).stdout
1575+
1576+
tests = [l.strip() for l in tests.decode("utf-8").splitlines() if l.strip()]
1577+
1578+
for test in sorted(tests):
1579+
# test_regrtest hangs for some reason. It is the test for the
1580+
# test harness itself and isn't exercising useful code. Skip it.
1581+
#
1582+
# test_ssl also seems to hang.
1583+
if test in ("test_regrtest", "test_ssl"):
1584+
continue
1585+
1586+
exec_and_log(
1587+
[
1588+
str(instrumented_python),
1589+
"-m",
1590+
"test",
1591+
# --pgo simply disables some tests, quiets output, and ignores the
1592+
# exit code. We could disable it if we wanted more verbose test
1593+
# output...
1594+
"--pgo",
1595+
test,
1596+
],
1597+
str(pcbuild_path),
1598+
env,
1599+
exit_on_error=False,
1600+
)
15921601

15931602
run_msbuild(
15941603
msbuild, pcbuild_path, configuration="PGUpdate", platform=build_platform

0 commit comments

Comments
 (0)