Skip to content

Commit 3d57d08

Browse files
authored
Add DebugifyBuilder for debug location coverage testing (#493)
This patch adds a new build factory for running tests using Debugify (see "How To Update Debug Info" in the LLVM docs[0]) for the purposes of detecting debug info errors as proposed on Discourse[1]. This builder is very similar to the `TestSuiteBuilder`, but it adds some required CMake flags to the LLVM and Test Suite builds, and adds an extra step where we use a script within `llvm/utils` to evaluate the output of Debugify. As part of implementing this, I had to make some small changes to the `TestSuiteBuilder` to allow CMake flags to be passed for the Test Suite build, as currently it only accepts flags for the LLVM build. These changes should be a no-op for all existing builds; only by passing the new `extra_test_suite_configure_args` parameter should this have any effect. [0] https://llvm.org/docs/HowToUpdateDebugInfo.html#test-original-debug-info-preservation-in-optimizations [1] https://discourse.llvm.org/t/rfc-require-real-or-annotated-source-locations-on-all-instructions/86816
1 parent a1b0d9a commit 3d57d08

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from buildbot.plugins import util
2+
from buildbot.steps.shell import ShellCommand
3+
from zorg.buildbot.builders import TestSuiteBuilder
4+
from zorg.buildbot.commands.CmakeCommand import CmakeCommand
5+
6+
7+
def addCheckDebugifyStep(f, debugify_output_path, compiler_dir=".", env={}):
8+
script = util.Interpolate(
9+
f"%(prop:builddir)s/{compiler_dir}/llvm/utils/llvm-original-di-preservation.py"
10+
)
11+
f.addStep(
12+
ShellCommand(
13+
name="check debugify output",
14+
command=[
15+
"python3",
16+
script,
17+
util.Interpolate(debugify_output_path),
18+
"--acceptance-test",
19+
"--reduce",
20+
],
21+
description="check debugify output",
22+
env=env,
23+
)
24+
)
25+
26+
27+
def getDebugifyBuildFactory(
28+
depends_on_projects=None,
29+
enable_runtimes="auto",
30+
targets=None,
31+
llvm_srcdir=None,
32+
obj_dir=None,
33+
checks=None,
34+
install_dir=None,
35+
clean=False,
36+
test_suite_build_flags="-O2 -g -DNDEBUG",
37+
extra_configure_args=None,
38+
enable_origin_tracking=True,
39+
extra_test_suite_configure_args=None,
40+
env={},
41+
**kwargs,
42+
):
43+
44+
# Make a local copy of the LLVM configure args, as we are going to modify that.
45+
if extra_configure_args is not None:
46+
llvm_cmake_args = extra_configure_args[:]
47+
else:
48+
llvm_cmake_args = list()
49+
50+
tracking_mode = "COVERAGE_AND_ORIGIN" if enable_origin_tracking else "COVERAGE"
51+
CmakeCommand.applyRequiredOptions(llvm_cmake_args, [
52+
('-DLLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING=', tracking_mode)
53+
])
54+
55+
# This path will be passed through to util.Interpolate, so we leave it in this format.
56+
debugify_output_path = f"%(prop:builddir)s/debugify-report.json"
57+
58+
# Make a local copy of the test suite configure args, as we are going to modify that.
59+
if extra_test_suite_configure_args is not None:
60+
test_suite_cmake_args = extra_test_suite_configure_args[:]
61+
else:
62+
test_suite_cmake_args = list()
63+
64+
CmakeCommand.applyDefaultOptions(test_suite_cmake_args, [
65+
('-DTEST_SUITE_SUBDIRS=', 'CTMark'),
66+
('-DTEST_SUITE_RUN_BENCHMARKS=', 'false'),
67+
('-DTEST_SUITE_COLLECT_CODE_SIZE=', 'false'),
68+
])
69+
# The only configuration that currently makes sense for Debugify builds is optimized debug info builds; any build
70+
# configuration adjustments can be made through the test_suite_build_flags arg.
71+
build_flags = f'{test_suite_build_flags} -Xclang -fverify-debuginfo-preserve -Xclang -fverify-debuginfo-preserve-export={debugify_output_path} -mllvm --debugify-quiet -mllvm -debugify-level=locations'
72+
CmakeCommand.applyRequiredOptions(test_suite_cmake_args, [
73+
('-DCMAKE_BUILD_TYPE=', 'RelWithDebInfo'),
74+
])
75+
test_suite_cmake_args += [
76+
util.Interpolate(f"-DCMAKE_C_FLAGS_RELWITHDEBINFO={build_flags}"),
77+
util.Interpolate(f"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO={build_flags}"),
78+
]
79+
80+
f = TestSuiteBuilder.getTestSuiteBuildFactory(
81+
depends_on_projects=depends_on_projects,
82+
enable_runtimes=enable_runtimes,
83+
targets=targets,
84+
llvm_srcdir=llvm_srcdir,
85+
obj_dir=obj_dir,
86+
checks=checks,
87+
install_dir=install_dir,
88+
clean=clean,
89+
extra_configure_args=llvm_cmake_args,
90+
extra_test_suite_configure_args=test_suite_cmake_args,
91+
**kwargs
92+
)
93+
94+
addCheckDebugifyStep(f, debugify_output_path, compiler_dir=f.monorepo_dir, env=env)
95+
96+
return f

zorg/buildbot/builders/TestSuiteBuilder.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def addTestSuiteStep(
1616
compiler_dir = '.',
1717
env = None,
1818
lit_args = None,
19+
extra_configure_args = None,
1920
**kwargs):
2021

2122
# Set defaults
@@ -24,15 +25,19 @@ def addTestSuiteStep(
2425
if lit_args is None:
2526
lit_args = []
2627

27-
cc = util.Interpolate('-DCMAKE_C_COMPILER=' + '%(prop:builddir)s/'+compiler_dir+'/bin/clang')
28-
cxx = util.Interpolate('-DCMAKE_CXX_COMPILER=' + '%(prop:builddir)s/'+compiler_dir+'/bin/clang++')
28+
cc = util.Interpolate('-DCMAKE_C_COMPILER=%(prop:builddir)s/'+compiler_dir+'/bin/clang')
29+
cxx = util.Interpolate('-DCMAKE_CXX_COMPILER=%(prop:builddir)s/'+compiler_dir+'/bin/clang++')
2930
lit = util.Interpolate('%(prop:builddir)s/' + compiler_dir + '/bin/llvm-lit')
3031
test_suite_base_dir = util.Interpolate('%(prop:builddir)s/' + 'test')
3132
test_suite_src_dir = util.Interpolate('%(prop:builddir)s/' + 'test/test-suite')
3233
test_suite_workdir = util.Interpolate('%(prop:builddir)s/' + 'test/build-test-suite')
33-
cmake_lit_arg = util.Interpolate('-DTEST_SUITE_LIT:FILEPATH=' + '%(prop:builddir)s/' + compiler_dir + '/bin/llvm-lit')
34+
cmake_lit_arg = util.Interpolate('-DTEST_SUITE_LIT:FILEPATH=%(prop:builddir)s/' + compiler_dir + '/bin/llvm-lit')
3435
# used for cmake building test-suite step
35-
options = [cc, cxx, cmake_lit_arg]
36+
if extra_configure_args is not None:
37+
cmake_args = extra_configure_args[:]
38+
else:
39+
cmake_args = list()
40+
cmake_args.extend([cc, cxx, cmake_lit_arg])
3641

3742
# always clobber the build directory to test each new compiler
3843
f.addStep(ShellCommand(name='Clean Test Suite Build dir',
@@ -51,7 +56,7 @@ def addTestSuiteStep(
5156
haltOnFailure=True,
5257
description='Running cmake on Test Suite dir',
5358
workdir=test_suite_workdir,
54-
options=options,
59+
options=cmake_args,
5560
path=test_suite_src_dir,
5661
generator='Ninja'))
5762

@@ -80,6 +85,7 @@ def getTestSuiteBuildFactory(
8085
install_dir = None,
8186
clean = False,
8287
extra_configure_args = None,
88+
extra_test_suite_configure_args = None,
8389
env = None,
8490
**kwargs):
8591

@@ -109,6 +115,7 @@ def getTestSuiteBuildFactory(
109115
compiler_dir=f.obj_dir,
110116
env=env,
111117
lit_args=lit_args,
118+
extra_configure_args=extra_test_suite_configure_args,
112119
**kwargs)
113120

114121
return f

0 commit comments

Comments
 (0)