1#!/usr/bin/env python 2# Copyright 2021 The ANGLE Project Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5"""Script to generate the test spec JSON files. Calls Chromium's generate_buildbot_json. 6 7=== NOTE: DO NOT RUN THIS SCRIPT DIRECTLY. === 8Run scripts/run_code_generation.py instead to update necessary hashes. 9 10""" 11 12import os 13import pprint 14import sys 15import subprocess 16 17d = os.path.dirname 18THIS_DIR = d(os.path.abspath(__file__)) 19TESTING_BBOT_DIR = os.path.join(d(d(THIS_DIR)), 'testing', 'buildbot') 20sys.path.insert(0, TESTING_BBOT_DIR) 21 22import generate_buildbot_json 23 24# Add custom mixins here. 25ADDITIONAL_MIXINS = { 26 'angle_skia_gold_test': { 27 '$mixin_append': { 28 'args': [ 29 '--git-revision=${got_angle_revision}', 30 # BREAK GLASS IN CASE OF EMERGENCY 31 # Uncommenting this argument will bypass all interactions with Skia 32 # Gold in any tests that use it. This is meant as a temporary 33 # emergency stop in case of a Gold outage that's affecting the bots. 34 # '--bypass-skia-gold-functionality', 35 ], 36 'precommit_args': [ 37 '--gerrit-issue=${patch_issue}', 38 '--gerrit-patchset=${patch_set}', 39 '--buildbucket-id=${buildbucket_build_id}', 40 ], 41 } 42 }, 43 44 # TODO(jmadill): De-duplicate when landed in Chrome. http://crbug.com/1236818 45 'angle_linux_nvidia_gtx_1660_stable': { 46 'swarming': { 47 'dimensions': { 48 'gpu': '10de:2184-440.100', 49 'os': 'Ubuntu-18.04.5|Ubuntu-18.04.6', 50 'pool': 'chromium.tests.gpu', 51 }, 52 }, 53 }, 54 'angle_win10_nvidia_gtx_1660_stable': { 55 'swarming': { 56 'dimensions': { 57 'gpu': '10de:2184-27.21.14.5638', 58 'os': 'Windows-10-18363', 59 'pool': 'chromium.tests.gpu', 60 }, 61 }, 62 }, 63} 64 65MIXIN_FILE_NAME = os.path.join(THIS_DIR, 'mixins.pyl') 66MIXINS_PYL_TEMPLATE = """\ 67# GENERATED FILE - DO NOT EDIT. 68# Generated by {script_name} using data from {data_source} 69# 70# Copyright 2021 The ANGLE Project Authors. All rights reserved. 71# Use of this source code is governed by a BSD-style license that can be 72# found in the LICENSE file. 73# 74# This is a .pyl, or "Python Literal", file. You can treat it just like a 75# .json file, with the following exceptions: 76# * all keys must be quoted (use single quotes, please); 77# * comments are allowed, using '#' syntax; and 78# * trailing commas are allowed. 79# 80# For more info see Chromium's mixins.pyl in testing/buildbot. 81 82{mixin_data} 83""" 84 85 86def main(): 87 if len(sys.argv) > 1: 88 gen_bb_json = os.path.join(TESTING_BBOT_DIR, 'generate_buildbot_json.py') 89 mixins_pyl = os.path.join(TESTING_BBOT_DIR, 'mixins.pyl') 90 inputs = [ 91 'test_suite_exceptions.pyl', 'test_suites.pyl', 'variants.pyl', 'waterfalls.pyl', 92 gen_bb_json, mixins_pyl 93 ] 94 outputs = ['angle.json', 'mixins.pyl'] 95 if sys.argv[1] == 'inputs': 96 print(','.join(inputs)) 97 elif sys.argv[1] == 'outputs': 98 print(','.join(outputs)) 99 else: 100 print('Invalid script parameters') 101 return 1 102 return 0 103 104 chromium_args = generate_buildbot_json.BBJSONGenerator.parse_args(sys.argv[1:]) 105 chromium_generator = generate_buildbot_json.BBJSONGenerator(chromium_args) 106 chromium_generator.load_configuration_files() 107 108 override_args = sys.argv[1:] + ['--pyl-files-dir', THIS_DIR] 109 angle_args = generate_buildbot_json.BBJSONGenerator.parse_args(override_args) 110 angle_generator = generate_buildbot_json.BBJSONGenerator(angle_args) 111 angle_generator.load_configuration_files() 112 angle_generator.resolve_configuration_files() 113 114 seen_mixins = set() 115 for waterfall in angle_generator.waterfalls: 116 seen_mixins = seen_mixins.union(waterfall.get('mixins', set())) 117 for bot_name, tester in waterfall['machines'].iteritems(): 118 seen_mixins = seen_mixins.union(tester.get('mixins', set())) 119 for suite in angle_generator.test_suites.values(): 120 if isinstance(suite, list): 121 # Don't care about this, it's a composition, which shouldn't include a 122 # swarming mixin. 123 continue 124 for test in suite.values(): 125 assert isinstance(test, dict) 126 seen_mixins = seen_mixins.union(test.get('mixins', set())) 127 128 found_mixins = ADDITIONAL_MIXINS.copy() 129 for mixin in seen_mixins: 130 if mixin in found_mixins: 131 continue 132 assert (mixin in chromium_generator.mixins) 133 found_mixins[mixin] = chromium_generator.mixins[mixin] 134 135 pp = pprint.PrettyPrinter(indent=2) 136 137 format_data = { 138 'script_name': os.path.basename(__file__), 139 'data_source': 'waterfall.pyl and Chromium\'s mixins.pyl', 140 'mixin_data': pp.pformat(found_mixins), 141 } 142 generated_mixin_pyl = MIXINS_PYL_TEMPLATE.format(**format_data) 143 144 with open(MIXIN_FILE_NAME, 'w') as f: 145 f.write(generated_mixin_pyl) 146 f.close() 147 148 return angle_generator.main() 149 150 151if __name__ == '__main__': # pragma: no cover 152 sys.exit(main()) 153