Path: blob/main_old/infra/specs/generate_test_spec_json.py
1701 views
#!/usr/bin/env python1# Copyright 2021 The ANGLE Project Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4"""Script to generate the test spec JSON files. Calls Chromium's generate_buildbot_json.56=== NOTE: DO NOT RUN THIS SCRIPT DIRECTLY. ===7Run scripts/run_code_generation.py instead to update necessary hashes.89"""1011import os12import pprint13import sys14import subprocess1516d = os.path.dirname17THIS_DIR = d(os.path.abspath(__file__))18TESTING_BBOT_DIR = os.path.join(d(d(THIS_DIR)), 'testing', 'buildbot')19sys.path.insert(0, TESTING_BBOT_DIR)2021import generate_buildbot_json2223# Add custom mixins here.24ADDITIONAL_MIXINS = {25'angle_skia_gold_test': {26'$mixin_append': {27'args': [28'--git-revision=${got_angle_revision}',29# BREAK GLASS IN CASE OF EMERGENCY30# Uncommenting this argument will bypass all interactions with Skia31# Gold in any tests that use it. This is meant as a temporary32# emergency stop in case of a Gold outage that's affecting the bots.33# '--bypass-skia-gold-functionality',34],35'precommit_args': [36'--gerrit-issue=${patch_issue}',37'--gerrit-patchset=${patch_set}',38'--buildbucket-id=${buildbucket_build_id}',39],40}41},42}43MIXIN_FILE_NAME = os.path.join(THIS_DIR, 'mixins.pyl')44MIXINS_PYL_TEMPLATE = """\45# GENERATED FILE - DO NOT EDIT.46# Generated by {script_name} using data from {data_source}47#48# Copyright 2021 The ANGLE Project Authors. All rights reserved.49# Use of this source code is governed by a BSD-style license that can be50# found in the LICENSE file.51#52# This is a .pyl, or "Python Literal", file. You can treat it just like a53# .json file, with the following exceptions:54# * all keys must be quoted (use single quotes, please);55# * comments are allowed, using '#' syntax; and56# * trailing commas are allowed.57#58# For more info see Chromium's mixins.pyl in testing/buildbot.5960{mixin_data}61"""626364def main():65if len(sys.argv) > 1:66gen_bb_json = os.path.join(TESTING_BBOT_DIR, 'generate_buildbot_json.py')67mixins_pyl = os.path.join(TESTING_BBOT_DIR, 'mixins.pyl')68inputs = [69'test_suite_exceptions.pyl', 'test_suites.pyl', 'variants.pyl', 'waterfalls.pyl',70gen_bb_json, mixins_pyl71]72outputs = ['angle.json', 'mixins.pyl']73if sys.argv[1] == 'inputs':74print(','.join(inputs))75elif sys.argv[1] == 'outputs':76print(','.join(outputs))77else:78print('Invalid script parameters')79return 180return 08182chromium_args = generate_buildbot_json.BBJSONGenerator.parse_args(sys.argv[1:])83chromium_generator = generate_buildbot_json.BBJSONGenerator(chromium_args)84chromium_generator.load_configuration_files()8586override_args = sys.argv[1:] + ['--pyl-files-dir', THIS_DIR]87angle_args = generate_buildbot_json.BBJSONGenerator.parse_args(override_args)88angle_generator = generate_buildbot_json.BBJSONGenerator(angle_args)89angle_generator.load_configuration_files()90angle_generator.resolve_configuration_files()9192seen_mixins = set()93for waterfall in angle_generator.waterfalls:94seen_mixins = seen_mixins.union(waterfall.get('mixins', set()))95for bot_name, tester in waterfall['machines'].iteritems():96seen_mixins = seen_mixins.union(tester.get('mixins', set()))97for suite in angle_generator.test_suites.values():98if isinstance(suite, list):99# Don't care about this, it's a composition, which shouldn't include a100# swarming mixin.101continue102for test in suite.values():103assert isinstance(test, dict)104seen_mixins = seen_mixins.union(test.get('mixins', set()))105106found_mixins = ADDITIONAL_MIXINS.copy()107for mixin in seen_mixins:108if mixin in found_mixins:109continue110assert (mixin in chromium_generator.mixins)111found_mixins[mixin] = chromium_generator.mixins[mixin]112113pp = pprint.PrettyPrinter(indent=2)114115format_data = {116'script_name': os.path.basename(__file__),117'data_source': 'waterfall.pyl and Chromium\'s mixins.pyl',118'mixin_data': pp.pformat(found_mixins),119}120generated_mixin_pyl = MIXINS_PYL_TEMPLATE.format(**format_data)121122with open(MIXIN_FILE_NAME, 'w') as f:123f.write(generated_mixin_pyl)124f.close()125126return angle_generator.main()127128129if __name__ == '__main__': # pragma: no cover130sys.exit(main())131132133