Skip to content

Commit e9a229d

Browse files
authored
Add helper function for the buildbot tests into zorg.buildbot.tests. (llvm#653)
Also added the initial tests for the TestSuiteBuilder.getLlvmTestSuiteSteps factory.
1 parent cf75a7a commit e9a229d

File tree

3 files changed

+121
-64
lines changed

3 files changed

+121
-64
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# RUN: python %s
2+
3+
# Lit Regression Tests for TestSuiteBuilder.getTestSuiteBuildFactory factory.
4+
5+
import sys
6+
7+
from buildbot.plugins import steps, util
8+
import buildbot.process.properties
9+
10+
import zorg
11+
from zorg.buildbot.builders import TestSuiteBuilder
12+
from zorg.buildbot.process.factory import LLVMBuildFactory
13+
14+
from zorg.buildbot.tests import factory_has_num_steps, factory_has_step, DEFAULT_ENV
15+
16+
f = TestSuiteBuilder.getLlvmTestSuiteSteps(
17+
cmake_definitions = {
18+
"CMAKE_C_COMPILER" : "/home/buildbot/worker/temp/build/bin/clang",
19+
"CMAKE_CXX_COMPILER" : "/home/buildbot/worker/temp/build/bin/clang++",
20+
"TEST_SUITE_LIT:FILEPATH" : "/home/buildbot/worker/temp/build/bin/llvm-lit",
21+
},
22+
hint = None,
23+
)
24+
25+
print(f"default factory: {f}\n")
26+
27+
assert factory_has_num_steps(f, 5)
28+
assert factory_has_step(f, "clean-src-dir")
29+
assert factory_has_step(f, "cmake-configure")
30+
assert factory_has_step(f, "build-default")
31+
assert not factory_has_step(f, "rsync-default")
32+
assert factory_has_step(f, "test-check")
33+
34+
f = TestSuiteBuilder.getLlvmTestSuiteSteps(
35+
cmake_definitions = {
36+
"TEST_SUITE_REMOTE_HOST" : "buildbot@arm64-linux-02",
37+
"TEST_SUITE_LIT_FLAGS" : "-v --threads=32 --time-tests",
38+
},
39+
compiler_dir = util.Interpolate("%(prop:builddir)s/build"),
40+
hint = None,
41+
)
42+
43+
print(f"default factory (compiler_dir): {f}\n")
44+
45+
assert factory_has_num_steps(f, 6)
46+
assert factory_has_step(f, "clean-src-dir")
47+
assert factory_has_step(f, "cmake-configure")
48+
assert factory_has_step(f, "build-default")
49+
assert factory_has_step(f, "rsync-default")
50+
assert factory_has_step(f, "test-check")

test/buildbot/builders/unified_cmakeex.py

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,12 @@
55
import sys
66

77
from buildbot.plugins import steps
8-
import buildbot.process.properties
98

109
import zorg
1110
from zorg.buildbot.builders import UnifiedTreeBuilder
1211
from zorg.buildbot.process.factory import LLVMBuildFactory
1312

14-
#Note:
15-
# - this function currently supports only %(kw:*)s formatting for the Interpolates.
16-
# - this function does not support the substitutions for arguments (such as '%(kw:arg:-)s' & etc).
17-
# - this function does not support the other types of the renderables except Interpolate
18-
# (such as WithProperties and os on).
19-
def partly_rendered(r):
20-
if isinstance(r, buildbot.process.properties.Interpolate):
21-
interpolations = {}
22-
for k, v in r.kwargs.items():
23-
interpolations[f"kw:{k}"] = v if v else ""
24-
return r.fmtstring % interpolations
25-
elif type(r) == str:
26-
return r
27-
28-
return "unsupported_rendering"
29-
30-
def factory_has_num_steps(f, expected_num):
31-
assert f
32-
if len(f.steps) != expected_num:
33-
print(f"error: factory_has_num_steps: {len(f.steps)}, expected {expected_num}")
34-
return len(f.steps) == expected_num
35-
36-
def factory_has_step(f, name, hasarg=None, contains=None):
37-
assert f
38-
assert name
39-
40-
result = False
41-
42-
for s in f.steps:
43-
v = partly_rendered(s.kwargs.get("name"))
44-
if v == name:
45-
result = True
46-
# check that the step has that argument
47-
arg_value = None
48-
if hasarg:
49-
if not hasarg in s.kwargs:
50-
print(f"error: step '{v}': missing expected step argument '{hasarg}'")
51-
return False
52-
53-
arg_value = s.kwargs.get(hasarg)
54-
55-
# Check for contained content if requested.
56-
if arg_value and contains:
57-
if type(contains) == type(arg_value) == dict:
58-
result = contains.items() <= arg_value.items()
59-
elif type(contains) == type(arg_value) == list:
60-
result = contains <= arg_value
61-
elif type(contains) == type(arg_value):
62-
result = contains == arg_value
63-
else:
64-
print(f"error: step '{v}', argument '{hasarg}': unsupported type to compare, expected is '{type(contains)}', actual is '{type(arg_value)}'")
65-
return False
66-
67-
if not result:
68-
print(f"error: step '{v}', argument '{hasarg}': expected\n\t{contains}\nactual:\n\t{arg_value}")
69-
70-
return result
71-
72-
print(f"error: missing expected step '{name}'")
73-
74-
return False
75-
76-
DEFAULT_ENV = {'TERM': 'dumb', 'NINJA_STATUS': '%e [%u/%r/%f] '}
13+
from zorg.buildbot.tests import factory_has_num_steps, factory_has_step, DEFAULT_ENV
7714

7815
# Use all defaults.
7916
f = UnifiedTreeBuilder.getCmakeExBuildFactory()

zorg/buildbot/tests/__init__.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- python -*-
2+
# ex: set filetype=python:
3+
4+
import buildbot.process.properties
5+
6+
__all__ = []
7+
8+
DEFAULT_ENV = {'TERM': 'dumb', 'NINJA_STATUS': '%e [%u/%r/%f] '}
9+
10+
#Note:
11+
# - this function currently supports only %(kw:*)s formatting for the Interpolates.
12+
# - this function does not support the substitutions for arguments (such as '%(kw:arg:-)s' & etc).
13+
# - this function does not support the other types of the renderables except Interpolate
14+
# (such as WithProperties and os on).
15+
def partly_rendered(r):
16+
if isinstance(r, buildbot.process.properties.Interpolate):
17+
interpolations = {}
18+
for k, v in r.kwargs.items():
19+
interpolations[f"kw:{k}"] = v if v else ""
20+
return r.fmtstring % interpolations
21+
elif type(r) == str:
22+
return r
23+
24+
return "unsupported_rendering"
25+
26+
def factory_has_num_steps(f, expected_num):
27+
assert f
28+
if len(f.steps) != expected_num:
29+
print(f"error: factory_has_num_steps: {len(f.steps)}, expected {expected_num}")
30+
return len(f.steps) == expected_num
31+
32+
def factory_has_step(f, name, hasarg=None, contains=None):
33+
assert f
34+
assert name
35+
36+
result = False
37+
38+
for s in f.steps:
39+
v = partly_rendered(s.kwargs.get("name"))
40+
if v == name:
41+
result = True
42+
# check that the step has that argument
43+
arg_value = None
44+
if hasarg:
45+
if not hasarg in s.kwargs:
46+
print(f"error: step '{v}': missing expected step argument '{hasarg}'")
47+
return False
48+
49+
arg_value = s.kwargs.get(hasarg)
50+
51+
# Check for contained content if requested.
52+
if arg_value and contains:
53+
if type(contains) == type(arg_value) == dict:
54+
result = contains.items() <= arg_value.items()
55+
elif type(contains) == type(arg_value) == list:
56+
result = contains <= arg_value
57+
elif type(contains) == type(arg_value):
58+
result = contains == arg_value
59+
else:
60+
print(f"error: step '{v}', argument '{hasarg}': unsupported type to compare, expected is '{type(contains)}', actual is '{type(arg_value)}'")
61+
return False
62+
63+
if not result:
64+
print(f"error: step '{v}', argument '{hasarg}': expected\n\t{contains}\nactual:\n\t{arg_value}")
65+
66+
return result
67+
68+
print(f"error: missing expected step '{name}'")
69+
70+
return False

0 commit comments

Comments
 (0)