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