Skip to content

Commit 2c8553b

Browse files
authored
Update TestSuiteBuilder.getLlvmTestSuiteSteps factory. (#656)
Added new optional arguments: * compiler_flags - common flags for C and C++ compilers. * linker_flags - common linker flags for all exe/module/shared configurations. * src_dir - source dir for the test suite source code (within prop:buildir). * obj_dir - build dir for the test suite (within prop:buildir). Added new output properties: * ts_srcdir * ts_objdir The 'compiler_flags' argument extends or adds the following CMake configuration parameters to the appropriate step: CMAKE_C_FLAGS and CMAKE_CXX_FLAGS. The 'linker_flags' argument extends or adds the following CMake configuration parameters accordingly: CMAKE_EXE_LINKER_FLAGS, CMAKE_MODULE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS.
1 parent 5f9e01c commit 2c8553b

File tree

2 files changed

+105
-21
lines changed

2 files changed

+105
-21
lines changed

test/buildbot/builders/testsuite.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,43 @@
2424

2525
print(f"default factory: {f}\n")
2626

27-
assert factory_has_num_steps(f, 5)
27+
assert factory_has_num_steps(f, 6)
2828
assert factory_has_step(f, "clean-src-dir")
29+
assert factory_has_step(f, "set-props")
2930
assert factory_has_step(f, "cmake-configure")
3031
assert factory_has_step(f, "build-default")
3132
assert not factory_has_step(f, "rsync-default")
3233
assert factory_has_step(f, "test-check")
3334

35+
compiler_flags_ = "-march=armv8l+pauth -mbranch-protection=pac-ret -O2"
36+
linker_flags_ = "-O2 -Wl,--emit-relocs"
37+
3438
f = TestSuiteBuilder.getLlvmTestSuiteSteps(
3539
cmake_definitions = {
3640
"TEST_SUITE_REMOTE_HOST" : "buildbot@arm64-linux-02",
3741
"TEST_SUITE_LIT_FLAGS" : "-v --threads=32 --time-tests",
42+
"CMAKE_CXX_FLAGS" : "-O0",
43+
"CMAKE_EXE_LINKER_FLAGS" : "-O0",
3844
},
3945
compiler_dir = util.Interpolate("%(prop:builddir)s/build"),
46+
compiler_flags = compiler_flags_,
47+
linker_flags = linker_flags_,
4048
hint = None,
4149
)
4250

4351
print(f"default factory (compiler_dir): {f}\n")
4452

45-
assert factory_has_num_steps(f, 6)
53+
assert factory_has_num_steps(f, 7)
4654
assert factory_has_step(f, "clean-src-dir")
55+
assert factory_has_step(f, "set-props")
4756
assert factory_has_step(f, "cmake-configure")
57+
assert factory_has_step(f, "cmake-configure", hasarg = "definitions", contains = {
58+
"CMAKE_C_FLAGS" : compiler_flags_,
59+
"CMAKE_CXX_FLAGS" : f"-O0 {compiler_flags_}",
60+
"CMAKE_EXE_LINKER_FLAGS" : f"-O0 {linker_flags_}",
61+
"CMAKE_MODULE_LINKER_FLAGS" : linker_flags_,
62+
"CMAKE_SHARED_LINKER_FLAGS" : linker_flags_,
63+
})
4864
assert factory_has_step(f, "build-default")
4965
assert factory_has_step(f, "rsync-default")
5066
assert factory_has_step(f, "test-check")

zorg/buildbot/builders/TestSuiteBuilder.py

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
from zorg.buildbot.process.factory import LLVMBuildFactory
1212

13-
# The DebugifyBuilder needs to know the test-suite build directory, so we share the build directory via this variable.
14-
test_suite_build_path_suffix = 'test/build-test-suite'
15-
test_suite_project_path_suffix = 'test/test-suite'
1613

1714
# Note: The 'compiler_dir' parameter or CMAKE_{C|CXX}_COMPILER and TEST_SUITE_LIT must be specified inside of 'cmake_definitions' parameters;
1815
# otherwise the function will get failed by assert. Also, some of CMAKE_{C|CXX}_COMPILER and TEST_SUITE_LIT can be specified in case the 'compiler_dir'
@@ -36,6 +33,12 @@ def getLlvmTestSuiteSteps(
3633
compiler_dir = None, # A path a root of built Clang toolchain tree. This path will be used
3734
# to specify CMAKE_{C|CXX}_COMPILER and TEST_SUITE_LIT if they are missing inside of
3835
# CMake definitions.
36+
compiler_flags = None, # Common flags for C and C++ compilers.
37+
linker_flags = None, # Common linker flags for all exe/module/shared configurations.
38+
39+
src_dir = None,
40+
obj_dir = None,
41+
3942
f = None
4043
):
4144
""" Create and configure a builder factory with a set of the build steps to retrieve, build and run the LLVM Test Suite project
@@ -46,6 +49,9 @@ def getLlvmTestSuiteSteps(
4649
This is one-stage CMake configurable build that uses Ninja generator by default. Using the other CMake generators
4750
also possible.
4851
52+
The factory supports the remote test runs on the dev boards. Specifying TEST_SUITE_REMOTE_HOST in the CMake definitions dict
53+
will add the rsync target step.
54+
4955
Property Parameters
5056
-------------------
5157
@@ -128,6 +134,24 @@ def getLlvmTestSuiteSteps(
128134
This argument must be specified if any of CMAKE_{C|CXX}_COMPILER and TEST_SUITE_LIT weren't specified
129135
in the CMake definitions dict.
130136
137+
compiler_flags : string, optional
138+
Common flags for C and C++ compilers.
139+
140+
This argument will add CMAKE_{C|CXX}_FLAGS CMake definitions if they were not specified; otherwise the existing
141+
definitions will be extended with these compiler flags.
142+
143+
linker_flags : string, optional
144+
Common linker flags for all exe/module/shared configurations.
145+
146+
This argument will add CMAKE_{EXE|MODULE|SHARED}_LINKER_FLAGS CMake definitions if they were not specified;
147+
otherwise the existing definitions will be extended with these linker flags.
148+
149+
src_dir : str, optional
150+
A custom llvm-test-suite source directory within %(prop:builddir)s of the builder (default is "llvm-test-suite").
151+
152+
obj_dir : str, optional
153+
The build folder (default is "build/llvm-test-suite").
154+
131155
f : LLVMBuildFactory, optional
132156
A factory object to fill up with the build steps. An empty stub will be created if this argument wasn't specified.
133157
@@ -139,7 +163,11 @@ def getLlvmTestSuiteSteps(
139163
Properties
140164
----------
141165
142-
None
166+
ts_srcdir : str
167+
A full path to the LLVM test-suite source code directory.
168+
169+
ts_objdir : str
170+
A full path to the build directory.
143171
144172
"""
145173
assert generator, "CMake generator must be specified."
@@ -169,19 +197,29 @@ def norm_target_list_arg(lst):
169197

170198
# Initial directories
171199
test_suite_src_dir = util.Interpolate("%(prop:builddir)s/%(kw:path_suffix)s",
172-
path_suffix = test_suite_project_path_suffix)
173-
test_suite_workdir = util.Interpolate("%(prop:builddir)s/%(kw:path_suffix)s",
174-
path_suffix = test_suite_build_path_suffix)
175-
200+
path_suffix = src_dir or "llvm-test-suite")
201+
test_suite_obj_dir = util.Interpolate("%(prop:builddir)s/%(kw:path_suffix)s",
202+
path_suffix = obj_dir or util.Interpolate("%(prop:objdir:-build)s/llvm-test-suite"))
176203

177204
# Create and return the default factory stub to store the build steps.
178205
# This factory can be used with the composite builder factories.
179206
if f is None:
180207
f = LLVMBuildFactory(
181208
hint = hint,
182-
obj_dir = test_suite_build_path_suffix,
209+
obj_dir = "build/llvm-test-suite", # stub, shouldn't be used
183210
)
184211

212+
f.addSteps([
213+
# Set up some properties, which could be used to configure the builders.
214+
steps.SetProperties(
215+
name = f.makeStepName('set-props'),
216+
properties = {
217+
"ts_srcdir" : test_suite_src_dir,
218+
"ts_objdir" : test_suite_obj_dir,
219+
}
220+
),
221+
])
222+
185223
# Add the Git step.
186224
if repo_profiles == "default":
187225
f.addSteps([
@@ -222,21 +260,51 @@ def norm_target_list_arg(lst):
222260
if "TEST_SUITE_LIT_FLAGS" in cmake_definitions:
223261
cmake_definitions.update({ "TEST_SUITE_LIT_FLAGS" : cmake_definitions["TEST_SUITE_LIT_FLAGS"].replace(" ", ";") })
224262

225-
# Check if we need to sync the test data with the remote host.
263+
# Check if we need to sync the test data on the remote host.
226264
remote_rsync = ("TEST_SUITE_REMOTE_HOST" in cmake_definitions)
227265

228-
if compiler_dir is None:
229-
assert "CMAKE_C_COMPILER" in cmake_definitions, "CMAKE_C_COMPILER must be specified in the CMake definitions."
230-
assert "CMAKE_CXX_COMPILER" in cmake_definitions, "CMAKE_CXX_COMPILER must be specified in the CMake definitions."
231-
assert ("TEST_SUITE_LIT" in cmake_definitions or "TEST_SUITE_LIT:FILEPATH" in cmake_definitions), "TEST_SUITE_LIT must be specified in the CMake definitions."
232-
else:
266+
if compiler_dir:
233267
#TODO: support for the executable extensions on the build host.
234268
if not "CMAKE_C_COMPILER" in cmake_definitions:
235269
cmake_definitions.update({ "CMAKE_C_COMPILER" : util.Interpolate("%(kw:compiler_dir)s/bin/clang", compiler_dir = compiler_dir) })
236270
if not "CMAKE_CXX_COMPILER" in cmake_definitions:
237271
cmake_definitions.update({ "CMAKE_CXX_COMPILER" : util.Interpolate("%(kw:compiler_dir)s/bin/clang++", compiler_dir = compiler_dir) })
238272
if not ("TEST_SUITE_LIT" in cmake_definitions or "TEST_SUITE_LIT:FILEPATH" in cmake_definitions):
239273
cmake_definitions.update({ "TEST_SUITE_LIT:FILEPATH" : util.Interpolate("%(kw:compiler_dir)s/bin/llvm-lit", compiler_dir = compiler_dir) })
274+
else:
275+
assert "CMAKE_C_COMPILER" in cmake_definitions, "CMAKE_C_COMPILER must be specified in the CMake definitions."
276+
assert "CMAKE_CXX_COMPILER" in cmake_definitions, "CMAKE_CXX_COMPILER must be specified in the CMake definitions."
277+
assert ("TEST_SUITE_LIT" in cmake_definitions or "TEST_SUITE_LIT:FILEPATH" in cmake_definitions), "TEST_SUITE_LIT must be specified in the CMake definitions."
278+
279+
#Note: we can get those flags as the renderables. Properly handle them by using %(kw:) interpolation.
280+
if compiler_flags:
281+
c_flags = compiler_flags
282+
cxx_flags = compiler_flags
283+
if "CMAKE_C_FLAGS" in cmake_definitions:
284+
c_flags = util.Interpolate("%(kw:c_flags)s %(kw:flags)s",
285+
c_flags = c_flags, flags = cmake_definitions["CMAKE_C_FLAGS"])
286+
cmake_definitions.update({ "CMAKE_C_FLAGS" : c_flags })
287+
if "CMAKE_CXX_FLAGS" in cmake_definitions:
288+
cxx_flags = util.Interpolate("%(kw:cxx_flags)s %(kw:flags)s",
289+
cxx_flags = cxx_flags, flags = cmake_definitions["CMAKE_CXX_FLAGS"])
290+
cmake_definitions.update({ "CMAKE_CXX_FLAGS" : cxx_flags })
291+
292+
if linker_flags:
293+
exe_flags = linker_flags
294+
module_flags = linker_flags
295+
shared_flags = linker_flags
296+
if "CMAKE_EXE_LINKER_FLAGS" in cmake_definitions:
297+
exe_flags = util.Interpolate("%(kw:exe_flags)s %(kw:flags)s",
298+
exe_flags = exe_flags, flags = cmake_definitions["CMAKE_EXE_LINKER_FLAGS"])
299+
cmake_definitions.update({ "CMAKE_EXE_LINKER_FLAGS" : exe_flags })
300+
if "CMAKE_MODULE_LINKER_FLAGS" in cmake_definitions:
301+
module_flags = util.Interpolate("%(kw:module_flags)s %(kw:flags)s",
302+
module_flags = module_flags, flags = cmake_definitions["CMAKE_MODULE_LINKER_FLAGS"])
303+
cmake_definitions.update({ "CMAKE_MODULE_LINKER_FLAGS" : module_flags })
304+
if "CMAKE_SHARED_LINKER_FLAGS" in cmake_definitions:
305+
shared_flags = util.Interpolate("%(kw:shared_flags)s %(kw:flags)s",
306+
shared_flags = shared_flags, flags = cmake_definitions["CMAKE_SHARED_LINKER_FLAGS"])
307+
cmake_definitions.update({ "CMAKE_SHARED_LINKER_FLAGS" : shared_flags })
240308

241309
f.addStep(
242310
steps.CMake(
@@ -248,7 +316,7 @@ def norm_target_list_arg(lst):
248316
description = ["CMake configure"],
249317
haltOnFailure = True,
250318
env = env,
251-
workdir = test_suite_workdir
319+
workdir = test_suite_obj_dir
252320
))
253321

254322
hint_suffix = f"-{hint}" if hint else ""
@@ -271,7 +339,7 @@ def norm_target_list_arg(lst):
271339
description = ["Build target", target_title],
272340
haltOnFailure = True,
273341
env = env,
274-
workdir = test_suite_workdir
342+
workdir = test_suite_obj_dir
275343
))
276344

277345
# Add a rsync step for each build target if the remote host has been specified
@@ -285,7 +353,7 @@ def norm_target_list_arg(lst):
285353
description = ["Rsync to target", target_title],
286354
haltOnFailure = True,
287355
env = env,
288-
workdir = test_suite_workdir
356+
workdir = test_suite_obj_dir
289357
))
290358

291359
# Check Commands.
@@ -299,7 +367,7 @@ def norm_target_list_arg(lst):
299367
descriptionDone = ["Running test:", target, "completed"],
300368
haltOnFailure = False, # We want to test as much as we could.
301369
env = env,
302-
workdir = test_suite_workdir
370+
workdir = test_suite_obj_dir
303371
))
304372

305373
return f

0 commit comments

Comments
 (0)