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

Appearance settings

Commit 3c89202

Browse filesBrowse files
authored
pythongh-100086: Add build info to test.libregrtest (python#100093)
The Python test runner (libregrtest) now logs Python build information like "debug" vs "release" build, or LTO and PGO optimizations.
1 parent 91a8e00 commit 3c89202
Copy full SHA for 3c89202

File tree

Expand file treeCollapse file tree

3 files changed

+91
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+91
-1
lines changed

‎Lib/test/libregrtest/main.py

Copy file name to clipboardExpand all lines: Lib/test/libregrtest/main.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
ChildError, DidNotRun)
1818
from test.libregrtest.setup import setup_tests
1919
from test.libregrtest.pgo import setup_pgo_tests
20-
from test.libregrtest.utils import removepy, count, format_duration, printlist
20+
from test.libregrtest.utils import (removepy, count, format_duration,
21+
printlist, get_build_info)
2122
from test import support
2223
from test.support import os_helper
2324
from test.support import threading_helper
@@ -491,6 +492,7 @@ def display_header(self):
491492
print("==", platform.python_implementation(), *sys.version.split())
492493
print("==", platform.platform(aliased=True),
493494
"%s-endian" % sys.byteorder)
495+
print("== Python build:", ' '.join(get_build_info()))
494496
print("== cwd:", os.getcwd())
495497
cpu_count = os.cpu_count()
496498
if cpu_count:

‎Lib/test/libregrtest/utils.py

Copy file name to clipboardExpand all lines: Lib/test/libregrtest/utils.py
+85Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
22
import os.path
33
import sys
4+
import sysconfig
45
import textwrap
56
from test import support
67

@@ -208,3 +209,87 @@ def clear_caches():
208209
pass
209210
else:
210211
fractions._hash_algorithm.cache_clear()
212+
213+
214+
def get_build_info():
215+
# Get most important configure and build options as a list of strings.
216+
# Example: ['debug', 'ASAN+MSAN'] or ['release', 'LTO+PGO'].
217+
218+
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
219+
cflags = sysconfig.get_config_var('PY_CFLAGS') or ''
220+
cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST') or ''
221+
ldflags_nodist = sysconfig.get_config_var('PY_LDFLAGS_NODIST') or ''
222+
223+
build = []
224+
if hasattr(sys, 'gettotalrefcount'):
225+
# --with-pydebug
226+
build.append('debug')
227+
228+
if '-DNDEBUG' in (cflags + cflags_nodist):
229+
build.append('without_assert')
230+
else:
231+
build.append('release')
232+
233+
if '--with-assertions' in config_args:
234+
build.append('with_assert')
235+
elif '-DNDEBUG' not in (cflags + cflags_nodist):
236+
build.append('with_assert')
237+
238+
# --enable-framework=name
239+
framework = sysconfig.get_config_var('PYTHONFRAMEWORK')
240+
if framework:
241+
build.append(f'framework={framework}')
242+
243+
# --enable-shared
244+
shared = int(sysconfig.get_config_var('PY_ENABLE_SHARED') or '0')
245+
if shared:
246+
build.append('shared')
247+
248+
# --with-lto
249+
optimizations = []
250+
if '-flto=thin' in ldflags_nodist:
251+
optimizations.append('ThinLTO')
252+
elif '-flto' in ldflags_nodist:
253+
optimizations.append('LTO')
254+
255+
# --enable-optimizations
256+
pgo_options = (
257+
# GCC
258+
'-fprofile-use',
259+
# clang: -fprofile-instr-use=code.profclangd
260+
'-fprofile-instr-use',
261+
# ICC
262+
"-prof-use",
263+
)
264+
if any(option in cflags_nodist for option in pgo_options):
265+
optimizations.append('PGO')
266+
if optimizations:
267+
build.append('+'.join(optimizations))
268+
269+
# --with-address-sanitizer
270+
sanitizers = []
271+
if support.check_sanitizer(address=True):
272+
sanitizers.append("ASAN")
273+
# --with-memory-sanitizer
274+
if support.check_sanitizer(memory=True):
275+
sanitizers.append("MSAN")
276+
# --with-undefined-behavior-sanitizer
277+
if support.check_sanitizer(ub=True):
278+
sanitizers.append("UBSAN")
279+
if sanitizers:
280+
build.append('+'.join(sanitizers))
281+
282+
# --with-trace-refs
283+
if hasattr(sys, 'getobjects'):
284+
build.append("TraceRefs")
285+
# --enable-pystats
286+
if hasattr(sys, '_stats_on'):
287+
build.append("pystats")
288+
# --with-valgrind
289+
if sysconfig.get_config_var('WITH_VALGRIND'):
290+
build.append("valgrind")
291+
# --with-dtrace
292+
if sysconfig.get_config_var('WITH_DTRACE'):
293+
build.append("dtrace")
294+
295+
return build
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The Python test runner (libregrtest) now logs Python build information like
2+
"debug" vs "release" build, or LTO and PGO optimizations. Patch by Victor
3+
Stinner.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.