blob: 314a88cb7544833d49b0173c7e88d7e7ff0bf512 [file] [log] [blame]
Avi Drissmandfd880852022-09-15 20:11:091# Copyright 2012 The Chromium Authors
[email protected]a2387a02012-09-19 22:31:362# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
[email protected]09e151b2014-03-30 16:52:174
5"""Presubmit script for changes affecting tools/perf/.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
tfarina78bb92f42015-01-31 00:20:488for more details about the presubmit API built into depot_tools.
[email protected]09e151b2014-03-30 16:52:179"""
10
[email protected]a2387a02012-09-19 22:31:3611import os
[email protected]a2387a02012-09-19 22:31:3612
Bruce Dawson13590672022-11-28 23:05:2013PRESUBMIT_VERSION = '2.0.0'
14
[email protected]7c97bc22013-08-03 01:39:3815
Ashley Enstad5c8ad4162018-02-16 16:45:2316def _CommonChecks(input_api, output_api, block_on_failure=False):
Bruce Dawson35f8e8c22022-11-29 06:00:4717 """Performs common checks that vary between commit and upload.
Ashley Enstad5c8ad4162018-02-16 16:45:2318
19 block_on_failure: For some failures, we would like to warn the
20 user but still allow them to upload the change. However, we
21 don't want them to commit code with those failures, so we
22 need to block the change on commit.
23 """
[email protected]67374a92012-10-05 05:48:1124 results = []
nednguyen087ed2c2015-11-04 20:11:2125
Ned Nguyenaba77602018-06-29 20:46:3926 results.extend(
27 _CheckPerfDataCurrentness(input_api, output_api, block_on_failure))
28 results.extend(
29 _CheckPerfJsonConfigs(input_api, output_api, block_on_failure))
Caleb Rouleau0d3593c72019-05-17 00:47:2430 results.extend(_CheckShardMaps(input_api, output_api, block_on_failure))
[email protected]67374a92012-10-05 05:48:1131 return results
[email protected]a2387a02012-09-19 22:31:3632
[email protected]7c97bc22013-08-03 01:39:3833
Bruce Dawson13590672022-11-28 23:05:2034def CheckPyLint(input_api, output_api):
35 return input_api.RunTests(
36 input_api.canned_checks.GetPylint(
37 input_api,
38 output_api,
39 extra_paths_list=_GetPathsToPrepend(input_api),
40 pylintrc='pylintrc',
41 version='2.7'))
42
43
nednguyen5919f7c2015-08-20 19:53:4844def _GetPathsToPrepend(input_api):
45 perf_dir = input_api.PresubmitLocalPath()
46 chromium_src_dir = input_api.os_path.join(perf_dir, '..', '..')
aiolos285b8fdf2016-01-27 22:14:5747 telemetry_dir = input_api.os_path.join(
48 chromium_src_dir, 'third_party', 'catapult', 'telemetry')
Rakib M. Hasan64803262019-08-08 23:56:2449 typ_dir = input_api.os_path.join(
50 chromium_src_dir, 'third_party', 'catapult', 'third_party', 'typ')
wierichs05d6ac72016-03-04 06:43:5551 experimental_dir = input_api.os_path.join(
52 chromium_src_dir, 'third_party', 'catapult', 'experimental')
rnephewaa1f9612017-03-10 00:34:1153 tracing_dir = input_api.os_path.join(
54 chromium_src_dir, 'third_party', 'catapult', 'tracing')
nednguyen3e9cc4ae2017-08-01 16:19:1055 py_utils_dir = input_api.os_path.join(
56 chromium_src_dir, 'third_party', 'catapult', 'common', 'py_utils')
bsheedye95bb962017-08-17 16:48:5457 android_pylib_dir = input_api.os_path.join(
58 chromium_src_dir, 'build', 'android')
Xiyuan Xiaf9c2d702019-10-30 15:55:2359 testing_dir = input_api.os_path.join(chromium_src_dir, 'testing')
nednguyen5919f7c2015-08-20 19:53:4860 return [
61 telemetry_dir,
Rakib M. Hasan64803262019-08-08 23:56:2462 typ_dir,
wierichs05d6ac72016-03-04 06:43:5563 experimental_dir,
rnephewaa1f9612017-03-10 00:34:1164 tracing_dir,
bsheedye95bb962017-08-17 16:48:5465 py_utils_dir,
66 android_pylib_dir,
Xiyuan Xiaf9c2d702019-10-30 15:55:2367 testing_dir,
nednguyen5919f7c2015-08-20 19:53:4868 ]
69
70
nednguyen292aea82017-02-23 19:06:0071def _RunArgs(args, input_api):
72 p = input_api.subprocess.Popen(args, stdout=input_api.subprocess.PIPE,
73 stderr=input_api.subprocess.STDOUT)
74 out, _ = p.communicate()
75 return (out, p.returncode)
76
Wenbin Zhang80cd5a542019-10-15 22:29:5477def _RunValidationScript(
78 input_api,
79 output_api,
80 script_path,
81 extra_args = None,
82 block_on_failure = None):
83 results = []
Brian Sheedy91853fc2021-11-05 23:06:1084 vpython = 'vpython3.bat' if input_api.is_windows else 'vpython3'
Wenbin Zhang80cd5a542019-10-15 22:29:5485 perf_dir = input_api.PresubmitLocalPath()
86 script_abs_path = input_api.os_path.join(perf_dir, script_path)
87 extra_args = extra_args if extra_args else []
Bruce Dawson8b5adcd2022-04-03 00:51:0488 # When running git cl presubmit --all this presubmit may be asked to check
89 # ~500 files, leading to a command line that is over 43,000 characters.
90 # This goes past the Windows 8191 character cmd.exe limit and causes cryptic
91 # failures. To avoid these we break the command up into smaller pieces. The
92 # non-Windows limit is chosen so that the code that splits up commands will
93 # get some exercise on other platforms.
94 # Depending on how long the command is on Windows the error may be:
95 # The command line is too long.
96 # Or it may be:
97 # OSError: Execution failed with error: [WinError 206] The filename or
98 # extension is too long.
99 # I suspect that the latter error comes from CreateProcess hitting its 32768
100 # character limit.
101 files_per_command = 50 if input_api.is_windows else 1000
102 # Handle the case where extra_args is empty.
103 for i in range(0, len(extra_args) if extra_args else 1, files_per_command):
104 args = [vpython, script_abs_path] + extra_args[i:i + files_per_command]
105 out, return_code = _RunArgs(args, input_api)
106 if return_code:
107 error_msg = 'Script ' + script_path + ' failed.'
108 if block_on_failure is None or block_on_failure:
109 results.append(output_api.PresubmitError(error_msg, long_text=out))
110 else:
111 results.append(
112 output_api.PresubmitPromptWarning(error_msg, long_text=out))
Wenbin Zhang80cd5a542019-10-15 22:29:54113 return results
nednguyen292aea82017-02-23 19:06:00114
Bruce Dawson13590672022-11-28 23:05:20115
116def CheckExpectations(input_api, output_api):
Wenbin Zhang80cd5a542019-10-15 22:29:54117 return _RunValidationScript(
118 input_api,
119 output_api,
120 'validate_story_expectation_data',
121 )
Ashley Enstadf6f833b2017-11-03 19:18:48122
Ned Nguyenaba77602018-06-29 20:46:39123def _CheckPerfDataCurrentness(input_api, output_api, block_on_failure):
Wenbin Zhang80cd5a542019-10-15 22:29:54124 return _RunValidationScript(
125 input_api,
126 output_api,
127 'generate_perf_data',
128 ['--validate-only'],
129 block_on_failure
130 )
Ned Nguyenaba77602018-06-29 20:46:39131
132def _CheckPerfJsonConfigs(input_api, output_api, block_on_failure):
Wenbin Zhang80cd5a542019-10-15 22:29:54133 return _RunValidationScript(
134 input_api,
135 output_api,
136 'validate_perf_json_config',
137 ['--validate-only'],
138 block_on_failure
139 )
nednguyen292aea82017-02-23 19:06:00140
Bruce Dawson13590672022-11-28 23:05:20141
142def CheckWprShaFiles(input_api, output_api):
nednguyen417ee8e2015-02-25 02:34:21143 """Check whether the wpr sha files have matching URLs."""
nednguyen3e9cc4ae2017-08-01 16:19:10144 wpr_archive_shas = []
nednguyen417ee8e2015-02-25 02:34:21145 for affected_file in input_api.AffectedFiles(include_deletes=False):
146 filename = affected_file.AbsoluteLocalPath()
nednguyen3e9cc4ae2017-08-01 16:19:10147 if not filename.endswith('.sha1'):
nednguyen417ee8e2015-02-25 02:34:21148 continue
nednguyen3e9cc4ae2017-08-01 16:19:10149 wpr_archive_shas.append(filename)
Wenbin Zhang80cd5a542019-10-15 22:29:54150 return _RunValidationScript(
151 input_api,
152 output_api,
153 'validate_wpr_archives',
154 wpr_archive_shas
155 )
nednguyen417ee8e2015-02-25 02:34:21156
Caleb Rouleau0d3593c72019-05-17 00:47:24157def _CheckShardMaps(input_api, output_api, block_on_failure):
Wenbin Zhang80cd5a542019-10-15 22:29:54158 return _RunValidationScript(
159 input_api,
160 output_api,
Caleb Rouleau97996622019-12-10 01:22:52161 'generate_perf_sharding.py',
Wenbin Zhang80cd5a542019-10-15 22:29:54162 ['validate'],
163 block_on_failure
164 )
Caleb Rouleau0d3593c72019-05-17 00:47:24165
Bruce Dawson13590672022-11-28 23:05:20166
167def CheckJson(input_api, output_api):
[email protected]09e151b2014-03-30 16:52:17168 """Checks whether JSON files in this change can be parsed."""
[email protected]faccd7e2014-04-01 23:05:19169 for affected_file in input_api.AffectedFiles(include_deletes=False):
170 filename = affected_file.AbsoluteLocalPath()
171 if os.path.splitext(filename)[1] != '.json':
172 continue
John Chen288dee02022-04-28 17:37:06173 if (os.path.basename(filename) == 'perf_results.json' and
174 os.path.basename(os.path.dirname(filename)) == 'speedometer2-future'):
175 # Intentionally invalid JSON file.
176 continue
[email protected]09e151b2014-03-30 16:52:17177 try:
Bruce Dawsonc4d1f412023-02-27 19:45:40178 input_api.json.load(open(filename, encoding='utf-8'))
[email protected]09e151b2014-03-30 16:52:17179 except ValueError:
180 return [output_api.PresubmitError('Error parsing JSON in %s!' % filename)]
181 return []
182
Bruce Dawson13590672022-11-28 23:05:20183
184def CheckVersionsInSmokeTests(input_api, output_api):
Wenbin Zhang80cd5a542019-10-15 22:29:54185 return _RunValidationScript(
186 input_api,
187 output_api,
Wenbin Zhanga903f8792019-10-11 04:45:54188 input_api.os_path.join(
Wenbin Zhang80cd5a542019-10-15 22:29:54189 'benchmarks', 'system_health_load_tests_smoke_test.py'),
190 )
[email protected]09e151b2014-03-30 16:52:17191
[email protected]67374a92012-10-05 05:48:11192def CheckChangeOnUpload(input_api, output_api):
193 report = []
194 report.extend(_CommonChecks(input_api, output_api))
195 return report
196
[email protected]7c97bc22013-08-03 01:39:38197
[email protected]67374a92012-10-05 05:48:11198def CheckChangeOnCommit(input_api, output_api):
199 report = []
Ashley Enstad5c8ad4162018-02-16 16:45:23200 report.extend(_CommonChecks(input_api, output_api, block_on_failure=True))
[email protected]a2387a02012-09-19 22:31:36201 return report