From 4631ea1968e9db5302cee9122a360a9583d47270 Mon Sep 17 00:00:00 2001 From: Vladimir Vereschaka Date: Tue, 11 Nov 2025 13:58:25 -0800 Subject: [PATCH 1/2] Add helper function for the buildbot tests into zorg.buildbot.tests. Also added the initial tests for the testSuiteBuilder.getLlvmTestSuiteSteps factory. --- test/buildbot/builders/testsuite.py | 51 +++++++++++++++++ test/buildbot/builders/unified_cmakeex.py | 65 +-------------------- zorg/buildbot/tests/__init__.py | 70 +++++++++++++++++++++++ 3 files changed, 122 insertions(+), 64 deletions(-) create mode 100644 test/buildbot/builders/testsuite.py create mode 100644 zorg/buildbot/tests/__init__.py diff --git a/test/buildbot/builders/testsuite.py b/test/buildbot/builders/testsuite.py new file mode 100644 index 000000000..c765befc3 --- /dev/null +++ b/test/buildbot/builders/testsuite.py @@ -0,0 +1,51 @@ +# RUN: python %s + +# Lit Regression Tests for TestSuiteBuilder.getTestSuiteBuildFactory factory. + +import sys + +from buildbot.plugins import steps, util +import buildbot.process.properties + +import zorg +from zorg.buildbot.builders import TestSuiteBuilder +from zorg.buildbot.process.factory import LLVMBuildFactory + +from zorg.buildbot.tests import factory_has_num_steps, factory_has_step, DEFAULT_ENV + +f = TestSuiteBuilder.getLlvmTestSuiteSteps( + cmake_definitions = { + "CMAKE_C_COMPILER" : "/home/buildbot/worker/temp/build/bin/clang", + "CMAKE_CXX_COMPILER" : "/home/buildbot/worker/temp/build/bin/clang++", + "TEST_SUITE_LIT:FILEPATH" : "/home/buildbot/worker/temp/build/bin/llvm-lit", + }, + hint = None, + ) + +assert factory_has_num_steps(f, 5) +assert factory_has_step(f, "clean-src-dir") +assert factory_has_step(f, "cmake-configure") +assert factory_has_step(f, "build-default") +assert not factory_has_step(f, "rsync-default") +assert factory_has_step(f, "test-check") + + +print(f"default factory: {f}\n") + +f = TestSuiteBuilder.getLlvmTestSuiteSteps( + cmake_definitions = { + "TEST_SUITE_REMOTE_HOST" : "buildbot@arm64-linux-02", + "TEST_SUITE_LIT_FLAGS" : "-v --threads=32 --time-tests", + }, + compiler_dir = util.Interpolate("%(prop:builddir)s/build"), + hint = None, + ) + +print(f"default factory (compiler_dir): {f}\n") + +assert factory_has_num_steps(f, 6) +assert factory_has_step(f, "clean-src-dir") +assert factory_has_step(f, "cmake-configure") +assert factory_has_step(f, "build-default") +assert factory_has_step(f, "rsync-default") +assert factory_has_step(f, "test-check") diff --git a/test/buildbot/builders/unified_cmakeex.py b/test/buildbot/builders/unified_cmakeex.py index 7f93acf23..5bb2bca9a 100644 --- a/test/buildbot/builders/unified_cmakeex.py +++ b/test/buildbot/builders/unified_cmakeex.py @@ -5,75 +5,12 @@ import sys from buildbot.plugins import steps -import buildbot.process.properties import zorg from zorg.buildbot.builders import UnifiedTreeBuilder from zorg.buildbot.process.factory import LLVMBuildFactory -#Note: -# - this function currently supports only %(kw:*)s formatting for the Interpolates. -# - this function does not support the substitutions for arguments (such as '%(kw:arg:-)s' & etc). -# - this function does not support the other types of the renderables except Interpolate -# (such as WithProperties and os on). -def partly_rendered(r): - if isinstance(r, buildbot.process.properties.Interpolate): - interpolations = {} - for k, v in r.kwargs.items(): - interpolations[f"kw:{k}"] = v if v else "" - return r.fmtstring % interpolations - elif type(r) == str: - return r - - return "unsupported_rendering" - -def factory_has_num_steps(f, expected_num): - assert f - if len(f.steps) != expected_num: - print(f"error: factory_has_num_steps: {len(f.steps)}, expected {expected_num}") - return len(f.steps) == expected_num - -def factory_has_step(f, name, hasarg=None, contains=None): - assert f - assert name - - result = False - - for s in f.steps: - v = partly_rendered(s.kwargs.get("name")) - if v == name: - result = True - # check that the step has that argument - arg_value = None - if hasarg: - if not hasarg in s.kwargs: - print(f"error: step '{v}': missing expected step argument '{hasarg}'") - return False - - arg_value = s.kwargs.get(hasarg) - - # Check for contained content if requested. - if arg_value and contains: - if type(contains) == type(arg_value) == dict: - result = contains.items() <= arg_value.items() - elif type(contains) == type(arg_value) == list: - result = contains <= arg_value - elif type(contains) == type(arg_value): - result = contains == arg_value - else: - print(f"error: step '{v}', argument '{hasarg}': unsupported type to compare, expected is '{type(contains)}', actual is '{type(arg_value)}'") - return False - - if not result: - print(f"error: step '{v}', argument '{hasarg}': expected\n\t{contains}\nactual:\n\t{arg_value}") - - return result - - print(f"error: missing expected step '{name}'") - - return False - -DEFAULT_ENV = {'TERM': 'dumb', 'NINJA_STATUS': '%e [%u/%r/%f] '} +from zorg.buildbot.tests import factory_has_num_steps, factory_has_step, DEFAULT_ENV # Use all defaults. f = UnifiedTreeBuilder.getCmakeExBuildFactory() diff --git a/zorg/buildbot/tests/__init__.py b/zorg/buildbot/tests/__init__.py new file mode 100644 index 000000000..d05b97eeb --- /dev/null +++ b/zorg/buildbot/tests/__init__.py @@ -0,0 +1,70 @@ +# -*- python -*- +# ex: set filetype=python: + +import buildbot.process.properties + +__all__ = [] + +DEFAULT_ENV = {'TERM': 'dumb', 'NINJA_STATUS': '%e [%u/%r/%f] '} + +#Note: +# - this function currently supports only %(kw:*)s formatting for the Interpolates. +# - this function does not support the substitutions for arguments (such as '%(kw:arg:-)s' & etc). +# - this function does not support the other types of the renderables except Interpolate +# (such as WithProperties and os on). +def partly_rendered(r): + if isinstance(r, buildbot.process.properties.Interpolate): + interpolations = {} + for k, v in r.kwargs.items(): + interpolations[f"kw:{k}"] = v if v else "" + return r.fmtstring % interpolations + elif type(r) == str: + return r + + return "unsupported_rendering" + +def factory_has_num_steps(f, expected_num): + assert f + if len(f.steps) != expected_num: + print(f"error: factory_has_num_steps: {len(f.steps)}, expected {expected_num}") + return len(f.steps) == expected_num + +def factory_has_step(f, name, hasarg=None, contains=None): + assert f + assert name + + result = False + + for s in f.steps: + v = partly_rendered(s.kwargs.get("name")) + if v == name: + result = True + # check that the step has that argument + arg_value = None + if hasarg: + if not hasarg in s.kwargs: + print(f"error: step '{v}': missing expected step argument '{hasarg}'") + return False + + arg_value = s.kwargs.get(hasarg) + + # Check for contained content if requested. + if arg_value and contains: + if type(contains) == type(arg_value) == dict: + result = contains.items() <= arg_value.items() + elif type(contains) == type(arg_value) == list: + result = contains <= arg_value + elif type(contains) == type(arg_value): + result = contains == arg_value + else: + print(f"error: step '{v}', argument '{hasarg}': unsupported type to compare, expected is '{type(contains)}', actual is '{type(arg_value)}'") + return False + + if not result: + print(f"error: step '{v}', argument '{hasarg}': expected\n\t{contains}\nactual:\n\t{arg_value}") + + return result + + print(f"error: missing expected step '{name}'") + + return False From 72d2a4519eca53c6367658d2a08fb04b44093a8f Mon Sep 17 00:00:00 2001 From: Vladimir Vereschaka Date: Thu, 13 Nov 2025 17:02:45 -0800 Subject: [PATCH 2/2] Move the factory dump before the asserts. --- test/buildbot/builders/testsuite.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/buildbot/builders/testsuite.py b/test/buildbot/builders/testsuite.py index c765befc3..f036b21c5 100644 --- a/test/buildbot/builders/testsuite.py +++ b/test/buildbot/builders/testsuite.py @@ -22,6 +22,8 @@ hint = None, ) +print(f"default factory: {f}\n") + assert factory_has_num_steps(f, 5) assert factory_has_step(f, "clean-src-dir") assert factory_has_step(f, "cmake-configure") @@ -29,9 +31,6 @@ assert not factory_has_step(f, "rsync-default") assert factory_has_step(f, "test-check") - -print(f"default factory: {f}\n") - f = TestSuiteBuilder.getLlvmTestSuiteSteps( cmake_definitions = { "TEST_SUITE_REMOTE_HOST" : "buildbot@arm64-linux-02",