Joshua Hood | 3455e135 | 2022-03-03 23:23:59 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
Avi Drissman | dfd88085 | 2022-09-15 20:11:09 | [diff] [blame] | 2 | # Copyright 2016 The Chromium Authors |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Script to generate the majority of the JSON files in the src/testing/buildbot |
| 7 | directory. Maintaining these files by hand is too unwieldy. |
| 8 | """ |
| 9 | |
| 10 | import argparse |
| 11 | import ast |
| 12 | import collections |
| 13 | import copy |
John Budorick | 826d5ed | 2017-12-28 19:27:32 | [diff] [blame] | 14 | import difflib |
Garrett Beaty | d5ca7596 | 2020-05-07 16:58:31 | [diff] [blame] | 15 | import glob |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 16 | import itertools |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 17 | import json |
| 18 | import os |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 19 | import string |
| 20 | import sys |
| 21 | |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 22 | import buildbot_json_magic_substitutions as magic_substitutions |
| 23 | |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 24 | # pylint: disable=super-with-arguments,useless-super-delegation |
| 25 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 26 | THIS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 27 | |
Brian Sheedy | f74819b | 2021-06-04 01:38:38 | [diff] [blame] | 28 | BROWSER_CONFIG_TO_TARGET_SUFFIX_MAP = { |
| 29 | 'android-chromium': '_android_chrome', |
| 30 | 'android-chromium-monochrome': '_android_monochrome', |
Brian Sheedy | f74819b | 2021-06-04 01:38:38 | [diff] [blame] | 31 | 'android-webview': '_android_webview', |
| 32 | } |
| 33 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 34 | |
| 35 | class BBGenErr(Exception): |
Nico Weber | 79dc5f685 | 2018-07-13 19:38:49 | [diff] [blame] | 36 | def __init__(self, message): |
| 37 | super(BBGenErr, self).__init__(message) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 38 | |
| 39 | |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 40 | class BaseGenerator(object): # pylint: disable=useless-object-inheritance |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 41 | def __init__(self, bb_gen): |
| 42 | self.bb_gen = bb_gen |
| 43 | |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 44 | def generate(self, waterfall, tester_name, tester_config, input_tests): |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 45 | raise NotImplementedError() # pragma: no cover |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 46 | |
| 47 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 48 | class GPUTelemetryTestGenerator(BaseGenerator): |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 49 | def __init__(self, bb_gen, is_android_webview=False, is_cast_streaming=False): |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 50 | super(GPUTelemetryTestGenerator, self).__init__(bb_gen) |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 51 | self._is_android_webview = is_android_webview |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 52 | self._is_cast_streaming = is_cast_streaming |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 53 | |
| 54 | def generate(self, waterfall, tester_name, tester_config, input_tests): |
| 55 | isolated_scripts = [] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 56 | for test_name, test_config in sorted(input_tests.items()): |
Ben Pastene | 8e7eb265 | 2022-04-29 19:44:31 | [diff] [blame] | 57 | # Variants allow more than one definition for a given test, and is defined |
| 58 | # in array format from resolve_variants(). |
| 59 | if not isinstance(test_config, list): |
| 60 | test_config = [test_config] |
| 61 | |
| 62 | for config in test_config: |
| 63 | test = self.bb_gen.generate_gpu_telemetry_test(waterfall, tester_name, |
| 64 | tester_config, test_name, |
| 65 | config, |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 66 | self._is_android_webview, |
| 67 | self._is_cast_streaming) |
Ben Pastene | 8e7eb265 | 2022-04-29 19:44:31 | [diff] [blame] | 68 | if test: |
| 69 | isolated_scripts.append(test) |
| 70 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 71 | return isolated_scripts |
| 72 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 73 | |
Brian Sheedy | b6491ba | 2022-09-26 20:49:49 | [diff] [blame] | 74 | class SkylabGPUTelemetryTestGenerator(GPUTelemetryTestGenerator): |
| 75 | def generate(self, *args, **kwargs): |
| 76 | # This should be identical to a regular GPU Telemetry test, but with any |
| 77 | # swarming arguments removed. |
| 78 | isolated_scripts = super(SkylabGPUTelemetryTestGenerator, |
| 79 | self).generate(*args, **kwargs) |
| 80 | for test in isolated_scripts: |
Xinan Lin | d9b1d2e7 | 2022-11-14 20:57:02 | [diff] [blame] | 81 | # chromium_GPU is the Autotest wrapper created for browser GPU tests |
| 82 | # run in Skylab. |
Xinan Lin | 1f28a0d | 2023-03-13 17:39:41 | [diff] [blame] | 83 | test['autotest_name'] = 'chromium_Graphics' |
Xinan Lin | d9b1d2e7 | 2022-11-14 20:57:02 | [diff] [blame] | 84 | # As of 22Q4, Skylab tests are running on a CrOS flavored Autotest |
| 85 | # framework and it does not support the sub-args like |
| 86 | # extra-browser-args. So we have to pop it out and create a new |
| 87 | # key for it. See crrev.com/c/3965359 for details. |
| 88 | for idx, arg in enumerate(test.get('args', [])): |
| 89 | if '--extra-browser-args' in arg: |
| 90 | test['args'].pop(idx) |
| 91 | test['extra_browser_args'] = arg.replace('--extra-browser-args=', '') |
| 92 | break |
Brian Sheedy | b6491ba | 2022-09-26 20:49:49 | [diff] [blame] | 93 | return isolated_scripts |
| 94 | |
| 95 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 96 | class GTestGenerator(BaseGenerator): |
| 97 | def __init__(self, bb_gen): |
| 98 | super(GTestGenerator, self).__init__(bb_gen) |
| 99 | |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 100 | def generate(self, waterfall, tester_name, tester_config, input_tests): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 101 | # The relative ordering of some of the tests is important to |
| 102 | # minimize differences compared to the handwritten JSON files, since |
| 103 | # Python's sorts are stable and there are some tests with the same |
| 104 | # key (see gles2_conform_d3d9_test and similar variants). Avoid |
| 105 | # losing the order by avoiding coalescing the dictionaries into one. |
| 106 | gtests = [] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 107 | for test_name, test_config in sorted(input_tests.items()): |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 108 | # Variants allow more than one definition for a given test, and is defined |
| 109 | # in array format from resolve_variants(). |
| 110 | if not isinstance(test_config, list): |
| 111 | test_config = [test_config] |
| 112 | |
| 113 | for config in test_config: |
| 114 | test = self.bb_gen.generate_gtest( |
| 115 | waterfall, tester_name, tester_config, test_name, config) |
| 116 | if test: |
| 117 | # generate_gtest may veto the test generation on this tester. |
| 118 | gtests.append(test) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 119 | return gtests |
| 120 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 121 | |
| 122 | class IsolatedScriptTestGenerator(BaseGenerator): |
| 123 | def __init__(self, bb_gen): |
| 124 | super(IsolatedScriptTestGenerator, self).__init__(bb_gen) |
| 125 | |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 126 | def generate(self, waterfall, tester_name, tester_config, input_tests): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 127 | isolated_scripts = [] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 128 | for test_name, test_config in sorted(input_tests.items()): |
Jeff Yoon | b8bfdbf3 | 2020-03-13 19:14:43 | [diff] [blame] | 129 | # Variants allow more than one definition for a given test, and is defined |
| 130 | # in array format from resolve_variants(). |
| 131 | if not isinstance(test_config, list): |
| 132 | test_config = [test_config] |
| 133 | |
| 134 | for config in test_config: |
| 135 | test = self.bb_gen.generate_isolated_script_test( |
| 136 | waterfall, tester_name, tester_config, test_name, config) |
| 137 | if test: |
| 138 | isolated_scripts.append(test) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 139 | return isolated_scripts |
| 140 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 141 | |
| 142 | class ScriptGenerator(BaseGenerator): |
| 143 | def __init__(self, bb_gen): |
| 144 | super(ScriptGenerator, self).__init__(bb_gen) |
| 145 | |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 146 | def generate(self, waterfall, tester_name, tester_config, input_tests): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 147 | scripts = [] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 148 | for test_name, test_config in sorted(input_tests.items()): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 149 | test = self.bb_gen.generate_script_test( |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 150 | waterfall, tester_name, tester_config, test_name, test_config) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 151 | if test: |
| 152 | scripts.append(test) |
| 153 | return scripts |
| 154 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 155 | |
| 156 | class JUnitGenerator(BaseGenerator): |
| 157 | def __init__(self, bb_gen): |
| 158 | super(JUnitGenerator, self).__init__(bb_gen) |
| 159 | |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 160 | def generate(self, waterfall, tester_name, tester_config, input_tests): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 161 | scripts = [] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 162 | for test_name, test_config in sorted(input_tests.items()): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 163 | test = self.bb_gen.generate_junit_test( |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 164 | waterfall, tester_name, tester_config, test_name, test_config) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 165 | if test: |
| 166 | scripts.append(test) |
| 167 | return scripts |
| 168 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 169 | |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 170 | class SkylabGenerator(BaseGenerator): |
| 171 | def __init__(self, bb_gen): |
| 172 | super(SkylabGenerator, self).__init__(bb_gen) |
| 173 | |
| 174 | def generate(self, waterfall, tester_name, tester_config, input_tests): |
| 175 | scripts = [] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 176 | for test_name, test_config in sorted(input_tests.items()): |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 177 | for config in test_config: |
| 178 | test = self.bb_gen.generate_skylab_test(waterfall, tester_name, |
| 179 | tester_config, test_name, |
| 180 | config) |
| 181 | if test: |
| 182 | scripts.append(test) |
| 183 | return scripts |
| 184 | |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 185 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 186 | def check_compound_references(other_test_suites=None, |
| 187 | sub_suite=None, |
| 188 | suite=None, |
| 189 | target_test_suites=None, |
| 190 | test_type=None, |
| 191 | **kwargs): |
| 192 | """Ensure comound reference's don't target other compounds""" |
| 193 | del kwargs |
| 194 | if sub_suite in other_test_suites or sub_suite in target_test_suites: |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 195 | raise BBGenErr('%s may not refer to other composition type test ' |
| 196 | 'suites (error found while processing %s)' % |
| 197 | (test_type, suite)) |
| 198 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 199 | |
| 200 | def check_basic_references(basic_suites=None, |
| 201 | sub_suite=None, |
| 202 | suite=None, |
| 203 | **kwargs): |
| 204 | """Ensure test has a basic suite reference""" |
| 205 | del kwargs |
| 206 | if sub_suite not in basic_suites: |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 207 | raise BBGenErr('Unable to find reference to %s while processing %s' % |
| 208 | (sub_suite, suite)) |
| 209 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 210 | |
| 211 | def check_conflicting_definitions(basic_suites=None, |
| 212 | seen_tests=None, |
| 213 | sub_suite=None, |
| 214 | suite=None, |
| 215 | test_type=None, |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 216 | target_test_suites=None, |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 217 | **kwargs): |
| 218 | """Ensure that if a test is reachable via multiple basic suites, |
| 219 | all of them have an identical definition of the tests. |
| 220 | """ |
| 221 | del kwargs |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 222 | variants = None |
| 223 | if test_type == 'matrix_compound_suites': |
| 224 | variants = target_test_suites[suite][sub_suite].get('variants') |
| 225 | variants = variants or [None] |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 226 | for test_name in basic_suites[sub_suite]: |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 227 | for variant in variants: |
| 228 | key = (test_name, variant) |
| 229 | if ((seen_sub_suite := seen_tests.get(key)) is not None |
| 230 | and basic_suites[sub_suite][test_name] != |
| 231 | basic_suites[seen_sub_suite][test_name]): |
| 232 | test_description = (test_name if variant is None else |
| 233 | f'{test_name} with variant {variant} applied') |
| 234 | raise BBGenErr( |
| 235 | 'Conflicting test definitions for %s from %s ' |
| 236 | 'and %s in %s (error found while processing %s)' % |
| 237 | (test_description, seen_tests[key], sub_suite, test_type, suite)) |
| 238 | seen_tests[key] = sub_suite |
| 239 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 240 | |
| 241 | def check_matrix_identifier(sub_suite=None, |
| 242 | suite=None, |
| 243 | suite_def=None, |
Jeff Yoon | da581c3 | 2020-03-06 03:56:05 | [diff] [blame] | 244 | all_variants=None, |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 245 | **kwargs): |
| 246 | """Ensure 'idenfitier' is defined for each variant""" |
| 247 | del kwargs |
| 248 | sub_suite_config = suite_def[sub_suite] |
Garrett Beaty | 2022db4 | 2023-08-29 17:22:40 | [diff] [blame] | 249 | for variant_name in sub_suite_config.get('variants', []): |
| 250 | if variant_name not in all_variants: |
| 251 | raise BBGenErr('Missing variant definition for %s in variants.pyl' % |
| 252 | variant_name) |
| 253 | variant = all_variants[variant_name] |
Jeff Yoon | da581c3 | 2020-03-06 03:56:05 | [diff] [blame] | 254 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 255 | if not 'identifier' in variant: |
| 256 | raise BBGenErr('Missing required identifier field in matrix ' |
| 257 | 'compound suite %s, %s' % (suite, sub_suite)) |
Sven Zheng | ef0d087 | 2022-04-04 22:13:29 | [diff] [blame] | 258 | if variant['identifier'] == '': |
| 259 | raise BBGenErr('Identifier field can not be "" in matrix ' |
| 260 | 'compound suite %s, %s' % (suite, sub_suite)) |
| 261 | if variant['identifier'].strip() != variant['identifier']: |
| 262 | raise BBGenErr('Identifier field can not have leading and trailing ' |
| 263 | 'whitespace in matrix compound suite %s, %s' % |
| 264 | (suite, sub_suite)) |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 265 | |
| 266 | |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 267 | class BBJSONGenerator(object): # pylint: disable=useless-object-inheritance |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 268 | def __init__(self, args): |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 269 | self.args = args |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 270 | self.waterfalls = None |
| 271 | self.test_suites = None |
| 272 | self.exceptions = None |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 273 | self.mixins = None |
Nodir Turakulov | fce3429 | 2019-12-18 17:05:41 | [diff] [blame] | 274 | self.gn_isolate_map = None |
Jeff Yoon | da581c3 | 2020-03-06 03:56:05 | [diff] [blame] | 275 | self.variants = None |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 276 | |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 277 | @staticmethod |
| 278 | def parse_args(argv): |
| 279 | |
| 280 | # RawTextHelpFormatter allows for styling of help statement |
| 281 | parser = argparse.ArgumentParser( |
| 282 | formatter_class=argparse.RawTextHelpFormatter) |
| 283 | |
| 284 | group = parser.add_mutually_exclusive_group() |
| 285 | group.add_argument( |
| 286 | '-c', |
| 287 | '--check', |
| 288 | action='store_true', |
| 289 | help= |
| 290 | 'Do consistency checks of configuration and generated files and then ' |
| 291 | 'exit. Used during presubmit. ' |
| 292 | 'Causes the tool to not generate any files.') |
| 293 | group.add_argument( |
| 294 | '--query', |
| 295 | type=str, |
| 296 | help=( |
| 297 | "Returns raw JSON information of buildbots and tests.\n" + |
| 298 | "Examples:\n" + " List all bots (all info):\n" + |
| 299 | " --query bots\n\n" + |
| 300 | " List all bots and only their associated tests:\n" + |
| 301 | " --query bots/tests\n\n" + |
| 302 | " List all information about 'bot1' " + |
| 303 | "(make sure you have quotes):\n" + " --query bot/'bot1'\n\n" + |
| 304 | " List tests running for 'bot1' (make sure you have quotes):\n" + |
| 305 | " --query bot/'bot1'/tests\n\n" + " List all tests:\n" + |
| 306 | " --query tests\n\n" + |
| 307 | " List all tests and the bots running them:\n" + |
| 308 | " --query tests/bots\n\n" + |
| 309 | " List all tests that satisfy multiple parameters\n" + |
| 310 | " (separation of parameters by '&' symbol):\n" + |
| 311 | " --query tests/'device_os:Android&device_type:hammerhead'\n\n" + |
| 312 | " List all tests that run with a specific flag:\n" + |
| 313 | " --query bots/'--test-launcher-print-test-studio=always'\n\n" + |
| 314 | " List specific test (make sure you have quotes):\n" |
| 315 | " --query test/'test1'\n\n" |
| 316 | " List all bots running 'test1' " + |
| 317 | "(make sure you have quotes):\n" + " --query test/'test1'/bots")) |
| 318 | parser.add_argument( |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 319 | '--json', |
| 320 | metavar='JSON_FILE_PATH', |
| 321 | type=os.path.abspath, |
| 322 | help='Outputs results into a json file. Only works with query function.' |
| 323 | ) |
| 324 | parser.add_argument( |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 325 | '-n', |
| 326 | '--new-files', |
| 327 | action='store_true', |
| 328 | help= |
| 329 | 'Write output files as .new.json. Useful during development so old and ' |
| 330 | 'new files can be looked at side-by-side.') |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 331 | parser.add_argument('--dimension-sets-handling', |
| 332 | choices=['disable'], |
| 333 | default='disable', |
| 334 | help=('This flag no longer has any effect:' |
| 335 | ' dimension_sets fields are not allowed')) |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 336 | parser.add_argument('-v', |
| 337 | '--verbose', |
| 338 | action='store_true', |
| 339 | help='Increases verbosity. Affects consistency checks.') |
| 340 | parser.add_argument('waterfall_filters', |
| 341 | metavar='waterfalls', |
| 342 | type=str, |
| 343 | nargs='*', |
| 344 | help='Optional list of waterfalls to generate.') |
| 345 | parser.add_argument( |
| 346 | '--pyl-files-dir', |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 347 | type=os.path.abspath, |
| 348 | help=('Path to the directory containing the input .pyl files.' |
| 349 | ' By default the directory containing this script will be used.')) |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 350 | parser.add_argument( |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 351 | '--output-dir', |
| 352 | type=os.path.abspath, |
| 353 | help=('Path to the directory to output generated .json files.' |
| 354 | 'By default, the pyl files directory will be used.')) |
Chong Gu | ee62224 | 2020-10-28 18:17:35 | [diff] [blame] | 355 | parser.add_argument('--isolate-map-file', |
| 356 | metavar='PATH', |
| 357 | help='path to additional isolate map files.', |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 358 | type=os.path.abspath, |
Chong Gu | ee62224 | 2020-10-28 18:17:35 | [diff] [blame] | 359 | default=[], |
| 360 | action='append', |
| 361 | dest='isolate_map_files') |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 362 | parser.add_argument( |
| 363 | '--infra-config-dir', |
| 364 | help='Path to the LUCI services configuration directory', |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 365 | type=os.path.abspath, |
| 366 | default=os.path.join(os.path.dirname(__file__), '..', '..', 'infra', |
| 367 | 'config')) |
| 368 | |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 369 | args = parser.parse_args(argv) |
| 370 | if args.json and not args.query: |
| 371 | parser.error( |
| 372 | "The --json flag can only be used with --query.") # pragma: no cover |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 373 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 374 | args.pyl_files_dir = args.pyl_files_dir or THIS_DIR |
| 375 | args.output_dir = args.output_dir or args.pyl_files_dir |
| 376 | |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 377 | def absolute_file_path(filename): |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 378 | return os.path.join(args.pyl_files_dir, filename) |
| 379 | |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 380 | args.waterfalls_pyl_path = absolute_file_path('waterfalls.pyl') |
Garrett Beaty | 96802d0 | 2023-07-07 14:18:05 | [diff] [blame] | 381 | args.mixins_pyl_path = absolute_file_path('mixins.pyl') |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 382 | args.test_suites_pyl_path = absolute_file_path('test_suites.pyl') |
| 383 | args.test_suite_exceptions_pyl_path = absolute_file_path( |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 384 | 'test_suite_exceptions.pyl') |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 385 | args.gn_isolate_map_pyl_path = absolute_file_path('gn_isolate_map.pyl') |
| 386 | args.variants_pyl_path = absolute_file_path('variants.pyl') |
| 387 | args.autoshard_exceptions_json_path = absolute_file_path( |
| 388 | 'autoshard_exceptions.json') |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 389 | |
| 390 | return args |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 391 | |
Stephen Martinis | 7eb8b61 | 2018-09-21 00:17:50 | [diff] [blame] | 392 | def print_line(self, line): |
| 393 | # Exists so that tests can mock |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 394 | print(line) # pragma: no cover |
Stephen Martinis | 7eb8b61 | 2018-09-21 00:17:50 | [diff] [blame] | 395 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 396 | def read_file(self, relative_path): |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 397 | with open(relative_path) as fp: |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 398 | return fp.read() |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 399 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 400 | def write_file(self, file_path, contents): |
Peter Kasting | acd55c1 | 2023-08-23 20:19:04 | [diff] [blame] | 401 | with open(file_path, 'w', newline='') as fp: |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 402 | fp.write(contents) |
Zhiling Huang | be00817 | 2018-03-08 19:13:11 | [diff] [blame] | 403 | |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 404 | # pylint: disable=inconsistent-return-statements |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 405 | def load_pyl_file(self, pyl_file_path): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 406 | try: |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 407 | return ast.literal_eval(self.read_file(pyl_file_path)) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 408 | except (SyntaxError, ValueError) as e: # pragma: no cover |
Josip Sokcevic | 7110fb38 | 2023-06-06 01:05:29 | [diff] [blame] | 409 | raise BBGenErr('Failed to parse pyl file "%s": %s' % |
| 410 | (pyl_file_path, e)) from e |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 411 | # pylint: enable=inconsistent-return-statements |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 412 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 413 | # TOOD(kbr): require that os_type be specified for all bots in waterfalls.pyl. |
| 414 | # Currently it is only mandatory for bots which run GPU tests. Change these to |
| 415 | # use [] instead of .get(). |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 416 | def is_android(self, tester_config): |
| 417 | return tester_config.get('os_type') == 'android' |
| 418 | |
Ben Pastene | a9e583b | 2019-01-16 02:57:26 | [diff] [blame] | 419 | def is_chromeos(self, tester_config): |
| 420 | return tester_config.get('os_type') == 'chromeos' |
| 421 | |
Chong Gu | c2ca5d0 | 2022-01-11 19:52:17 | [diff] [blame] | 422 | def is_fuchsia(self, tester_config): |
| 423 | return tester_config.get('os_type') == 'fuchsia' |
| 424 | |
Brian Sheedy | 781c8ca4 | 2021-03-08 22:03:21 | [diff] [blame] | 425 | def is_lacros(self, tester_config): |
| 426 | return tester_config.get('os_type') == 'lacros' |
| 427 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 428 | def is_linux(self, tester_config): |
| 429 | return tester_config.get('os_type') == 'linux' |
| 430 | |
Kai Ninomiya | 40de9f5 | 2019-10-18 21:38:49 | [diff] [blame] | 431 | def is_mac(self, tester_config): |
| 432 | return tester_config.get('os_type') == 'mac' |
| 433 | |
| 434 | def is_win(self, tester_config): |
| 435 | return tester_config.get('os_type') == 'win' |
| 436 | |
| 437 | def is_win64(self, tester_config): |
| 438 | return (tester_config.get('os_type') == 'win' and |
| 439 | tester_config.get('browser_config') == 'release_x64') |
| 440 | |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 441 | def get_exception_for_test(self, test_config): |
| 442 | return self.exceptions.get(test_config['name']) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 443 | |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 444 | def should_run_on_tester(self, waterfall, tester_name, test_config): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 445 | # Currently, the only reason a test should not run on a given tester is that |
| 446 | # it's in the exceptions. (Once the GPU waterfall generation script is |
| 447 | # incorporated here, the rules will become more complex.) |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 448 | exception = self.get_exception_for_test(test_config) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 449 | if not exception: |
| 450 | return True |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 451 | remove_from = None |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 452 | remove_from = exception.get('remove_from') |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 453 | if remove_from: |
| 454 | if tester_name in remove_from: |
| 455 | return False |
| 456 | # TODO(kbr): this code path was added for some tests (including |
| 457 | # android_webview_unittests) on one machine (Nougat Phone |
| 458 | # Tester) which exists with the same name on two waterfalls, |
| 459 | # chromium.android and chromium.fyi; the tests are run on one |
| 460 | # but not the other. Once the bots are all uniquely named (a |
| 461 | # different ongoing project) this code should be removed. |
| 462 | # TODO(kbr): add coverage. |
| 463 | return (tester_name + ' ' + waterfall['name'] |
| 464 | not in remove_from) # pragma: no cover |
| 465 | return True |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 466 | |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 467 | def get_test_modifications(self, test, tester_name): |
| 468 | exception = self.get_exception_for_test(test) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 469 | if not exception: |
| 470 | return None |
Nico Weber | 79dc5f685 | 2018-07-13 19:38:49 | [diff] [blame] | 471 | return exception.get('modifications', {}).get(tester_name) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 472 | |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 473 | def get_test_replacements(self, test, tester_name): |
| 474 | exception = self.get_exception_for_test(test) |
Brian Sheedy | e6ea0ee | 2019-07-11 02:54:37 | [diff] [blame] | 475 | if not exception: |
| 476 | return None |
| 477 | return exception.get('replacements', {}).get(tester_name) |
| 478 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 479 | def merge_command_line_args(self, arr, prefix, splitter): |
| 480 | prefix_len = len(prefix) |
Kenneth Russell | 650995a | 2018-05-03 21:17:01 | [diff] [blame] | 481 | idx = 0 |
| 482 | first_idx = -1 |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 483 | accumulated_args = [] |
Kenneth Russell | 650995a | 2018-05-03 21:17:01 | [diff] [blame] | 484 | while idx < len(arr): |
| 485 | flag = arr[idx] |
| 486 | delete_current_entry = False |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 487 | if flag.startswith(prefix): |
| 488 | arg = flag[prefix_len:] |
| 489 | accumulated_args.extend(arg.split(splitter)) |
Kenneth Russell | 650995a | 2018-05-03 21:17:01 | [diff] [blame] | 490 | if first_idx < 0: |
| 491 | first_idx = idx |
| 492 | else: |
| 493 | delete_current_entry = True |
| 494 | if delete_current_entry: |
| 495 | del arr[idx] |
| 496 | else: |
| 497 | idx += 1 |
| 498 | if first_idx >= 0: |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 499 | arr[first_idx] = prefix + splitter.join(accumulated_args) |
| 500 | return arr |
| 501 | |
| 502 | def maybe_fixup_args_array(self, arr): |
| 503 | # The incoming array of strings may be an array of command line |
| 504 | # arguments. To make it easier to turn on certain features per-bot or |
| 505 | # per-test-suite, look specifically for certain flags and merge them |
| 506 | # appropriately. |
| 507 | # --enable-features=Feature1 --enable-features=Feature2 |
| 508 | # are merged to: |
| 509 | # --enable-features=Feature1,Feature2 |
| 510 | # and: |
| 511 | # --extra-browser-args=arg1 --extra-browser-args=arg2 |
| 512 | # are merged to: |
| 513 | # --extra-browser-args=arg1 arg2 |
| 514 | arr = self.merge_command_line_args(arr, '--enable-features=', ',') |
| 515 | arr = self.merge_command_line_args(arr, '--extra-browser-args=', ' ') |
Yuly Novikov | 8c487e7 | 2020-10-16 20:00:29 | [diff] [blame] | 516 | arr = self.merge_command_line_args(arr, '--test-launcher-filter-file=', ';') |
Cameron Higgins | 971f0b9 | 2023-01-03 18:05:09 | [diff] [blame] | 517 | arr = self.merge_command_line_args(arr, '--extra-app-args=', ',') |
Kenneth Russell | 650995a | 2018-05-03 21:17:01 | [diff] [blame] | 518 | return arr |
| 519 | |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 520 | def substitute_magic_args(self, test_config, tester_name, tester_config): |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 521 | """Substitutes any magic substitution args present in |test_config|. |
| 522 | |
| 523 | Substitutions are done in-place. |
| 524 | |
| 525 | See buildbot_json_magic_substitutions.py for more information on this |
| 526 | feature. |
| 527 | |
| 528 | Args: |
| 529 | test_config: A dict containing a configuration for a specific test on |
| 530 | a specific builder, e.g. the output of update_and_cleanup_test. |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 531 | tester_name: A string containing the name of the tester that |test_config| |
| 532 | came from. |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 533 | tester_config: A dict containing the configuration for the builder that |
| 534 | |test_config| is for. |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 535 | """ |
| 536 | substituted_array = [] |
Brian Sheedy | ba13cf52 | 2022-09-13 21:00:09 | [diff] [blame] | 537 | original_args = test_config.get('args', []) |
| 538 | for arg in original_args: |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 539 | if arg.startswith(magic_substitutions.MAGIC_SUBSTITUTION_PREFIX): |
| 540 | function = arg.replace( |
| 541 | magic_substitutions.MAGIC_SUBSTITUTION_PREFIX, '') |
| 542 | if hasattr(magic_substitutions, function): |
| 543 | substituted_array.extend( |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 544 | getattr(magic_substitutions, function)(test_config, tester_name, |
| 545 | tester_config)) |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 546 | else: |
| 547 | raise BBGenErr( |
| 548 | 'Magic substitution function %s does not exist' % function) |
| 549 | else: |
| 550 | substituted_array.append(arg) |
Brian Sheedy | ba13cf52 | 2022-09-13 21:00:09 | [diff] [blame] | 551 | if substituted_array != original_args: |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 552 | test_config['args'] = self.maybe_fixup_args_array(substituted_array) |
| 553 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 554 | def dictionary_merge(self, a, b, path=None): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 555 | """http://stackoverflow.com/questions/7204805/ |
| 556 | python-dictionaries-of-dictionaries-merge |
| 557 | merges b into a |
| 558 | """ |
| 559 | if path is None: |
| 560 | path = [] |
| 561 | for key in b: |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 562 | if key not in a: |
| 563 | if b[key] is not None: |
| 564 | a[key] = b[key] |
| 565 | continue |
| 566 | |
| 567 | if isinstance(a[key], dict) and isinstance(b[key], dict): |
| 568 | self.dictionary_merge(a[key], b[key], path + [str(key)]) |
| 569 | elif a[key] == b[key]: |
| 570 | pass # same leaf value |
| 571 | elif isinstance(a[key], list) and isinstance(b[key], list): |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 572 | a[key] = a[key] + b[key] |
| 573 | if key.endswith('args'): |
| 574 | a[key] = self.maybe_fixup_args_array(a[key]) |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 575 | elif b[key] is None: |
| 576 | del a[key] |
| 577 | else: |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 578 | a[key] = b[key] |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 579 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 580 | return a |
| 581 | |
John Budorick | ab10871 | 2018-09-01 00:12:21 | [diff] [blame] | 582 | def initialize_args_for_test( |
| 583 | self, generated_test, tester_config, additional_arg_keys=None): |
John Budorick | ab10871 | 2018-09-01 00:12:21 | [diff] [blame] | 584 | args = [] |
| 585 | args.extend(generated_test.get('args', [])) |
| 586 | args.extend(tester_config.get('args', [])) |
John Budorick | edfe7f87 | 2018-01-23 15:27:22 | [diff] [blame] | 587 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 588 | def add_conditional_args(key, fn): |
John Budorick | ab10871 | 2018-09-01 00:12:21 | [diff] [blame] | 589 | val = generated_test.pop(key, []) |
| 590 | if fn(tester_config): |
| 591 | args.extend(val) |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 592 | |
| 593 | add_conditional_args('desktop_args', lambda cfg: not self.is_android(cfg)) |
Brian Sheedy | 781c8ca4 | 2021-03-08 22:03:21 | [diff] [blame] | 594 | add_conditional_args('lacros_args', self.is_lacros) |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 595 | add_conditional_args('linux_args', self.is_linux) |
| 596 | add_conditional_args('android_args', self.is_android) |
Ben Pastene | 52890ace | 2019-05-24 20:03:36 | [diff] [blame] | 597 | add_conditional_args('chromeos_args', self.is_chromeos) |
Kai Ninomiya | 40de9f5 | 2019-10-18 21:38:49 | [diff] [blame] | 598 | add_conditional_args('mac_args', self.is_mac) |
| 599 | add_conditional_args('win_args', self.is_win) |
| 600 | add_conditional_args('win64_args', self.is_win64) |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 601 | |
John Budorick | ab10871 | 2018-09-01 00:12:21 | [diff] [blame] | 602 | for key in additional_arg_keys or []: |
| 603 | args.extend(generated_test.pop(key, [])) |
| 604 | args.extend(tester_config.get(key, [])) |
| 605 | |
| 606 | if args: |
| 607 | generated_test['args'] = self.maybe_fixup_args_array(args) |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 608 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 609 | def initialize_swarming_dictionary_for_test(self, generated_test, |
| 610 | tester_config): |
| 611 | if 'swarming' not in generated_test: |
| 612 | generated_test['swarming'] = {} |
Dirk Pranke | 81ff51c | 2017-12-09 19:24:28 | [diff] [blame] | 613 | if not 'can_use_on_swarming_builders' in generated_test['swarming']: |
| 614 | generated_test['swarming'].update({ |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 615 | 'can_use_on_swarming_builders': tester_config.get('use_swarming', |
| 616 | True) |
Dirk Pranke | 81ff51c | 2017-12-09 19:24:28 | [diff] [blame] | 617 | }) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 618 | if 'swarming' in tester_config: |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 619 | self.dictionary_merge(generated_test['swarming'], |
| 620 | tester_config['swarming']) |
Brian Sheedy | bc984e24 | 2021-04-21 23:44:51 | [diff] [blame] | 621 | # Apply any platform-specific Swarming dimensions after the generic ones. |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 622 | if 'android_swarming' in generated_test: |
| 623 | if self.is_android(tester_config): # pragma: no cover |
| 624 | self.dictionary_merge( |
| 625 | generated_test['swarming'], |
| 626 | generated_test['android_swarming']) # pragma: no cover |
| 627 | del generated_test['android_swarming'] # pragma: no cover |
Brian Sheedy | bc984e24 | 2021-04-21 23:44:51 | [diff] [blame] | 628 | if 'chromeos_swarming' in generated_test: |
| 629 | if self.is_chromeos(tester_config): # pragma: no cover |
| 630 | self.dictionary_merge( |
| 631 | generated_test['swarming'], |
| 632 | generated_test['chromeos_swarming']) # pragma: no cover |
| 633 | del generated_test['chromeos_swarming'] # pragma: no cover |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 634 | |
| 635 | def clean_swarming_dictionary(self, swarming_dict): |
| 636 | # Clean out redundant entries from a test's "swarming" dictionary. |
| 637 | # This is really only needed to retain 100% parity with the |
| 638 | # handwritten JSON files, and can be removed once all the files are |
| 639 | # autogenerated. |
| 640 | if 'shards' in swarming_dict: |
| 641 | if swarming_dict['shards'] == 1: # pragma: no cover |
| 642 | del swarming_dict['shards'] # pragma: no cover |
Kenneth Russell | fbda3c53 | 2017-12-08 23:57:24 | [diff] [blame] | 643 | if 'hard_timeout' in swarming_dict: |
| 644 | if swarming_dict['hard_timeout'] == 0: # pragma: no cover |
| 645 | del swarming_dict['hard_timeout'] # pragma: no cover |
Garrett Beaty | bb18d53 | 2023-06-26 22:16:33 | [diff] [blame] | 646 | del swarming_dict['can_use_on_swarming_builders'] |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 647 | |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 648 | def update_and_cleanup_test(self, test, test_name, tester_name, tester_config, |
| 649 | waterfall): |
| 650 | # Apply swarming mixins. |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 651 | test = self.apply_all_mixins( |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 652 | test, waterfall, tester_name, tester_config) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 653 | # See if there are any exceptions that need to be merged into this |
| 654 | # test's specification. |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 655 | modifications = self.get_test_modifications(test, tester_name) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 656 | if modifications: |
| 657 | test = self.dictionary_merge(test, modifications) |
Garrett Beaty | bfeff8f | 2023-06-16 18:57:25 | [diff] [blame] | 658 | if (swarming_dict := test.get('swarming')) is not None: |
Garrett Beaty | bb18d53 | 2023-06-26 22:16:33 | [diff] [blame] | 659 | if swarming_dict.get('can_use_on_swarming_builders'): |
Garrett Beaty | bfeff8f | 2023-06-16 18:57:25 | [diff] [blame] | 660 | self.clean_swarming_dictionary(swarming_dict) |
| 661 | else: |
| 662 | del test['swarming'] |
Ben Pastene | e012aea4 | 2019-05-14 22:32:28 | [diff] [blame] | 663 | # Ensure all Android Swarming tests run only on userdebug builds if another |
| 664 | # build type was not specified. |
| 665 | if 'swarming' in test and self.is_android(tester_config): |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 666 | dimensions = test.get('swarming', {}).get('dimensions', {}) |
| 667 | if (dimensions.get('os') == 'Android' |
| 668 | and not dimensions.get('device_os_type')): |
| 669 | dimensions['device_os_type'] = 'userdebug' |
Brian Sheedy | e6ea0ee | 2019-07-11 02:54:37 | [diff] [blame] | 670 | self.replace_test_args(test, test_name, tester_name) |
Garrett Beaty | afd33e0f | 2023-06-23 20:47:57 | [diff] [blame] | 671 | if 'args' in test and not test['args']: |
| 672 | test.pop('args') |
Ben Pastene | e012aea4 | 2019-05-14 22:32:28 | [diff] [blame] | 673 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 674 | return test |
| 675 | |
Brian Sheedy | e6ea0ee | 2019-07-11 02:54:37 | [diff] [blame] | 676 | def replace_test_args(self, test, test_name, tester_name): |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 677 | replacements = self.get_test_replacements(test, tester_name) or {} |
Brian Sheedy | e6ea0ee | 2019-07-11 02:54:37 | [diff] [blame] | 678 | valid_replacement_keys = ['args', 'non_precommit_args', 'precommit_args'] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 679 | for key, replacement_dict in replacements.items(): |
Brian Sheedy | e6ea0ee | 2019-07-11 02:54:37 | [diff] [blame] | 680 | if key not in valid_replacement_keys: |
| 681 | raise BBGenErr( |
| 682 | 'Given replacement key %s for %s on %s is not in the list of valid ' |
| 683 | 'keys %s' % (key, test_name, tester_name, valid_replacement_keys)) |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 684 | for replacement_key, replacement_val in replacement_dict.items(): |
Brian Sheedy | e6ea0ee | 2019-07-11 02:54:37 | [diff] [blame] | 685 | found_key = False |
| 686 | for i, test_key in enumerate(test.get(key, [])): |
| 687 | # Handle both the key/value being replaced being defined as two |
| 688 | # separate items or as key=value. |
| 689 | if test_key == replacement_key: |
| 690 | found_key = True |
| 691 | # Handle flags without values. |
| 692 | if replacement_val == None: |
| 693 | del test[key][i] |
| 694 | else: |
| 695 | test[key][i+1] = replacement_val |
| 696 | break |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 697 | if test_key.startswith(replacement_key + '='): |
Brian Sheedy | e6ea0ee | 2019-07-11 02:54:37 | [diff] [blame] | 698 | found_key = True |
| 699 | if replacement_val == None: |
| 700 | del test[key][i] |
| 701 | else: |
| 702 | test[key][i] = '%s=%s' % (replacement_key, replacement_val) |
| 703 | break |
| 704 | if not found_key: |
| 705 | raise BBGenErr('Could not find %s in existing list of values for key ' |
| 706 | '%s in %s on %s' % (replacement_key, key, test_name, |
| 707 | tester_name)) |
| 708 | |
Shenghua Zhang | aba8bad | 2018-02-07 02:12:09 | [diff] [blame] | 709 | def add_common_test_properties(self, test, tester_config): |
Brian Sheedy | 5ea8f6c6 | 2020-05-21 03:05:05 | [diff] [blame] | 710 | if self.is_chromeos(tester_config) and tester_config.get('use_swarming', |
Ben Pastene | a9e583b | 2019-01-16 02:57:26 | [diff] [blame] | 711 | True): |
| 712 | # The presence of the "device_type" dimension indicates that the tests |
Brian Sheedy | 9493da89 | 2020-05-13 22:58:06 | [diff] [blame] | 713 | # are targeting CrOS hardware and so need the special trigger script. |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 714 | if 'device_type' in test.get('swarming', {}).get('dimensions', {}): |
Ben Pastene | a9e583b | 2019-01-16 02:57:26 | [diff] [blame] | 715 | test['trigger_script'] = { |
| 716 | 'script': '//testing/trigger_scripts/chromeos_device_trigger.py', |
| 717 | } |
Shenghua Zhang | aba8bad | 2018-02-07 02:12:09 | [diff] [blame] | 718 | |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 719 | def add_android_presentation_args(self, tester_config, result): |
Ben Pastene | 858f4be | 2019-01-09 23:52:09 | [diff] [blame] | 720 | args = result.get('args', []) |
John Budorick | 262ae11 | 2019-07-12 19:24:38 | [diff] [blame] | 721 | bucket = tester_config.get('results_bucket', 'chromium-result-details') |
| 722 | args.append('--gs-results-bucket=%s' % bucket) |
Ben Pastene | 858f4be | 2019-01-09 23:52:09 | [diff] [blame] | 723 | if (result['swarming']['can_use_on_swarming_builders'] and not |
| 724 | tester_config.get('skip_merge_script', False)): |
| 725 | result['merge'] = { |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 726 | 'args': [ |
| 727 | '--bucket', |
| 728 | bucket, |
| 729 | '--test-name', |
| 730 | result['name'], |
| 731 | ], |
| 732 | 'script': ('//build/android/pylib/results/presentation/' |
| 733 | 'test_results_presentation.py'), |
Ben Pastene | 858f4be | 2019-01-09 23:52:09 | [diff] [blame] | 734 | } |
Ben Pastene | 858f4be | 2019-01-09 23:52:09 | [diff] [blame] | 735 | if not tester_config.get('skip_output_links', False): |
| 736 | result['swarming']['output_links'] = [ |
| 737 | { |
| 738 | 'link': [ |
| 739 | 'https://luci-logdog.appspot.com/v/?s', |
| 740 | '=android%2Fswarming%2Flogcats%2F', |
| 741 | '${TASK_ID}%2F%2B%2Funified_logcats', |
| 742 | ], |
| 743 | 'name': 'shard #${SHARD_INDEX} logcats', |
| 744 | }, |
| 745 | ] |
| 746 | if args: |
| 747 | result['args'] = args |
| 748 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 749 | def generate_gtest(self, waterfall, tester_name, tester_config, test_name, |
| 750 | test_config): |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 751 | if not self.should_run_on_tester(waterfall, tester_name, test_config): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 752 | return None |
| 753 | result = copy.deepcopy(test_config) |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 754 | # Use test_name here instead of test['name'] because test['name'] will be |
| 755 | # modified with the variant identifier in a matrix compound suite |
| 756 | result.setdefault('test', test_name) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 757 | self.initialize_swarming_dictionary_for_test(result, tester_config) |
John Budorick | ab10871 | 2018-09-01 00:12:21 | [diff] [blame] | 758 | |
| 759 | self.initialize_args_for_test( |
| 760 | result, tester_config, additional_arg_keys=['gtest_args']) |
Jamie Madill | a8be0d7 | 2020-10-02 05:24:04 | [diff] [blame] | 761 | if self.is_android(tester_config) and tester_config.get( |
Yuly Novikov | 26dd4705 | 2021-02-11 00:57:14 | [diff] [blame] | 762 | 'use_swarming', True): |
| 763 | if not test_config.get('use_isolated_scripts_api', False): |
| 764 | # TODO(https://crbug.com/1137998) make Android presentation work with |
| 765 | # isolated scripts in test_results_presentation.py merge script |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 766 | self.add_android_presentation_args(tester_config, result) |
Yuly Novikov | 26dd4705 | 2021-02-11 00:57:14 | [diff] [blame] | 767 | result['args'] = result.get('args', []) + ['--recover-devices'] |
Benjamin Pastene | 766d48f5 | 2017-12-18 21:47:42 | [diff] [blame] | 768 | |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 769 | result = self.update_and_cleanup_test( |
| 770 | result, test_name, tester_name, tester_config, waterfall) |
Shenghua Zhang | aba8bad | 2018-02-07 02:12:09 | [diff] [blame] | 771 | self.add_common_test_properties(result, tester_config) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 772 | self.substitute_magic_args(result, tester_name, tester_config) |
Stephen Martinis | bc7b777 | 2019-05-01 22:01:43 | [diff] [blame] | 773 | |
Garrett Beaty | bb18d53 | 2023-06-26 22:16:33 | [diff] [blame] | 774 | if 'swarming' in result and not result.get('merge'): |
Jamie Madill | a8be0d7 | 2020-10-02 05:24:04 | [diff] [blame] | 775 | if test_config.get('use_isolated_scripts_api', False): |
| 776 | merge_script = 'standard_isolated_script_merge' |
| 777 | else: |
| 778 | merge_script = 'standard_gtest_merge' |
| 779 | |
Stephen Martinis | bc7b777 | 2019-05-01 22:01:43 | [diff] [blame] | 780 | result['merge'] = { |
Jamie Madill | a8be0d7 | 2020-10-02 05:24:04 | [diff] [blame] | 781 | 'script': '//testing/merge_scripts/%s.py' % merge_script, |
Stephen Martinis | bc7b777 | 2019-05-01 22:01:43 | [diff] [blame] | 782 | } |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 783 | return result |
| 784 | |
| 785 | def generate_isolated_script_test(self, waterfall, tester_name, tester_config, |
| 786 | test_name, test_config): |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 787 | if not self.should_run_on_tester(waterfall, tester_name, test_config): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 788 | return None |
| 789 | result = copy.deepcopy(test_config) |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 790 | # Use test_name here instead of test['name'] because test['name'] will be |
| 791 | # modified with the variant identifier in a matrix compound suite |
Garrett Beaty | dca3d88 | 2023-09-14 23:50:32 | [diff] [blame] | 792 | result.setdefault('test', test_name) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 793 | self.initialize_swarming_dictionary_for_test(result, tester_config) |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 794 | self.initialize_args_for_test(result, tester_config) |
Yuly Novikov | 26dd4705 | 2021-02-11 00:57:14 | [diff] [blame] | 795 | if self.is_android(tester_config) and tester_config.get( |
| 796 | 'use_swarming', True): |
| 797 | if tester_config.get('use_android_presentation', False): |
| 798 | # TODO(https://crbug.com/1137998) make Android presentation work with |
| 799 | # isolated scripts in test_results_presentation.py merge script |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 800 | self.add_android_presentation_args(tester_config, result) |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 801 | result = self.update_and_cleanup_test( |
| 802 | result, test_name, tester_name, tester_config, waterfall) |
Shenghua Zhang | aba8bad | 2018-02-07 02:12:09 | [diff] [blame] | 803 | self.add_common_test_properties(result, tester_config) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 804 | self.substitute_magic_args(result, tester_name, tester_config) |
Stephen Martinis | f5004706 | 2019-05-06 22:26:17 | [diff] [blame] | 805 | |
Garrett Beaty | bb18d53 | 2023-06-26 22:16:33 | [diff] [blame] | 806 | if 'swarming' in result and not result.get('merge'): |
Stephen Martinis | f5004706 | 2019-05-06 22:26:17 | [diff] [blame] | 807 | # TODO(https://crbug.com/958376): Consider adding the ability to not have |
| 808 | # this default. |
| 809 | result['merge'] = { |
| 810 | 'script': '//testing/merge_scripts/standard_isolated_script_merge.py', |
Stephen Martinis | f5004706 | 2019-05-06 22:26:17 | [diff] [blame] | 811 | } |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 812 | return result |
| 813 | |
| 814 | def generate_script_test(self, waterfall, tester_name, tester_config, |
| 815 | test_name, test_config): |
Brian Sheedy | 158cd0f | 2019-04-26 01:12:44 | [diff] [blame] | 816 | # TODO(https://crbug.com/953072): Remove this check whenever a better |
| 817 | # long-term solution is implemented. |
| 818 | if (waterfall.get('forbid_script_tests', False) or |
| 819 | waterfall['machines'][tester_name].get('forbid_script_tests', False)): |
| 820 | raise BBGenErr('Attempted to generate a script test on tester ' + |
| 821 | tester_name + ', which explicitly forbids script tests') |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 822 | if not self.should_run_on_tester(waterfall, tester_name, test_config): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 823 | return None |
| 824 | result = { |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 825 | 'name': test_config['name'], |
| 826 | 'script': test_config['script'], |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 827 | } |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 828 | result = self.update_and_cleanup_test( |
| 829 | result, test_name, tester_name, tester_config, waterfall) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 830 | self.substitute_magic_args(result, tester_name, tester_config) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 831 | return result |
| 832 | |
| 833 | def generate_junit_test(self, waterfall, tester_name, tester_config, |
| 834 | test_name, test_config): |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 835 | if not self.should_run_on_tester(waterfall, tester_name, test_config): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 836 | return None |
John Budorick | def6acb | 2019-09-17 22:51:09 | [diff] [blame] | 837 | result = copy.deepcopy(test_config) |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 838 | # Use test_name here instead of test['name'] because test['name'] will be |
| 839 | # modified with the variant identifier in a matrix compound suite |
| 840 | result.setdefault('test', test_name) |
John Budorick | def6acb | 2019-09-17 22:51:09 | [diff] [blame] | 841 | self.initialize_args_for_test(result, tester_config) |
| 842 | result = self.update_and_cleanup_test( |
| 843 | result, test_name, tester_name, tester_config, waterfall) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 844 | self.substitute_magic_args(result, tester_name, tester_config) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 845 | return result |
| 846 | |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 847 | def generate_skylab_test(self, waterfall, tester_name, tester_config, |
| 848 | test_name, test_config): |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 849 | if not self.should_run_on_tester(waterfall, tester_name, test_config): |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 850 | return None |
| 851 | result = copy.deepcopy(test_config) |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 852 | # Use test_name here instead of test['name'] because test['name'] will be |
| 853 | # modified with the variant identifier in a matrix compound suite |
| 854 | result['test'] = test_name |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 855 | self.initialize_args_for_test(result, tester_config) |
| 856 | result = self.update_and_cleanup_test(result, test_name, tester_name, |
| 857 | tester_config, waterfall) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 858 | self.substitute_magic_args(result, tester_name, tester_config) |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 859 | return result |
| 860 | |
Garrett Beaty | 65d4422 | 2023-08-01 17:22:11 | [diff] [blame] | 861 | def substitute_gpu_args(self, tester_config, test, args): |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 862 | substitutions = { |
| 863 | # Any machine in waterfalls.pyl which desires to run GPU tests |
| 864 | # must provide the os_type key. |
| 865 | 'os_type': tester_config['os_type'], |
| 866 | 'gpu_vendor_id': '0', |
| 867 | 'gpu_device_id': '0', |
| 868 | } |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 869 | dimensions = test.get('swarming', {}).get('dimensions', {}) |
| 870 | if 'gpu' in dimensions: |
| 871 | # First remove the driver version, then split into vendor and device. |
| 872 | gpu = dimensions['gpu'] |
| 873 | if gpu != 'none': |
| 874 | gpu = gpu.split('-')[0].split(':') |
| 875 | substitutions['gpu_vendor_id'] = gpu[0] |
| 876 | substitutions['gpu_device_id'] = gpu[1] |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 877 | return [string.Template(arg).safe_substitute(substitutions) for arg in args] |
| 878 | |
| 879 | def generate_gpu_telemetry_test(self, waterfall, tester_name, tester_config, |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 880 | test_name, test_config, is_android_webview, |
| 881 | is_cast_streaming): |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 882 | # These are all just specializations of isolated script tests with |
| 883 | # a bunch of boilerplate command line arguments added. |
| 884 | |
| 885 | # The step name must end in 'test' or 'tests' in order for the |
| 886 | # results to automatically show up on the flakiness dashboard. |
| 887 | # (At least, this was true some time ago.) Continue to use this |
| 888 | # naming convention for the time being to minimize changes. |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 889 | # |
| 890 | # test name is the name of the test without the variant ID added |
| 891 | if not (test_name.endswith('test') or test_name.endswith('tests')): |
| 892 | raise BBGenErr( |
| 893 | f'telemetry test names must end with test or tests, got {test_name}') |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 894 | result = self.generate_isolated_script_test(waterfall, tester_name, |
| 895 | tester_config, test_name, |
| 896 | test_config) |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 897 | if not result: |
| 898 | return None |
Garrett Beaty | dca3d88 | 2023-09-14 23:50:32 | [diff] [blame] | 899 | result['test'] = test_config.get('test') or self.get_default_isolate_name( |
| 900 | tester_config, is_android_webview) |
Chan Li | ab7d8dd8 | 2020-04-24 23:42:19 | [diff] [blame] | 901 | |
Chan Li | a3ad150 | 2020-04-28 05:32:11 | [diff] [blame] | 902 | # Populate test_id_prefix. |
Garrett Beaty | dca3d88 | 2023-09-14 23:50:32 | [diff] [blame] | 903 | gn_entry = self.gn_isolate_map[result['test']] |
Chan Li | 17d969f9 | 2020-07-10 00:50:03 | [diff] [blame] | 904 | result['test_id_prefix'] = 'ninja:%s/' % gn_entry['label'] |
Chan Li | ab7d8dd8 | 2020-04-24 23:42:19 | [diff] [blame] | 905 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 906 | args = result.get('args', []) |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 907 | # Use test_name here instead of test['name'] because test['name'] will be |
| 908 | # modified with the variant identifier in a matrix compound suite |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 909 | test_to_run = result.pop('telemetry_test_name', test_name) |
erikchen | 6da2d9b | 2018-08-03 23:01:14 | [diff] [blame] | 910 | |
erikchen | 6da2d9b | 2018-08-03 23:01:14 | [diff] [blame] | 911 | # These tests upload and download results from cloud storage and therefore |
| 912 | # aren't idempotent yet. https://crbug.com/549140. |
Garrett Beaty | bfeff8f | 2023-06-16 18:57:25 | [diff] [blame] | 913 | if 'swarming' in result: |
| 914 | result['swarming']['idempotent'] = False |
erikchen | 6da2d9b | 2018-08-03 23:01:14 | [diff] [blame] | 915 | |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 916 | browser = '' |
| 917 | if is_cast_streaming: |
| 918 | browser = 'cast-streaming-shell' |
| 919 | elif is_android_webview: |
| 920 | browser = 'android-webview-instrumentation' |
| 921 | else: |
| 922 | browser = tester_config['browser_config'] |
Brian Sheedy | 4053a70 | 2020-07-28 02:09:52 | [diff] [blame] | 923 | |
Greg Thompson | cec7d8d | 2023-01-10 19:11:53 | [diff] [blame] | 924 | extra_browser_args = [] |
| 925 | |
Brian Sheedy | 4053a70 | 2020-07-28 02:09:52 | [diff] [blame] | 926 | # Most platforms require --enable-logging=stderr to get useful browser logs. |
| 927 | # However, this actively messes with logging on CrOS (because Chrome's |
| 928 | # stderr goes nowhere on CrOS) AND --log-level=0 is required for some reason |
| 929 | # in order to see JavaScript console messages. See |
| 930 | # https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/chrome_os_logging.md |
Greg Thompson | cec7d8d | 2023-01-10 19:11:53 | [diff] [blame] | 931 | if self.is_chromeos(tester_config): |
| 932 | extra_browser_args.append('--log-level=0') |
| 933 | elif not self.is_fuchsia(tester_config) or browser != 'fuchsia-chrome': |
| 934 | # Stderr logging is not needed for Chrome browser on Fuchsia, as ordinary |
| 935 | # logging via syslog is captured. |
| 936 | extra_browser_args.append('--enable-logging=stderr') |
| 937 | |
| 938 | # --expose-gc allows the WebGL conformance tests to more reliably |
| 939 | # reproduce GC-related bugs in the V8 bindings. |
| 940 | extra_browser_args.append('--js-flags=--expose-gc') |
Brian Sheedy | 4053a70 | 2020-07-28 02:09:52 | [diff] [blame] | 941 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 942 | args = [ |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 943 | test_to_run, |
| 944 | '--show-stdout', |
| 945 | '--browser=%s' % browser, |
| 946 | # --passthrough displays more of the logging in Telemetry when |
| 947 | # run via typ, in particular some of the warnings about tests |
| 948 | # being expected to fail, but passing. |
| 949 | '--passthrough', |
| 950 | '-v', |
Brian Sheedy | 814e048 | 2022-10-03 23:24:12 | [diff] [blame] | 951 | '--stable-jobs', |
Greg Thompson | cec7d8d | 2023-01-10 19:11:53 | [diff] [blame] | 952 | '--extra-browser-args=%s' % ' '.join(extra_browser_args), |
Brian Sheedy | 997e480 | 2023-10-18 02:28:13 | [diff] [blame^] | 953 | '--enforce-browser-version', |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 954 | ] + args |
Garrett Beaty | bfeff8f | 2023-06-16 18:57:25 | [diff] [blame] | 955 | result['args'] = self.maybe_fixup_args_array( |
Garrett Beaty | 65d4422 | 2023-08-01 17:22:11 | [diff] [blame] | 956 | self.substitute_gpu_args(tester_config, result, args)) |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 957 | return result |
| 958 | |
Brian Sheedy | f74819b | 2021-06-04 01:38:38 | [diff] [blame] | 959 | def get_default_isolate_name(self, tester_config, is_android_webview): |
| 960 | if self.is_android(tester_config): |
| 961 | if is_android_webview: |
| 962 | return 'telemetry_gpu_integration_test_android_webview' |
| 963 | return ( |
| 964 | 'telemetry_gpu_integration_test' + |
| 965 | BROWSER_CONFIG_TO_TARGET_SUFFIX_MAP[tester_config['browser_config']]) |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 966 | if self.is_fuchsia(tester_config): |
Chong Gu | c2ca5d0 | 2022-01-11 19:52:17 | [diff] [blame] | 967 | return 'telemetry_gpu_integration_test_fuchsia' |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 968 | return 'telemetry_gpu_integration_test' |
Brian Sheedy | f74819b | 2021-06-04 01:38:38 | [diff] [blame] | 969 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 970 | def get_test_generator_map(self): |
| 971 | return { |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 972 | 'android_webview_gpu_telemetry_tests': |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 973 | GPUTelemetryTestGenerator(self, is_android_webview=True), |
| 974 | 'cast_streaming_tests': |
| 975 | GPUTelemetryTestGenerator(self, is_cast_streaming=True), |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 976 | 'gpu_telemetry_tests': |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 977 | GPUTelemetryTestGenerator(self), |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 978 | 'gtest_tests': |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 979 | GTestGenerator(self), |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 980 | 'isolated_scripts': |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 981 | IsolatedScriptTestGenerator(self), |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 982 | 'junit_tests': |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 983 | JUnitGenerator(self), |
Bo Liu | 555a0f9 | 2019-03-29 12:11:56 | [diff] [blame] | 984 | 'scripts': |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 985 | ScriptGenerator(self), |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 986 | 'skylab_tests': |
Fabrice de Gans | cbd655f | 2022-08-04 20:15:30 | [diff] [blame] | 987 | SkylabGenerator(self), |
Brian Sheedy | b6491ba | 2022-09-26 20:49:49 | [diff] [blame] | 988 | 'skylab_gpu_telemetry_tests': |
| 989 | SkylabGPUTelemetryTestGenerator(self), |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 990 | } |
| 991 | |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 992 | def get_test_type_remapper(self): |
| 993 | return { |
Fabrice de Gans | 22327248 | 2022-08-08 16:56:57 | [diff] [blame] | 994 | # These are a specialization of isolated_scripts with a bunch of |
| 995 | # boilerplate command line arguments added to each one. |
| 996 | 'android_webview_gpu_telemetry_tests': 'isolated_scripts', |
| 997 | 'cast_streaming_tests': 'isolated_scripts', |
| 998 | 'gpu_telemetry_tests': 'isolated_scripts', |
Brian Sheedy | b6491ba | 2022-09-26 20:49:49 | [diff] [blame] | 999 | # These are the same as existing test types, just configured to run |
| 1000 | # in Skylab instead of via normal swarming. |
| 1001 | 'skylab_gpu_telemetry_tests': 'skylab_tests', |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 1002 | } |
| 1003 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1004 | def check_composition_type_test_suites(self, test_type, |
| 1005 | additional_validators=None): |
| 1006 | """Pre-pass to catch errors reliabily for compound/matrix suites""" |
| 1007 | validators = [check_compound_references, |
| 1008 | check_basic_references, |
| 1009 | check_conflicting_definitions] |
| 1010 | if additional_validators: |
| 1011 | validators += additional_validators |
| 1012 | |
| 1013 | target_suites = self.test_suites.get(test_type, {}) |
| 1014 | other_test_type = ('compound_suites' |
| 1015 | if test_type == 'matrix_compound_suites' |
| 1016 | else 'matrix_compound_suites') |
| 1017 | other_suites = self.test_suites.get(other_test_type, {}) |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1018 | basic_suites = self.test_suites.get('basic_suites', {}) |
| 1019 | |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1020 | for suite, suite_def in target_suites.items(): |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1021 | if suite in basic_suites: |
| 1022 | raise BBGenErr('%s names may not duplicate basic test suite names ' |
| 1023 | '(error found while processsing %s)' |
| 1024 | % (test_type, suite)) |
Nodir Turakulov | 28232afd | 2019-12-17 18:02:01 | [diff] [blame] | 1025 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1026 | seen_tests = {} |
| 1027 | for sub_suite in suite_def: |
| 1028 | for validator in validators: |
| 1029 | validator( |
| 1030 | basic_suites=basic_suites, |
| 1031 | other_test_suites=other_suites, |
| 1032 | seen_tests=seen_tests, |
| 1033 | sub_suite=sub_suite, |
| 1034 | suite=suite, |
| 1035 | suite_def=suite_def, |
| 1036 | target_test_suites=target_suites, |
| 1037 | test_type=test_type, |
Jeff Yoon | da581c3 | 2020-03-06 03:56:05 | [diff] [blame] | 1038 | all_variants=self.variants |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1039 | ) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1040 | |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1041 | def flatten_test_suites(self): |
| 1042 | new_test_suites = {} |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1043 | test_types = ['basic_suites', 'compound_suites', 'matrix_compound_suites'] |
| 1044 | for category in test_types: |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1045 | for name, value in self.test_suites.get(category, {}).items(): |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1046 | new_test_suites[name] = value |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1047 | self.test_suites = new_test_suites |
| 1048 | |
Chan Li | a3ad150 | 2020-04-28 05:32:11 | [diff] [blame] | 1049 | def resolve_test_id_prefixes(self): |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1050 | for suite in self.test_suites['basic_suites'].values(): |
| 1051 | for key, test in suite.items(): |
Dirk Pranke | 0e879b2 | 2020-07-16 23:53:56 | [diff] [blame] | 1052 | assert isinstance(test, dict) |
Nodir Turakulov | fce3429 | 2019-12-18 17:05:41 | [diff] [blame] | 1053 | |
Garrett Beaty | dca3d88 | 2023-09-14 23:50:32 | [diff] [blame] | 1054 | isolate_name = test.get('test') or key |
Nodir Turakulov | fce3429 | 2019-12-18 17:05:41 | [diff] [blame] | 1055 | gn_entry = self.gn_isolate_map.get(isolate_name) |
| 1056 | if gn_entry: |
Corentin Wallez | 55b8e77 | 2020-04-24 17:39:28 | [diff] [blame] | 1057 | label = gn_entry['label'] |
| 1058 | |
| 1059 | if label.count(':') != 1: |
| 1060 | raise BBGenErr( |
| 1061 | 'Malformed GN label "%s" in gn_isolate_map for key "%s",' |
| 1062 | ' implicit names (like //f/b meaning //f/b:b) are disallowed.' % |
| 1063 | (label, isolate_name)) |
| 1064 | if label.split(':')[1] != isolate_name: |
| 1065 | raise BBGenErr( |
| 1066 | 'gn_isolate_map key name "%s" doesn\'t match GN target name in' |
| 1067 | ' label "%s" see http://crbug.com/1071091 for details.' % |
| 1068 | (isolate_name, label)) |
| 1069 | |
Chan Li | a3ad150 | 2020-04-28 05:32:11 | [diff] [blame] | 1070 | test['test_id_prefix'] = 'ninja:%s/' % label |
Nodir Turakulov | fce3429 | 2019-12-18 17:05:41 | [diff] [blame] | 1071 | else: # pragma: no cover |
| 1072 | # Some tests do not have an entry gn_isolate_map.pyl, such as |
| 1073 | # telemetry tests. |
| 1074 | # TODO(crbug.com/1035304): require an entry in gn_isolate_map. |
| 1075 | pass |
| 1076 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1077 | def resolve_composition_test_suites(self): |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1078 | self.check_composition_type_test_suites('compound_suites') |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1079 | |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1080 | compound_suites = self.test_suites.get('compound_suites', {}) |
| 1081 | # check_composition_type_test_suites() checks that all basic suites |
| 1082 | # referenced by compound suites exist. |
| 1083 | basic_suites = self.test_suites.get('basic_suites') |
| 1084 | |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1085 | for name, value in compound_suites.items(): |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1086 | # Resolve this to a dictionary. |
| 1087 | full_suite = {} |
| 1088 | for entry in value: |
| 1089 | suite = basic_suites[entry] |
| 1090 | full_suite.update(suite) |
| 1091 | compound_suites[name] = full_suite |
| 1092 | |
Jeff Yoon | 85fb8df | 2020-08-20 16:47:43 | [diff] [blame] | 1093 | def resolve_variants(self, basic_test_definition, variants, mixins): |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1094 | """ Merge variant-defined configurations to each test case definition in a |
| 1095 | test suite. |
| 1096 | |
| 1097 | The output maps a unique test name to an array of configurations because |
| 1098 | there may exist more than one definition for a test name using variants. The |
| 1099 | test name is referenced while mapping machines to test suites, so unpacking |
| 1100 | the array is done by the generators. |
| 1101 | |
| 1102 | Args: |
| 1103 | basic_test_definition: a {} defined test suite in the format |
| 1104 | test_name:test_config |
| 1105 | variants: an [] of {} defining configurations to be applied to each test |
| 1106 | case in the basic test_definition |
| 1107 | |
| 1108 | Return: |
| 1109 | a {} of test_name:[{}], where each {} is a merged configuration |
| 1110 | """ |
| 1111 | |
| 1112 | # Each test in a basic test suite will have a definition per variant. |
| 1113 | test_suite = {} |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1114 | for variant in variants: |
| 1115 | # Unpack the variant from variants.pyl if it's string based. |
| 1116 | if isinstance(variant, str): |
| 1117 | variant = self.variants[variant] |
Jeff Yoon | da581c3 | 2020-03-06 03:56:05 | [diff] [blame] | 1118 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1119 | # If 'enabled' is set to False, we will not use this variant; otherwise if |
| 1120 | # the variant doesn't include 'enabled' variable or 'enabled' is set to |
| 1121 | # True, we will use this variant |
| 1122 | if not variant.get('enabled', True): |
| 1123 | continue |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1124 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1125 | # Make a shallow copy of the variant to remove variant-specific fields, |
| 1126 | # leaving just mixin fields |
| 1127 | variant = copy.copy(variant) |
| 1128 | variant.pop('enabled', None) |
| 1129 | identifier = variant.pop('identifier') |
| 1130 | variant_mixins = variant.pop('mixins', []) |
| 1131 | variant_skylab = variant.pop('skylab', {}) |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1132 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1133 | for test_name, test_config in basic_test_definition.items(): |
| 1134 | new_test = self.apply_mixin(variant, test_config) |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1135 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1136 | new_test['mixins'] = (test_config.get('mixins', []) + variant_mixins + |
| 1137 | mixins) |
Xinan Lin | 05fb9c175 | 2020-12-17 00:15:52 | [diff] [blame] | 1138 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1139 | # The identifier is used to make the name of the test unique. |
| 1140 | # Generators in the recipe uniquely identify a test by it's name, so we |
| 1141 | # don't want to have the same name for each variant. |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1142 | new_test['name'] = f'{test_name} {identifier}' |
Ben Pastene | 5f231cf2 | 2022-05-05 18:03:07 | [diff] [blame] | 1143 | |
| 1144 | # Attach the variant identifier to the test config so downstream |
| 1145 | # generators can make modifications based on the original name. This |
| 1146 | # is mainly used in generate_gpu_telemetry_test(). |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1147 | new_test['variant_id'] = identifier |
Ben Pastene | 5f231cf2 | 2022-05-05 18:03:07 | [diff] [blame] | 1148 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1149 | for k, v in variant_skylab.items(): |
Sven Zheng | 22ba631 | 2023-10-16 22:59:35 | [diff] [blame] | 1150 | # cros_chrome_version is the ash chrome version in the cros img in the |
| 1151 | # variant of cros_board. We don't want to include it in the final json |
| 1152 | # files; so remove it. |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1153 | if k != 'cros_chrome_version': |
| 1154 | new_test[k] = v |
| 1155 | |
Sven Zheng | 22ba631 | 2023-10-16 22:59:35 | [diff] [blame] | 1156 | # For skylab, we need to pop the correct `autotest_name`. This field |
| 1157 | # defines what wrapper we use in OS infra. e.g. for gtest it's |
| 1158 | # https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/autotest/files/server/site_tests/chromium/chromium.py |
| 1159 | if variant_skylab and 'autotest_name' not in new_test: |
| 1160 | if 'tast_expr' in test_config: |
| 1161 | if 'lacros' in test_config['name']: |
| 1162 | new_test['autotest_name'] = 'tast.lacros-from-gcs' |
| 1163 | else: |
| 1164 | new_test['autotest_name'] = 'tast.chrome-from-gcs' |
| 1165 | elif 'benchmark' in test_config: |
| 1166 | new_test['autotest_name'] = 'chromium_Telemetry' |
| 1167 | else: |
| 1168 | new_test['autotest_name'] = 'chromium' |
| 1169 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1170 | test_suite.setdefault(test_name, []).append(new_test) |
| 1171 | |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1172 | return test_suite |
| 1173 | |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1174 | def resolve_matrix_compound_test_suites(self): |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1175 | self.check_composition_type_test_suites('matrix_compound_suites', |
| 1176 | [check_matrix_identifier]) |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1177 | |
| 1178 | matrix_compound_suites = self.test_suites.get('matrix_compound_suites', {}) |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1179 | # check_composition_type_test_suites() checks that all basic suites are |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1180 | # referenced by matrix suites exist. |
| 1181 | basic_suites = self.test_suites.get('basic_suites') |
| 1182 | |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1183 | for matrix_suite_name, matrix_config in matrix_compound_suites.items(): |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1184 | full_suite = {} |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1185 | |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1186 | for test_suite, mtx_test_suite_config in matrix_config.items(): |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1187 | basic_test_def = copy.deepcopy(basic_suites[test_suite]) |
| 1188 | |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1189 | def update_tests(expanded): |
| 1190 | for test_name, new_tests in expanded.items(): |
| 1191 | if not isinstance(new_tests, list): |
| 1192 | new_tests = [new_tests] |
| 1193 | tests_for_name = full_suite.setdefault(test_name, []) |
| 1194 | for t in new_tests: |
| 1195 | if t not in tests_for_name: |
| 1196 | tests_for_name.append(t) |
| 1197 | |
Garrett Beaty | 60a7b2a | 2023-09-13 23:00:40 | [diff] [blame] | 1198 | if (variants := mtx_test_suite_config.get('variants')): |
Jeff Yoon | 85fb8df | 2020-08-20 16:47:43 | [diff] [blame] | 1199 | mixins = mtx_test_suite_config.get('mixins', []) |
Garrett Beaty | 60a7b2a | 2023-09-13 23:00:40 | [diff] [blame] | 1200 | result = self.resolve_variants(basic_test_def, variants, mixins) |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1201 | update_tests(result) |
Sven Zheng | 2fe6dd6f | 2021-08-06 21:12:27 | [diff] [blame] | 1202 | else: |
| 1203 | suite = basic_suites[test_suite] |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1204 | update_tests(suite) |
| 1205 | matrix_compound_suites[matrix_suite_name] = full_suite |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1206 | |
| 1207 | def link_waterfalls_to_test_suites(self): |
| 1208 | for waterfall in self.waterfalls: |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1209 | for tester_name, tester in waterfall['machines'].items(): |
| 1210 | for suite, value in tester.get('test_suites', {}).items(): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1211 | if not value in self.test_suites: |
| 1212 | # Hard / impossible to cover this in the unit test. |
| 1213 | raise self.unknown_test_suite( |
| 1214 | value, tester_name, waterfall['name']) # pragma: no cover |
| 1215 | tester['test_suites'][suite] = self.test_suites[value] |
| 1216 | |
| 1217 | def load_configuration_files(self): |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1218 | self.waterfalls = self.load_pyl_file(self.args.waterfalls_pyl_path) |
| 1219 | self.test_suites = self.load_pyl_file(self.args.test_suites_pyl_path) |
| 1220 | self.exceptions = self.load_pyl_file( |
| 1221 | self.args.test_suite_exceptions_pyl_path) |
| 1222 | self.mixins = self.load_pyl_file(self.args.mixins_pyl_path) |
| 1223 | self.gn_isolate_map = self.load_pyl_file(self.args.gn_isolate_map_pyl_path) |
Chong Gu | ee62224 | 2020-10-28 18:17:35 | [diff] [blame] | 1224 | for isolate_map in self.args.isolate_map_files: |
| 1225 | isolate_map = self.load_pyl_file(isolate_map) |
| 1226 | duplicates = set(isolate_map).intersection(self.gn_isolate_map) |
| 1227 | if duplicates: |
| 1228 | raise BBGenErr('Duplicate targets in isolate map files: %s.' % |
| 1229 | ', '.join(duplicates)) |
| 1230 | self.gn_isolate_map.update(isolate_map) |
| 1231 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1232 | self.variants = self.load_pyl_file(self.args.variants_pyl_path) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1233 | |
| 1234 | def resolve_configuration_files(self): |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1235 | self.resolve_test_names() |
Garrett Beaty | dca3d88 | 2023-09-14 23:50:32 | [diff] [blame] | 1236 | self.resolve_isolate_names() |
Garrett Beaty | 65d4422 | 2023-08-01 17:22:11 | [diff] [blame] | 1237 | self.resolve_dimension_sets() |
Chan Li | a3ad150 | 2020-04-28 05:32:11 | [diff] [blame] | 1238 | self.resolve_test_id_prefixes() |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1239 | self.resolve_composition_test_suites() |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1240 | self.resolve_matrix_compound_test_suites() |
| 1241 | self.flatten_test_suites() |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1242 | self.link_waterfalls_to_test_suites() |
| 1243 | |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1244 | def resolve_test_names(self): |
| 1245 | for suite_name, suite in self.test_suites.get('basic_suites').items(): |
| 1246 | for test_name, test in suite.items(): |
| 1247 | if 'name' in test: |
| 1248 | raise BBGenErr( |
| 1249 | f'The name field is set in test {test_name} in basic suite ' |
| 1250 | f'{suite_name}, this is not supported, the test name is the key ' |
| 1251 | 'within the basic suite') |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 1252 | # When a test is expanded with variants, this will be overwritten, but |
| 1253 | # this ensures every test definition has the name field set |
| 1254 | test['name'] = test_name |
Garrett Beaty | 235c141 | 2023-08-29 20:26:29 | [diff] [blame] | 1255 | |
Garrett Beaty | dca3d88 | 2023-09-14 23:50:32 | [diff] [blame] | 1256 | def resolve_isolate_names(self): |
| 1257 | for suite_name, suite in self.test_suites.get('basic_suites').items(): |
| 1258 | for test_name, test in suite.items(): |
| 1259 | if 'isolate_name' in test: |
| 1260 | raise BBGenErr( |
| 1261 | f'The isolate_name field is set in test {test_name} in basic ' |
| 1262 | f'suite {suite_name}, the test field should be used instead') |
| 1263 | |
Garrett Beaty | 65d4422 | 2023-08-01 17:22:11 | [diff] [blame] | 1264 | def resolve_dimension_sets(self): |
Garrett Beaty | 65d4422 | 2023-08-01 17:22:11 | [diff] [blame] | 1265 | |
| 1266 | def definitions(): |
| 1267 | for suite_name, suite in self.test_suites.get('basic_suites', {}).items(): |
| 1268 | for test_name, test in suite.items(): |
| 1269 | yield test, f'test {test_name} in basic suite {suite_name}' |
| 1270 | |
| 1271 | for mixin_name, mixin in self.mixins.items(): |
| 1272 | yield mixin, f'mixin {mixin_name}' |
| 1273 | |
| 1274 | for waterfall in self.waterfalls: |
| 1275 | for builder_name, builder in waterfall.get('machines', {}).items(): |
| 1276 | yield ( |
| 1277 | builder, |
| 1278 | f'builder {builder_name} in waterfall {waterfall["name"]}', |
| 1279 | ) |
| 1280 | |
| 1281 | for test_name, exceptions in self.exceptions.items(): |
| 1282 | modifications = exceptions.get('modifications', {}) |
| 1283 | for builder_name, mods in modifications.items(): |
| 1284 | yield ( |
| 1285 | mods, |
| 1286 | f'exception for test {test_name} on builder {builder_name}', |
| 1287 | ) |
| 1288 | |
| 1289 | for definition, location in definitions(): |
| 1290 | for swarming_attr in ( |
| 1291 | 'swarming', |
| 1292 | 'android_swarming', |
| 1293 | 'chromeos_swarming', |
| 1294 | ): |
| 1295 | if (swarming := |
| 1296 | definition.get(swarming_attr)) and 'dimension_sets' in swarming: |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 1297 | raise BBGenErr( |
| 1298 | f'dimension_sets is no longer supported (set in {location}),' |
| 1299 | ' instead, use set dimensions to a single dict') |
Garrett Beaty | 65d4422 | 2023-08-01 17:22:11 | [diff] [blame] | 1300 | |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1301 | def unknown_bot(self, bot_name, waterfall_name): |
| 1302 | return BBGenErr( |
| 1303 | 'Unknown bot name "%s" on waterfall "%s"' % (bot_name, waterfall_name)) |
| 1304 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1305 | def unknown_test_suite(self, suite_name, bot_name, waterfall_name): |
| 1306 | return BBGenErr( |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1307 | 'Test suite %s from machine %s on waterfall %s not present in ' |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1308 | 'test_suites.pyl' % (suite_name, bot_name, waterfall_name)) |
| 1309 | |
| 1310 | def unknown_test_suite_type(self, suite_type, bot_name, waterfall_name): |
| 1311 | return BBGenErr( |
| 1312 | 'Unknown test suite type ' + suite_type + ' in bot ' + bot_name + |
| 1313 | ' on waterfall ' + waterfall_name) |
| 1314 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1315 | def apply_all_mixins(self, test, waterfall, builder_name, builder): |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1316 | """Applies all present swarming mixins to the test for a given builder. |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1317 | |
| 1318 | Checks in the waterfall, builder, and test objects for mixins. |
| 1319 | """ |
| 1320 | def valid_mixin(mixin_name): |
| 1321 | """Asserts that the mixin is valid.""" |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1322 | if mixin_name not in self.mixins: |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1323 | raise BBGenErr("bad mixin %s" % mixin_name) |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1324 | |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1325 | def must_be_list(mixins, typ, name): |
| 1326 | """Asserts that given mixins are a list.""" |
| 1327 | if not isinstance(mixins, list): |
| 1328 | raise BBGenErr("'%s' in %s '%s' must be a list" % (mixins, typ, name)) |
| 1329 | |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 1330 | test_name = test['name'] |
Brian Sheedy | 7658c98 | 2020-01-08 02:27:58 | [diff] [blame] | 1331 | remove_mixins = set() |
| 1332 | if 'remove_mixins' in builder: |
| 1333 | must_be_list(builder['remove_mixins'], 'builder', builder_name) |
| 1334 | for rm in builder['remove_mixins']: |
| 1335 | valid_mixin(rm) |
| 1336 | remove_mixins.add(rm) |
| 1337 | if 'remove_mixins' in test: |
| 1338 | must_be_list(test['remove_mixins'], 'test', test_name) |
| 1339 | for rm in test['remove_mixins']: |
| 1340 | valid_mixin(rm) |
| 1341 | remove_mixins.add(rm) |
| 1342 | del test['remove_mixins'] |
| 1343 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1344 | if 'mixins' in waterfall: |
| 1345 | must_be_list(waterfall['mixins'], 'waterfall', waterfall['name']) |
| 1346 | for mixin in waterfall['mixins']: |
Brian Sheedy | 7658c98 | 2020-01-08 02:27:58 | [diff] [blame] | 1347 | if mixin in remove_mixins: |
| 1348 | continue |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1349 | valid_mixin(mixin) |
Austin Eng | 148d9f0f | 2022-02-08 19:18:53 | [diff] [blame] | 1350 | test = self.apply_mixin(self.mixins[mixin], test, builder) |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1351 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1352 | if 'mixins' in builder: |
| 1353 | must_be_list(builder['mixins'], 'builder', builder_name) |
| 1354 | for mixin in builder['mixins']: |
Brian Sheedy | 7658c98 | 2020-01-08 02:27:58 | [diff] [blame] | 1355 | if mixin in remove_mixins: |
| 1356 | continue |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1357 | valid_mixin(mixin) |
Austin Eng | 148d9f0f | 2022-02-08 19:18:53 | [diff] [blame] | 1358 | test = self.apply_mixin(self.mixins[mixin], test, builder) |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1359 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1360 | if not 'mixins' in test: |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1361 | return test |
| 1362 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1363 | must_be_list(test['mixins'], 'test', test_name) |
| 1364 | for mixin in test['mixins']: |
Brian Sheedy | 7658c98 | 2020-01-08 02:27:58 | [diff] [blame] | 1365 | # We don't bother checking if the given mixin is in remove_mixins here |
| 1366 | # since this is already the lowest level, so if a mixin is added here that |
| 1367 | # we don't want, we can just delete its entry. |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1368 | valid_mixin(mixin) |
Austin Eng | 148d9f0f | 2022-02-08 19:18:53 | [diff] [blame] | 1369 | test = self.apply_mixin(self.mixins[mixin], test, builder) |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1370 | del test['mixins'] |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1371 | return test |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1372 | |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1373 | def apply_mixin(self, mixin, test, builder=None): |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1374 | """Applies a mixin to a test. |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1375 | |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1376 | A mixin is applied by copying all fields from the mixin into the |
| 1377 | test with the following exceptions: |
| 1378 | * For the various *args keys, the test's existing value (an empty |
| 1379 | list if not present) will be extended with the mixin's value. |
| 1380 | * The sub-keys of the swarming value will be copied to the test's |
| 1381 | swarming value with the following exceptions: |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 1382 | * For the named_caches sub-keys, the test's existing value (an |
| 1383 | empty list if not present) will be extended with the mixin's |
| 1384 | value. |
| 1385 | * For the dimensions sub-key, the tests's existing value (an empty |
| 1386 | dict if not present) will be updated with the mixin's value. |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1387 | """ |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1388 | |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1389 | new_test = copy.deepcopy(test) |
| 1390 | mixin = copy.deepcopy(mixin) |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1391 | |
| 1392 | if 'description' in mixin: |
| 1393 | description = [] |
| 1394 | if 'description' in new_test: |
| 1395 | description.append(new_test['description']) |
| 1396 | description.append(mixin.pop('description')) |
| 1397 | new_test['description'] = '\n'.join(description) |
| 1398 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1399 | if 'swarming' in mixin: |
| 1400 | swarming_mixin = mixin['swarming'] |
| 1401 | new_test.setdefault('swarming', {}) |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1402 | if 'dimensions' in swarming_mixin: |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 1403 | new_test['swarming'].setdefault('dimensions', {}).update( |
| 1404 | swarming_mixin.pop('dimensions')) |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1405 | if 'named_caches' in swarming_mixin: |
| 1406 | new_test['swarming'].setdefault('named_caches', []).extend( |
| 1407 | swarming_mixin['named_caches']) |
| 1408 | del swarming_mixin['named_caches'] |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1409 | # python dict update doesn't do recursion at all. Just hard code the |
| 1410 | # nested update we need (mixin['swarming'] shouldn't clobber |
| 1411 | # test['swarming'], but should update it). |
| 1412 | new_test['swarming'].update(swarming_mixin) |
| 1413 | del mixin['swarming'] |
| 1414 | |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1415 | # Array so we can assign to it in a nested scope. |
| 1416 | args_need_fixup = ['args' in mixin] |
| 1417 | |
| 1418 | for a in ( |
| 1419 | 'args', |
| 1420 | 'precommit_args', |
| 1421 | 'non_precommit_args', |
| 1422 | 'desktop_args', |
| 1423 | 'lacros_args', |
| 1424 | 'linux_args', |
| 1425 | 'android_args', |
| 1426 | 'chromeos_args', |
| 1427 | 'mac_args', |
| 1428 | 'win_args', |
| 1429 | 'win64_args', |
| 1430 | ): |
| 1431 | if (value := mixin.pop(a, None)) is None: |
| 1432 | continue |
| 1433 | if not isinstance(value, list): |
| 1434 | raise BBGenErr(f'"{a}" must be a list') |
| 1435 | new_test.setdefault(a, []).extend(value) |
| 1436 | |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1437 | args = new_test.get('args', []) |
Austin Eng | 148d9f0f | 2022-02-08 19:18:53 | [diff] [blame] | 1438 | |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1439 | def add_conditional_args(key, fn): |
Garrett Beaty | 8d6708c | 2023-07-20 17:20:41 | [diff] [blame] | 1440 | if builder is None: |
| 1441 | return |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1442 | val = new_test.pop(key, []) |
| 1443 | if val and fn(builder): |
| 1444 | args.extend(val) |
| 1445 | args_need_fixup[0] = True |
Austin Eng | 148d9f0f | 2022-02-08 19:18:53 | [diff] [blame] | 1446 | |
Garrett Beaty | 4c35b14 | 2023-06-23 21:01:23 | [diff] [blame] | 1447 | add_conditional_args('desktop_args', lambda cfg: not self.is_android(cfg)) |
| 1448 | add_conditional_args('lacros_args', self.is_lacros) |
| 1449 | add_conditional_args('linux_args', self.is_linux) |
| 1450 | add_conditional_args('android_args', self.is_android) |
| 1451 | add_conditional_args('chromeos_args', self.is_chromeos) |
| 1452 | add_conditional_args('mac_args', self.is_mac) |
| 1453 | add_conditional_args('win_args', self.is_win) |
| 1454 | add_conditional_args('win64_args', self.is_win64) |
| 1455 | |
| 1456 | if args_need_fixup[0]: |
| 1457 | new_test['args'] = self.maybe_fixup_args_array(args) |
Wez | c0e835b70 | 2018-10-30 00:38:41 | [diff] [blame] | 1458 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1459 | new_test.update(mixin) |
Stephen Martinis | b6a5049 | 2018-09-12 23:59:32 | [diff] [blame] | 1460 | return new_test |
| 1461 | |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1462 | def generate_output_tests(self, waterfall): |
| 1463 | """Generates the tests for a waterfall. |
| 1464 | |
| 1465 | Args: |
| 1466 | waterfall: a dictionary parsed from a master pyl file |
| 1467 | Returns: |
| 1468 | A dictionary mapping builders to test specs |
| 1469 | """ |
| 1470 | return { |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1471 | name: self.get_tests_for_config(waterfall, name, config) |
| 1472 | for name, config in waterfall['machines'].items() |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | def get_tests_for_config(self, waterfall, name, config): |
Greg Guterman | 5c614415 | 2020-02-28 20:08:53 | [diff] [blame] | 1476 | generator_map = self.get_test_generator_map() |
| 1477 | test_type_remapper = self.get_test_type_remapper() |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1478 | |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1479 | tests = {} |
| 1480 | # Copy only well-understood entries in the machine's configuration |
| 1481 | # verbatim into the generated JSON. |
| 1482 | if 'additional_compile_targets' in config: |
| 1483 | tests['additional_compile_targets'] = config[ |
| 1484 | 'additional_compile_targets'] |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1485 | for test_type, input_tests in config.get('test_suites', {}).items(): |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1486 | if test_type not in generator_map: |
| 1487 | raise self.unknown_test_suite_type( |
| 1488 | test_type, name, waterfall['name']) # pragma: no cover |
| 1489 | test_generator = generator_map[test_type] |
| 1490 | # Let multiple kinds of generators generate the same kinds |
| 1491 | # of tests. For example, gpu_telemetry_tests are a |
| 1492 | # specialization of isolated_scripts. |
| 1493 | new_tests = test_generator.generate( |
| 1494 | waterfall, name, config, input_tests) |
| 1495 | remapped_test_type = test_type_remapper.get(test_type, test_type) |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 1496 | tests.setdefault(remapped_test_type, []).extend(new_tests) |
| 1497 | |
| 1498 | for test_type, tests_for_type in tests.items(): |
| 1499 | if test_type == 'additional_compile_targets': |
| 1500 | continue |
| 1501 | tests[test_type] = sorted(tests_for_type, key=lambda t: t['name']) |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1502 | |
| 1503 | return tests |
| 1504 | |
| 1505 | def jsonify(self, all_tests): |
| 1506 | return json.dumps( |
| 1507 | all_tests, indent=2, separators=(',', ': '), |
| 1508 | sort_keys=True) + '\n' |
| 1509 | |
| 1510 | def generate_outputs(self): # pragma: no cover |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1511 | self.load_configuration_files() |
| 1512 | self.resolve_configuration_files() |
| 1513 | filters = self.args.waterfall_filters |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1514 | result = collections.defaultdict(dict) |
| 1515 | |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 1516 | if os.path.exists(self.args.autoshard_exceptions_json_path): |
| 1517 | autoshards = json.loads( |
| 1518 | self.read_file(self.args.autoshard_exceptions_json_path)) |
| 1519 | else: |
| 1520 | autoshards = {} |
| 1521 | |
Dirk Pranke | 6269d30 | 2020-10-01 00:14:39 | [diff] [blame] | 1522 | required_fields = ('name',) |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1523 | for waterfall in self.waterfalls: |
| 1524 | for field in required_fields: |
| 1525 | # Verify required fields |
| 1526 | if field not in waterfall: |
| 1527 | raise BBGenErr("Waterfall %s has no %s" % (waterfall['name'], field)) |
| 1528 | |
| 1529 | # Handle filter flag, if specified |
| 1530 | if filters and waterfall['name'] not in filters: |
| 1531 | continue |
| 1532 | |
| 1533 | # Join config files and hardcoded values together |
| 1534 | all_tests = self.generate_output_tests(waterfall) |
| 1535 | result[waterfall['name']] = all_tests |
| 1536 | |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 1537 | if not autoshards: |
| 1538 | continue |
| 1539 | for builder, test_spec in all_tests.items(): |
| 1540 | for target_type, test_list in test_spec.items(): |
| 1541 | if target_type == 'additional_compile_targets': |
| 1542 | continue |
| 1543 | for test_dict in test_list: |
| 1544 | # Suites that apply variants or other customizations will create |
| 1545 | # test_dicts that have "name" value that is different from the |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 1546 | # "test" value. |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 1547 | # e.g. name = vulkan_swiftshader_content_browsertests, but |
| 1548 | # test = content_browsertests and |
| 1549 | # test_id_prefix = "ninja://content/test:content_browsertests/" |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 1550 | test_name = test_dict['name'] |
Stephanie Kim | 572b43c0 | 2023-04-13 14:24:13 | [diff] [blame] | 1551 | shard_info = autoshards.get(waterfall['name'], |
| 1552 | {}).get(builder, {}).get(test_name) |
| 1553 | if shard_info: |
| 1554 | test_dict['swarming'].update( |
| 1555 | {'shards': int(shard_info['shards'])}) |
| 1556 | |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1557 | # Add do not edit warning |
| 1558 | for tests in result.values(): |
| 1559 | tests['AAAAA1 AUTOGENERATED FILE DO NOT EDIT'] = {} |
| 1560 | tests['AAAAA2 See generate_buildbot_json.py to make changes'] = {} |
| 1561 | |
| 1562 | return result |
| 1563 | |
| 1564 | def write_json_result(self, result): # pragma: no cover |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1565 | suffix = '.json' |
| 1566 | if self.args.new_files: |
| 1567 | suffix = '.new' + suffix |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 1568 | |
| 1569 | for filename, contents in result.items(): |
| 1570 | jsonstr = self.jsonify(contents) |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1571 | file_path = os.path.join(self.args.output_dir, filename + suffix) |
| 1572 | self.write_file(file_path, jsonstr) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1573 | |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1574 | def get_valid_bot_names(self): |
Garrett Beaty | ff6e98d | 2021-09-02 17:00:16 | [diff] [blame] | 1575 | # Extract bot names from infra/config/generated/luci/luci-milo.cfg. |
Stephen Martinis | 26627cf | 2018-12-19 01:51:42 | [diff] [blame] | 1576 | # NOTE: This reference can cause issues; if a file changes there, the |
| 1577 | # presubmit here won't be run by default. A manually maintained list there |
| 1578 | # tries to run presubmit here when luci-milo.cfg is changed. If any other |
| 1579 | # references to configs outside of this directory are added, please change |
| 1580 | # their presubmit to run `generate_buildbot_json.py -c`, so that the tree |
| 1581 | # never ends up in an invalid state. |
Garrett Beaty | 4f3e921 | 2020-06-25 20:21:49 | [diff] [blame] | 1582 | |
Garrett Beaty | 7e866fc | 2021-06-16 14:12:10 | [diff] [blame] | 1583 | # Get the generated project.pyl so we can check if we should be enforcing |
| 1584 | # that the specs are for builders that actually exist |
| 1585 | # If not, return None to indicate that we won't enforce that builders in |
| 1586 | # waterfalls.pyl are defined in LUCI |
Garrett Beaty | 4f3e921 | 2020-06-25 20:21:49 | [diff] [blame] | 1587 | project_pyl_path = os.path.join(self.args.infra_config_dir, 'generated', |
| 1588 | 'project.pyl') |
| 1589 | if os.path.exists(project_pyl_path): |
| 1590 | settings = ast.literal_eval(self.read_file(project_pyl_path)) |
| 1591 | if not settings.get('validate_source_side_specs_have_builder', True): |
| 1592 | return None |
| 1593 | |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1594 | bot_names = set() |
Garrett Beaty | d5ca7596 | 2020-05-07 16:58:31 | [diff] [blame] | 1595 | milo_configs = glob.glob( |
Garrett Beaty | ff6e98d | 2021-09-02 17:00:16 | [diff] [blame] | 1596 | os.path.join(self.args.infra_config_dir, 'generated', 'luci', |
| 1597 | 'luci-milo*.cfg')) |
John Budorick | c12abd1 | 2018-08-14 19:37:43 | [diff] [blame] | 1598 | for c in milo_configs: |
| 1599 | for l in self.read_file(c).splitlines(): |
| 1600 | if (not 'name: "buildbucket/luci.chromium.' in l and |
Garrett Beaty | d5ca7596 | 2020-05-07 16:58:31 | [diff] [blame] | 1601 | not 'name: "buildbucket/luci.chrome.' in l): |
John Budorick | c12abd1 | 2018-08-14 19:37:43 | [diff] [blame] | 1602 | continue |
| 1603 | # l looks like |
| 1604 | # `name: "buildbucket/luci.chromium.try/win_chromium_dbg_ng"` |
| 1605 | # Extract win_chromium_dbg_ng part. |
| 1606 | bot_names.add(l[l.rindex('/') + 1:l.rindex('"')]) |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1607 | return bot_names |
| 1608 | |
Ben Pastene | 9a01008 | 2019-09-25 20:41:37 | [diff] [blame] | 1609 | def get_internal_waterfalls(self): |
| 1610 | # Similar to get_builders_that_do_not_actually_exist above, but for |
| 1611 | # waterfalls defined in internal configs. |
Yuke Liao | e6c23dd | 2021-07-28 16:12:20 | [diff] [blame] | 1612 | return [ |
Kramer Ge | 3bf853a | 2023-04-13 19:39:47 | [diff] [blame] | 1613 | 'chrome', 'chrome.pgo', 'chrome.gpu.fyi', 'internal.chrome.fyi', |
Marco Georgaklis | 333e8386b | 2023-09-07 22:46:33 | [diff] [blame] | 1614 | 'internal.chromeos.fyi', 'internal.optimization_guide', 'internal.soda' |
Yuke Liao | e6c23dd | 2021-07-28 16:12:20 | [diff] [blame] | 1615 | ] |
Ben Pastene | 9a01008 | 2019-09-25 20:41:37 | [diff] [blame] | 1616 | |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1617 | def check_input_file_consistency(self, verbose=False): |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1618 | self.check_input_files_sorting(verbose) |
| 1619 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1620 | self.load_configuration_files() |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1621 | self.check_composition_type_test_suites('compound_suites') |
Jeff Yoon | 67c3e83 | 2020-02-08 07:39:38 | [diff] [blame] | 1622 | self.check_composition_type_test_suites('matrix_compound_suites', |
| 1623 | [check_matrix_identifier]) |
Chan Li | a3ad150 | 2020-04-28 05:32:11 | [diff] [blame] | 1624 | self.resolve_test_id_prefixes() |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1625 | self.flatten_test_suites() |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1626 | |
| 1627 | # All bots should exist. |
| 1628 | bot_names = self.get_valid_bot_names() |
Garrett Beaty | 2a02de3c | 2020-05-15 13:57:35 | [diff] [blame] | 1629 | if bot_names is not None: |
| 1630 | internal_waterfalls = self.get_internal_waterfalls() |
| 1631 | for waterfall in self.waterfalls: |
| 1632 | # TODO(crbug.com/991417): Remove the need for this exception. |
| 1633 | if waterfall['name'] in internal_waterfalls: |
Kenneth Russell | 8a386d4 | 2018-06-02 09:48:01 | [diff] [blame] | 1634 | continue # pragma: no cover |
Garrett Beaty | 2a02de3c | 2020-05-15 13:57:35 | [diff] [blame] | 1635 | for bot_name in waterfall['machines']: |
Garrett Beaty | 2a02de3c | 2020-05-15 13:57:35 | [diff] [blame] | 1636 | if bot_name not in bot_names: |
Garrett Beaty | b989592 | 2022-04-18 23:34:58 | [diff] [blame] | 1637 | if waterfall['name'] in [ |
| 1638 | 'client.v8.chromium', 'client.v8.fyi', 'tryserver.v8' |
| 1639 | ]: |
Garrett Beaty | 2a02de3c | 2020-05-15 13:57:35 | [diff] [blame] | 1640 | # TODO(thakis): Remove this once these bots move to luci. |
| 1641 | continue # pragma: no cover |
| 1642 | if waterfall['name'] in ['tryserver.webrtc', |
| 1643 | 'webrtc.chromium.fyi.experimental']: |
| 1644 | # These waterfalls have their bot configs in a different repo. |
| 1645 | # so we don't know about their bot names. |
| 1646 | continue # pragma: no cover |
| 1647 | if waterfall['name'] in ['client.devtools-frontend.integration', |
| 1648 | 'tryserver.devtools-frontend', |
| 1649 | 'chromium.devtools-frontend']: |
| 1650 | continue # pragma: no cover |
Garrett Beaty | 48d261a | 2020-09-17 22:11:20 | [diff] [blame] | 1651 | if waterfall['name'] in ['client.openscreen.chromium']: |
| 1652 | continue # pragma: no cover |
Garrett Beaty | 2a02de3c | 2020-05-15 13:57:35 | [diff] [blame] | 1653 | raise self.unknown_bot(bot_name, waterfall['name']) |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1654 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1655 | # All test suites must be referenced. |
| 1656 | suites_seen = set() |
| 1657 | generator_map = self.get_test_generator_map() |
| 1658 | for waterfall in self.waterfalls: |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1659 | for bot_name, tester in waterfall['machines'].items(): |
| 1660 | for suite_type, suite in tester.get('test_suites', {}).items(): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1661 | if suite_type not in generator_map: |
| 1662 | raise self.unknown_test_suite_type(suite_type, bot_name, |
| 1663 | waterfall['name']) |
| 1664 | if suite not in self.test_suites: |
| 1665 | raise self.unknown_test_suite(suite, bot_name, waterfall['name']) |
| 1666 | suites_seen.add(suite) |
| 1667 | # Since we didn't resolve the configuration files, this set |
| 1668 | # includes both composition test suites and regular ones. |
| 1669 | resolved_suites = set() |
| 1670 | for suite_name in suites_seen: |
| 1671 | suite = self.test_suites[suite_name] |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1672 | for sub_suite in suite: |
| 1673 | resolved_suites.add(sub_suite) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1674 | resolved_suites.add(suite_name) |
| 1675 | # At this point, every key in test_suites.pyl should be referenced. |
| 1676 | missing_suites = set(self.test_suites.keys()) - resolved_suites |
| 1677 | if missing_suites: |
| 1678 | raise BBGenErr('The following test suites were unreferenced by bots on ' |
| 1679 | 'the waterfalls: ' + str(missing_suites)) |
| 1680 | |
| 1681 | # All test suite exceptions must refer to bots on the waterfall. |
| 1682 | all_bots = set() |
| 1683 | missing_bots = set() |
| 1684 | for waterfall in self.waterfalls: |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1685 | for bot_name, tester in waterfall['machines'].items(): |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1686 | all_bots.add(bot_name) |
Kenneth Russell | 8ceeabf | 2017-12-11 17:53:28 | [diff] [blame] | 1687 | # In order to disambiguate between bots with the same name on |
| 1688 | # different waterfalls, support has been added to various |
| 1689 | # exceptions for concatenating the waterfall name after the bot |
| 1690 | # name. |
| 1691 | all_bots.add(bot_name + ' ' + waterfall['name']) |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1692 | for exception in self.exceptions.values(): |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1693 | removals = (exception.get('remove_from', []) + |
| 1694 | exception.get('remove_gtest_from', []) + |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1695 | list(exception.get('modifications', {}).keys())) |
Nico Weber | d18b896 | 2018-05-16 19:39:38 | [diff] [blame] | 1696 | for removal in removals: |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1697 | if removal not in all_bots: |
| 1698 | missing_bots.add(removal) |
Stephen Martinis | cc70c96 | 2018-07-31 21:22:41 | [diff] [blame] | 1699 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 1700 | if missing_bots: |
| 1701 | raise BBGenErr('The following nonexistent machines were referenced in ' |
| 1702 | 'the test suite exceptions: ' + str(missing_bots)) |
| 1703 | |
Garrett Beaty | b061e69d | 2023-06-27 16:15:35 | [diff] [blame] | 1704 | for name, mixin in self.mixins.items(): |
| 1705 | if '$mixin_append' in mixin: |
| 1706 | raise BBGenErr( |
| 1707 | f'$mixin_append is no longer supported (set in mixin "{name}"),' |
| 1708 | ' args and named caches specified as normal will be appended') |
| 1709 | |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1710 | # All mixins must be referenced |
| 1711 | seen_mixins = set() |
| 1712 | for waterfall in self.waterfalls: |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1713 | seen_mixins = seen_mixins.union(waterfall.get('mixins', set())) |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1714 | for bot_name, tester in waterfall['machines'].items(): |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1715 | seen_mixins = seen_mixins.union(tester.get('mixins', set())) |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1716 | for suite in self.test_suites.values(): |
| 1717 | if isinstance(suite, list): |
| 1718 | # Don't care about this, it's a composition, which shouldn't include a |
| 1719 | # swarming mixin. |
| 1720 | continue |
| 1721 | |
| 1722 | for test in suite.values(): |
Dirk Pranke | 0e879b2 | 2020-07-16 23:53:56 | [diff] [blame] | 1723 | assert isinstance(test, dict) |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1724 | seen_mixins = seen_mixins.union(test.get('mixins', set())) |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1725 | |
Zhaoyang Li | 9da047d5 | 2021-05-10 21:31:44 | [diff] [blame] | 1726 | for variant in self.variants: |
| 1727 | # Unpack the variant from variants.pyl if it's string based. |
| 1728 | if isinstance(variant, str): |
| 1729 | variant = self.variants[variant] |
| 1730 | seen_mixins = seen_mixins.union(variant.get('mixins', set())) |
| 1731 | |
Stephen Martinis | b72f6d2 | 2018-10-04 23:29:01 | [diff] [blame] | 1732 | missing_mixins = set(self.mixins.keys()) - seen_mixins |
Stephen Martinis | 0382bc1 | 2018-09-17 22:29:07 | [diff] [blame] | 1733 | if missing_mixins: |
| 1734 | raise BBGenErr('The following mixins are unreferenced: %s. They must be' |
| 1735 | ' referenced in a waterfall, machine, or test suite.' % ( |
| 1736 | str(missing_mixins))) |
| 1737 | |
Jeff Yoon | da581c3 | 2020-03-06 03:56:05 | [diff] [blame] | 1738 | # All variant references must be referenced |
| 1739 | seen_variants = set() |
| 1740 | for suite in self.test_suites.values(): |
| 1741 | if isinstance(suite, list): |
| 1742 | continue |
| 1743 | |
| 1744 | for test in suite.values(): |
| 1745 | if isinstance(test, dict): |
| 1746 | for variant in test.get('variants', []): |
| 1747 | if isinstance(variant, str): |
| 1748 | seen_variants.add(variant) |
| 1749 | |
| 1750 | missing_variants = set(self.variants.keys()) - seen_variants |
| 1751 | if missing_variants: |
| 1752 | raise BBGenErr('The following variants were unreferenced: %s. They must ' |
| 1753 | 'be referenced in a matrix test suite under the variants ' |
| 1754 | 'key.' % str(missing_variants)) |
| 1755 | |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1756 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1757 | def type_assert(self, node, typ, file_path, verbose=False): |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1758 | """Asserts that the Python AST node |node| is of type |typ|. |
| 1759 | |
| 1760 | If verbose is set, it prints out some helpful context lines, showing where |
| 1761 | exactly the error occurred in the file. |
| 1762 | """ |
| 1763 | if not isinstance(node, typ): |
| 1764 | if verbose: |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1765 | lines = [""] + self.read_file(file_path).splitlines() |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1766 | |
| 1767 | context = 2 |
| 1768 | lines_start = max(node.lineno - context, 0) |
| 1769 | # Add one to include the last line |
| 1770 | lines_end = min(node.lineno + context, len(lines)) + 1 |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1771 | lines = itertools.chain( |
| 1772 | ['== %s ==\n' % file_path], |
| 1773 | ["<snip>\n"], |
| 1774 | [ |
| 1775 | '%d %s' % (lines_start + i, line) |
| 1776 | for i, line in enumerate(lines[lines_start:lines_start + |
| 1777 | context]) |
| 1778 | ], |
| 1779 | ['-' * 80 + '\n'], |
| 1780 | ['%d %s' % (node.lineno, lines[node.lineno])], |
| 1781 | [ |
| 1782 | '-' * (node.col_offset + 3) + '^' + '-' * |
| 1783 | (80 - node.col_offset - 4) + '\n' |
| 1784 | ], |
| 1785 | [ |
| 1786 | '%d %s' % (node.lineno + 1 + i, line) |
| 1787 | for i, line in enumerate(lines[node.lineno + 1:lines_end]) |
| 1788 | ], |
| 1789 | ["<snip>\n"], |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1790 | ) |
| 1791 | # Print out a useful message when a type assertion fails. |
| 1792 | for l in lines: |
| 1793 | self.print_line(l.strip()) |
| 1794 | |
| 1795 | node_dumped = ast.dump(node, annotate_fields=False) |
| 1796 | # If the node is huge, truncate it so everything fits in a terminal |
| 1797 | # window. |
| 1798 | if len(node_dumped) > 60: # pragma: no cover |
| 1799 | node_dumped = node_dumped[:30] + ' <SNIP> ' + node_dumped[-30:] |
| 1800 | raise BBGenErr( |
Garrett Beaty | 807011ab | 2023-04-12 00:52:39 | [diff] [blame] | 1801 | 'Invalid .pyl file \'%s\'. Python AST node %r on line %s expected to' |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1802 | ' be %s, is %s' % |
| 1803 | (file_path, node_dumped, node.lineno, typ, type(node))) |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1804 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1805 | def check_ast_list_formatted(self, |
| 1806 | keys, |
| 1807 | file_path, |
| 1808 | verbose, |
Stephen Martinis | 1384ff9 | 2020-01-07 19:52:15 | [diff] [blame] | 1809 | check_sorting=True): |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1810 | """Checks if a list of ast keys are correctly formatted. |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1811 | |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1812 | Currently only checks to ensure they're correctly sorted, and that there |
| 1813 | are no duplicates. |
| 1814 | |
| 1815 | Args: |
| 1816 | keys: An python list of AST nodes. |
| 1817 | |
| 1818 | It's a list of AST nodes instead of a list of strings because |
| 1819 | when verbose is set, it tries to print out context of where the |
| 1820 | diffs are in the file. |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1821 | file_path: The path to the file this node is from. |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1822 | verbose: If set, print out diff information about how the keys are |
| 1823 | incorrectly formatted. |
| 1824 | check_sorting: If true, checks if the list is sorted. |
| 1825 | Returns: |
| 1826 | If the keys are correctly formatted. |
| 1827 | """ |
| 1828 | if not keys: |
| 1829 | return True |
| 1830 | |
| 1831 | assert isinstance(keys[0], ast.Str) |
| 1832 | |
| 1833 | keys_strs = [k.s for k in keys] |
| 1834 | # Keys to diff against. Used below. |
| 1835 | keys_to_diff_against = None |
| 1836 | # If the list is properly formatted. |
| 1837 | list_formatted = True |
| 1838 | |
| 1839 | # Duplicates are always bad. |
| 1840 | if len(set(keys_strs)) != len(keys_strs): |
| 1841 | list_formatted = False |
| 1842 | keys_to_diff_against = list(collections.OrderedDict.fromkeys(keys_strs)) |
| 1843 | |
| 1844 | if check_sorting and sorted(keys_strs) != keys_strs: |
| 1845 | list_formatted = False |
| 1846 | if list_formatted: |
| 1847 | return True |
| 1848 | |
| 1849 | if verbose: |
| 1850 | line_num = keys[0].lineno |
| 1851 | keys = [k.s for k in keys] |
| 1852 | if check_sorting: |
| 1853 | # If we have duplicates, sorting this will take care of it anyways. |
| 1854 | keys_to_diff_against = sorted(set(keys)) |
| 1855 | # else, keys_to_diff_against is set above already |
| 1856 | |
| 1857 | self.print_line('=' * 80) |
| 1858 | self.print_line('(First line of keys is %s)' % line_num) |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1859 | for line in difflib.context_diff(keys, |
| 1860 | keys_to_diff_against, |
| 1861 | fromfile='current (%r)' % file_path, |
| 1862 | tofile='sorted', |
| 1863 | lineterm=''): |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1864 | self.print_line(line) |
| 1865 | self.print_line('=' * 80) |
| 1866 | |
| 1867 | return False |
| 1868 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1869 | def check_ast_dict_formatted(self, node, file_path, verbose): |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1870 | """Checks if an ast dictionary's keys are correctly formatted. |
| 1871 | |
| 1872 | Just a simple wrapper around check_ast_list_formatted. |
| 1873 | Args: |
| 1874 | node: An AST node. Assumed to be a dictionary. |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1875 | file_path: The path to the file this node is from. |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1876 | verbose: If set, print out diff information about how the keys are |
| 1877 | incorrectly formatted. |
| 1878 | check_sorting: If true, checks if the list is sorted. |
| 1879 | Returns: |
| 1880 | If the dictionary is correctly formatted. |
| 1881 | """ |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1882 | keys = [] |
| 1883 | # The keys of this dict are ordered as ordered in the file; normal python |
| 1884 | # dictionary keys are given an arbitrary order, but since we parsed the |
| 1885 | # file itself, the order as given in the file is preserved. |
| 1886 | for key in node.keys: |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1887 | self.type_assert(key, ast.Str, file_path, verbose) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1888 | keys.append(key) |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1889 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1890 | return self.check_ast_list_formatted(keys, file_path, verbose) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1891 | |
| 1892 | def check_input_files_sorting(self, verbose=False): |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1893 | # TODO(https://crbug.com/886993): Add the ability for this script to |
| 1894 | # actually format the files, rather than just complain if they're |
| 1895 | # incorrectly formatted. |
| 1896 | bad_files = set() |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1897 | |
| 1898 | def parse_file(file_path): |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1899 | """Parses and validates a .pyl file. |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1900 | |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1901 | Returns an AST node representing the value in the pyl file.""" |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1902 | parsed = ast.parse(self.read_file(file_path)) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1903 | |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1904 | # Must be a module. |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1905 | self.type_assert(parsed, ast.Module, file_path, verbose) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1906 | module = parsed.body |
| 1907 | |
| 1908 | # Only one expression in the module. |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1909 | self.type_assert(module, list, file_path, verbose) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1910 | if len(module) != 1: # pragma: no cover |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1911 | raise BBGenErr('Invalid .pyl file %s' % file_path) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1912 | expr = module[0] |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1913 | self.type_assert(expr, ast.Expr, file_path, verbose) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1914 | |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1915 | return expr.value |
| 1916 | |
| 1917 | # Handle this separately |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1918 | value = parse_file(self.args.waterfalls_pyl_path) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1919 | # Value should be a list. |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1920 | self.type_assert(value, ast.List, self.args.waterfalls_pyl_path, verbose) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1921 | |
| 1922 | keys = [] |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 1923 | for elm in value.elts: |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1924 | self.type_assert(elm, ast.Dict, self.args.waterfalls_pyl_path, verbose) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1925 | waterfall_name = None |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 1926 | for key, val in zip(elm.keys, elm.values): |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1927 | self.type_assert(key, ast.Str, self.args.waterfalls_pyl_path, verbose) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1928 | if key.s == 'machines': |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1929 | if not self.check_ast_dict_formatted( |
| 1930 | val, self.args.waterfalls_pyl_path, verbose): |
| 1931 | bad_files.add(self.args.waterfalls_pyl_path) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1932 | |
| 1933 | if key.s == "name": |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1934 | self.type_assert(val, ast.Str, self.args.waterfalls_pyl_path, verbose) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1935 | waterfall_name = val |
| 1936 | assert waterfall_name |
| 1937 | keys.append(waterfall_name) |
| 1938 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1939 | if not self.check_ast_list_formatted(keys, self.args.waterfalls_pyl_path, |
| 1940 | verbose): |
| 1941 | bad_files.add(self.args.waterfalls_pyl_path) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1942 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1943 | for file_path in ( |
| 1944 | self.args.mixins_pyl_path, |
| 1945 | self.args.test_suites_pyl_path, |
| 1946 | self.args.test_suite_exceptions_pyl_path, |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1947 | ): |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1948 | value = parse_file(file_path) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1949 | # Value should be a dictionary. |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1950 | self.type_assert(value, ast.Dict, file_path, verbose) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1951 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1952 | if not self.check_ast_dict_formatted(value, file_path, verbose): |
| 1953 | bad_files.add(file_path) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1954 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1955 | if file_path == self.args.test_suites_pyl_path: |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1956 | expected_keys = ['basic_suites', |
| 1957 | 'compound_suites', |
| 1958 | 'matrix_compound_suites'] |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1959 | actual_keys = [node.s for node in value.keys] |
| 1960 | assert all(key in expected_keys for key in actual_keys), ( |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1961 | 'Invalid %r file; expected keys %r, got %r' % |
| 1962 | (file_path, expected_keys, actual_keys)) |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 1963 | suite_dicts = list(value.values) |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1964 | # Only two keys should mean only 1 or 2 values |
Jeff Yoon | 8154e58 | 2019-12-03 23:30:01 | [diff] [blame] | 1965 | assert len(suite_dicts) <= 3 |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1966 | for suite_group in suite_dicts: |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1967 | if not self.check_ast_dict_formatted(suite_group, file_path, verbose): |
| 1968 | bad_files.add(file_path) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1969 | |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1970 | for key, suite in zip(value.keys, value.values): |
| 1971 | # The compound suites are checked in |
| 1972 | # 'check_composition_type_test_suites()' |
| 1973 | if key.s == 'basic_suites': |
| 1974 | for group in suite.values: |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1975 | if not self.check_ast_dict_formatted(group, file_path, verbose): |
| 1976 | bad_files.add(file_path) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1977 | break |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1978 | |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1979 | elif file_path == self.args.test_suite_exceptions_pyl_path: |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1980 | # Check the values for each test. |
| 1981 | for test in value.values: |
| 1982 | for kind, node in zip(test.keys, test.values): |
| 1983 | if isinstance(node, ast.Dict): |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1984 | if not self.check_ast_dict_formatted(node, file_path, verbose): |
| 1985 | bad_files.add(file_path) |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1986 | elif kind.s == 'remove_from': |
| 1987 | # Don't care about sorting; these are usually grouped, since the |
| 1988 | # same bug can affect multiple builders. Do want to make sure |
| 1989 | # there aren't duplicates. |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 1990 | if not self.check_ast_list_formatted( |
| 1991 | node.elts, file_path, verbose, check_sorting=False): |
| 1992 | bad_files.add(file_path) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1993 | |
| 1994 | if bad_files: |
| 1995 | raise BBGenErr( |
Stephen Martinis | 54d64ad | 2018-09-21 22:16:20 | [diff] [blame] | 1996 | 'The following files have invalid keys: %s\n. They are either ' |
Stephen Martinis | 5bef0fc | 2020-01-06 22:47:53 | [diff] [blame] | 1997 | 'unsorted, or have duplicates. Re-run this with --verbose to see ' |
| 1998 | 'more details.' % ', '.join(bad_files)) |
Stephen Martinis | f8389372 | 2018-09-19 00:02:18 | [diff] [blame] | 1999 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2000 | def check_output_file_consistency(self, verbose=False): |
| 2001 | self.load_configuration_files() |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2002 | # All waterfalls/bucket .json files must have been written |
| 2003 | # by this script already. |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2004 | self.resolve_configuration_files() |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2005 | ungenerated_files = set() |
Dirk Pranke | 772f55f | 2021-04-28 04:51:16 | [diff] [blame] | 2006 | outputs = self.generate_outputs() |
| 2007 | for filename, expected_contents in outputs.items(): |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2008 | expected = self.jsonify(expected_contents) |
Garrett Beaty | 79339e18 | 2023-04-10 20:45:47 | [diff] [blame] | 2009 | file_path = os.path.join(self.args.output_dir, filename + '.json') |
Ben Pastene | f21cda3 | 2023-03-30 22:00:57 | [diff] [blame] | 2010 | current = self.read_file(file_path) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2011 | if expected != current: |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2012 | ungenerated_files.add(filename) |
John Budorick | 826d5ed | 2017-12-28 19:27:32 | [diff] [blame] | 2013 | if verbose: # pragma: no cover |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2014 | self.print_line('File ' + filename + |
| 2015 | '.json did not have the following expected ' |
John Budorick | 826d5ed | 2017-12-28 19:27:32 | [diff] [blame] | 2016 | 'contents:') |
| 2017 | for line in difflib.unified_diff( |
| 2018 | expected.splitlines(), |
Stephen Martinis | 7eb8b61 | 2018-09-21 00:17:50 | [diff] [blame] | 2019 | current.splitlines(), |
| 2020 | fromfile='expected', tofile='current'): |
| 2021 | self.print_line(line) |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2022 | |
| 2023 | if ungenerated_files: |
| 2024 | raise BBGenErr( |
| 2025 | 'The following files have not been properly ' |
| 2026 | 'autogenerated by generate_buildbot_json.py: ' + |
| 2027 | ', '.join([filename + '.json' for filename in ungenerated_files])) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2028 | |
Dirk Pranke | 772f55f | 2021-04-28 04:51:16 | [diff] [blame] | 2029 | for builder_group, builders in outputs.items(): |
| 2030 | for builder, step_types in builders.items(): |
Garrett Beaty | dca3d88 | 2023-09-14 23:50:32 | [diff] [blame] | 2031 | for test_type in ('gtest_tests', 'isolated_scripts'): |
| 2032 | for step_data in step_types.get(test_type, []): |
| 2033 | step_name = step_data['name'] |
| 2034 | self._check_swarming_config(builder_group, builder, step_name, |
| 2035 | step_data) |
Dirk Pranke | 772f55f | 2021-04-28 04:51:16 | [diff] [blame] | 2036 | |
| 2037 | def _check_swarming_config(self, filename, builder, step_name, step_data): |
Ben Pastene | 338f56b | 2023-03-31 21:24:45 | [diff] [blame] | 2038 | # TODO(crbug.com/1203436): Ensure all swarming tests specify cpu, not |
Dirk Pranke | 772f55f | 2021-04-28 04:51:16 | [diff] [blame] | 2039 | # just mac tests. |
Garrett Beaty | bb18d53 | 2023-06-26 22:16:33 | [diff] [blame] | 2040 | if 'swarming' in step_data: |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 2041 | dimensions = step_data['swarming'].get('dimensions') |
| 2042 | if not dimensions: |
Ben Pastene | 338f56b | 2023-03-31 21:24:45 | [diff] [blame] | 2043 | raise BBGenErr('%s: %s / %s : os must be specified for all ' |
Dirk Pranke | 772f55f | 2021-04-28 04:51:16 | [diff] [blame] | 2044 | 'swarmed tests' % (filename, builder, step_name)) |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 2045 | if not dimensions.get('os'): |
| 2046 | raise BBGenErr('%s: %s / %s : os must be specified for all ' |
| 2047 | 'swarmed tests' % (filename, builder, step_name)) |
| 2048 | if 'Mac' in dimensions.get('os') and not dimensions.get('cpu'): |
| 2049 | raise BBGenErr('%s: %s / %s : cpu must be specified for mac ' |
| 2050 | 'swarmed tests' % (filename, builder, step_name)) |
Dirk Pranke | 772f55f | 2021-04-28 04:51:16 | [diff] [blame] | 2051 | |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2052 | def check_consistency(self, verbose=False): |
Stephen Martinis | 7eb8b61 | 2018-09-21 00:17:50 | [diff] [blame] | 2053 | self.check_input_file_consistency(verbose) # pragma: no cover |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2054 | self.check_output_file_consistency(verbose) # pragma: no cover |
| 2055 | |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2056 | def does_test_match(self, test_info, params_dict): |
| 2057 | """Checks to see if the test matches the parameters given. |
| 2058 | |
| 2059 | Compares the provided test_info with the params_dict to see |
| 2060 | if the bot matches the parameters given. If so, returns True. |
| 2061 | Else, returns false. |
| 2062 | |
| 2063 | Args: |
| 2064 | test_info (dict): Information about a specific bot provided |
| 2065 | in the format shown in waterfalls.pyl |
| 2066 | params_dict (dict): Dictionary of parameters and their values |
| 2067 | to look for in the bot |
| 2068 | Ex: { |
| 2069 | 'device_os':'android', |
| 2070 | '--flag':True, |
| 2071 | 'mixins': ['mixin1', 'mixin2'], |
| 2072 | 'ex_key':'ex_value' |
| 2073 | } |
| 2074 | |
| 2075 | """ |
| 2076 | DIMENSION_PARAMS = ['device_os', 'device_type', 'os', |
| 2077 | 'kvm', 'pool', 'integrity'] # dimension parameters |
| 2078 | SWARMING_PARAMS = ['shards', 'hard_timeout', 'idempotent', |
| 2079 | 'can_use_on_swarming_builders'] |
| 2080 | for param in params_dict: |
| 2081 | # if dimension parameter |
| 2082 | if param in DIMENSION_PARAMS or param in SWARMING_PARAMS: |
| 2083 | if not 'swarming' in test_info: |
| 2084 | return False |
| 2085 | swarming = test_info['swarming'] |
| 2086 | if param in SWARMING_PARAMS: |
| 2087 | if not param in swarming: |
| 2088 | return False |
| 2089 | if not str(swarming[param]) == params_dict[param]: |
| 2090 | return False |
| 2091 | else: |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 2092 | if not 'dimensions' in swarming: |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2093 | return False |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 2094 | dimensions = swarming['dimensions'] |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2095 | # only looking at the first dimension set |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 2096 | if not param in dimensions: |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2097 | return False |
Garrett Beaty | ade673d | 2023-08-04 22:00:25 | [diff] [blame] | 2098 | if not dimensions[param] == params_dict[param]: |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2099 | return False |
| 2100 | |
| 2101 | # if flag |
| 2102 | elif param.startswith('--'): |
| 2103 | if not 'args' in test_info: |
| 2104 | return False |
| 2105 | if not param in test_info['args']: |
| 2106 | return False |
| 2107 | |
| 2108 | # not dimension parameter/flag/mixin |
| 2109 | else: |
| 2110 | if not param in test_info: |
| 2111 | return False |
| 2112 | if not test_info[param] == params_dict[param]: |
| 2113 | return False |
| 2114 | return True |
| 2115 | def error_msg(self, msg): |
| 2116 | """Prints an error message. |
| 2117 | |
| 2118 | In addition to a catered error message, also prints |
| 2119 | out where the user can find more help. Then, program exits. |
| 2120 | """ |
| 2121 | self.print_line(msg + (' If you need more information, ' + |
| 2122 | 'please run with -h or --help to see valid commands.')) |
| 2123 | sys.exit(1) |
| 2124 | |
| 2125 | def find_bots_that_run_test(self, test, bots): |
| 2126 | matching_bots = [] |
| 2127 | for bot in bots: |
| 2128 | bot_info = bots[bot] |
| 2129 | tests = self.flatten_tests_for_bot(bot_info) |
| 2130 | for test_info in tests: |
Garrett Beaty | ffe83c4f | 2023-09-08 19:07:37 | [diff] [blame] | 2131 | test_name = test_info['name'] |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2132 | if not test_name == test: |
| 2133 | continue |
| 2134 | matching_bots.append(bot) |
| 2135 | return matching_bots |
| 2136 | |
| 2137 | def find_tests_with_params(self, tests, params_dict): |
| 2138 | matching_tests = [] |
| 2139 | for test_name in tests: |
| 2140 | test_info = tests[test_name] |
| 2141 | if not self.does_test_match(test_info, params_dict): |
| 2142 | continue |
| 2143 | if not test_name in matching_tests: |
| 2144 | matching_tests.append(test_name) |
| 2145 | return matching_tests |
| 2146 | |
| 2147 | def flatten_waterfalls_for_query(self, waterfalls): |
| 2148 | bots = {} |
| 2149 | for waterfall in waterfalls: |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2150 | waterfall_tests = self.generate_output_tests(waterfall) |
| 2151 | for bot in waterfall_tests: |
| 2152 | bot_info = waterfall_tests[bot] |
| 2153 | bots[bot] = bot_info |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2154 | return bots |
| 2155 | |
| 2156 | def flatten_tests_for_bot(self, bot_info): |
| 2157 | """Returns a list of flattened tests. |
| 2158 | |
| 2159 | Returns a list of tests not grouped by test category |
| 2160 | for a specific bot. |
| 2161 | """ |
| 2162 | TEST_CATS = self.get_test_generator_map().keys() |
| 2163 | tests = [] |
| 2164 | for test_cat in TEST_CATS: |
| 2165 | if not test_cat in bot_info: |
| 2166 | continue |
| 2167 | test_cat_tests = bot_info[test_cat] |
| 2168 | tests = tests + test_cat_tests |
| 2169 | return tests |
| 2170 | |
| 2171 | def flatten_tests_for_query(self, test_suites): |
| 2172 | """Returns a flattened dictionary of tests. |
| 2173 | |
| 2174 | Returns a dictionary of tests associate with their |
| 2175 | configuration, not grouped by their test suite. |
| 2176 | """ |
| 2177 | tests = {} |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 2178 | for test_suite in test_suites.values(): |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2179 | for test in test_suite: |
| 2180 | test_info = test_suite[test] |
| 2181 | test_name = test |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2182 | tests[test_name] = test_info |
| 2183 | return tests |
| 2184 | |
| 2185 | def parse_query_filter_params(self, params): |
| 2186 | """Parses the filter parameters. |
| 2187 | |
| 2188 | Creates a dictionary from the parameters provided |
| 2189 | to filter the bot array. |
| 2190 | """ |
| 2191 | params_dict = {} |
| 2192 | for p in params: |
| 2193 | # flag |
| 2194 | if p.startswith("--"): |
| 2195 | params_dict[p] = True |
| 2196 | else: |
| 2197 | pair = p.split(":") |
| 2198 | if len(pair) != 2: |
| 2199 | self.error_msg('Invalid command.') |
| 2200 | # regular parameters |
| 2201 | if pair[1].lower() == "true": |
| 2202 | params_dict[pair[0]] = True |
| 2203 | elif pair[1].lower() == "false": |
| 2204 | params_dict[pair[0]] = False |
| 2205 | else: |
| 2206 | params_dict[pair[0]] = pair[1] |
| 2207 | return params_dict |
| 2208 | |
| 2209 | def get_test_suites_dict(self, bots): |
| 2210 | """Returns a dictionary of bots and their tests. |
| 2211 | |
| 2212 | Returns a dictionary of bots and a list of their associated tests. |
| 2213 | """ |
| 2214 | test_suite_dict = dict() |
| 2215 | for bot in bots: |
| 2216 | bot_info = bots[bot] |
| 2217 | tests = self.flatten_tests_for_bot(bot_info) |
| 2218 | test_suite_dict[bot] = tests |
| 2219 | return test_suite_dict |
| 2220 | |
| 2221 | def output_query_result(self, result, json_file=None): |
| 2222 | """Outputs the result of the query. |
| 2223 | |
| 2224 | If a json file parameter name is provided, then |
| 2225 | the result is output into the json file. If not, |
| 2226 | then the result is printed to the console. |
| 2227 | """ |
| 2228 | output = json.dumps(result, indent=2) |
| 2229 | if json_file: |
| 2230 | self.write_file(json_file, output) |
| 2231 | else: |
| 2232 | self.print_line(output) |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2233 | |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 2234 | # pylint: disable=inconsistent-return-statements |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2235 | def query(self, args): |
| 2236 | """Queries tests or bots. |
| 2237 | |
| 2238 | Depending on the arguments provided, outputs a json of |
| 2239 | tests or bots matching the appropriate optional parameters provided. |
| 2240 | """ |
| 2241 | # split up query statement |
| 2242 | query = args.query.split('/') |
| 2243 | self.load_configuration_files() |
| 2244 | self.resolve_configuration_files() |
| 2245 | |
| 2246 | # flatten bots json |
| 2247 | tests = self.test_suites |
| 2248 | bots = self.flatten_waterfalls_for_query(self.waterfalls) |
| 2249 | |
| 2250 | cmd_class = query[0] |
| 2251 | |
| 2252 | # For queries starting with 'bots' |
| 2253 | if cmd_class == "bots": |
| 2254 | if len(query) == 1: |
| 2255 | return self.output_query_result(bots, args.json) |
| 2256 | # query with specific parameters |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 2257 | if len(query) == 2: |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2258 | if query[1] == 'tests': |
| 2259 | test_suites_dict = self.get_test_suites_dict(bots) |
| 2260 | return self.output_query_result(test_suites_dict, args.json) |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 2261 | self.error_msg("This query should be in the format: bots/tests.") |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2262 | |
| 2263 | else: |
| 2264 | self.error_msg("This query should have 0 or 1 '/', found %s instead." |
| 2265 | % str(len(query)-1)) |
| 2266 | |
| 2267 | # For queries starting with 'bot' |
| 2268 | elif cmd_class == "bot": |
| 2269 | if not len(query) == 2 and not len(query) == 3: |
| 2270 | self.error_msg("Command should have 1 or 2 '/', found %s instead." |
| 2271 | % str(len(query)-1)) |
| 2272 | bot_id = query[1] |
| 2273 | if not bot_id in bots: |
| 2274 | self.error_msg("No bot named '" + bot_id + "' found.") |
| 2275 | bot_info = bots[bot_id] |
| 2276 | if len(query) == 2: |
| 2277 | return self.output_query_result(bot_info, args.json) |
| 2278 | if not query[2] == 'tests': |
| 2279 | self.error_msg("The query should be in the format:" + |
| 2280 | "bot/<bot-name>/tests.") |
| 2281 | |
| 2282 | bot_tests = self.flatten_tests_for_bot(bot_info) |
| 2283 | return self.output_query_result(bot_tests, args.json) |
| 2284 | |
| 2285 | # For queries starting with 'tests' |
| 2286 | elif cmd_class == "tests": |
| 2287 | if not len(query) == 1 and not len(query) == 2: |
| 2288 | self.error_msg("The query should have 0 or 1 '/', found %s instead." |
| 2289 | % str(len(query)-1)) |
| 2290 | flattened_tests = self.flatten_tests_for_query(tests) |
| 2291 | if len(query) == 1: |
| 2292 | return self.output_query_result(flattened_tests, args.json) |
| 2293 | |
| 2294 | # create params dict |
| 2295 | params = query[1].split('&') |
| 2296 | params_dict = self.parse_query_filter_params(params) |
| 2297 | matching_bots = self.find_tests_with_params(flattened_tests, params_dict) |
| 2298 | return self.output_query_result(matching_bots) |
| 2299 | |
| 2300 | # For queries starting with 'test' |
| 2301 | elif cmd_class == "test": |
| 2302 | if not len(query) == 2 and not len(query) == 3: |
| 2303 | self.error_msg("The query should have 1 or 2 '/', found %s instead." |
| 2304 | % str(len(query)-1)) |
| 2305 | test_id = query[1] |
| 2306 | if len(query) == 2: |
| 2307 | flattened_tests = self.flatten_tests_for_query(tests) |
| 2308 | for test in flattened_tests: |
| 2309 | if test == test_id: |
| 2310 | return self.output_query_result(flattened_tests[test], args.json) |
| 2311 | self.error_msg("There is no test named %s." % test_id) |
| 2312 | if not query[2] == 'bots': |
| 2313 | self.error_msg("The query should be in the format: " + |
| 2314 | "test/<test-name>/bots") |
| 2315 | bots_for_test = self.find_bots_that_run_test(test_id, bots) |
| 2316 | return self.output_query_result(bots_for_test) |
| 2317 | |
| 2318 | else: |
| 2319 | self.error_msg("Your command did not match any valid commands." + |
| 2320 | "Try starting with 'bots', 'bot', 'tests', or 'test'.") |
Joshua Hood | 56c673c | 2022-03-02 20:29:33 | [diff] [blame] | 2321 | # pylint: enable=inconsistent-return-statements |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2322 | |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 2323 | def main(self): # pragma: no cover |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2324 | if self.args.check: |
Stephen Martinis | 7eb8b61 | 2018-09-21 00:17:50 | [diff] [blame] | 2325 | self.check_consistency(verbose=self.args.verbose) |
Karen Qian | e24b7ee | 2019-02-12 23:37:06 | [diff] [blame] | 2326 | elif self.args.query: |
| 2327 | self.query(self.args) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2328 | else: |
Greg Guterman | f60eb05 | 2020-03-12 17:40:01 | [diff] [blame] | 2329 | self.write_json_result(self.generate_outputs()) |
Kenneth Russell | eb60cbd2 | 2017-12-05 07:54:28 | [diff] [blame] | 2330 | return 0 |
| 2331 | |
| 2332 | if __name__ == "__main__": # pragma: no cover |
Garrett Beaty | 1afaccc | 2020-06-25 19:58:15 | [diff] [blame] | 2333 | generator = BBJSONGenerator(BBJSONGenerator.parse_args(sys.argv[1:])) |
| 2334 | sys.exit(generator.main()) |