1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
content / test / gpu / PRESUBMIT.py [blame]
# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Top-level presubmit script for content/test/gpu.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools.
"""
PRESUBMIT_VERSION = '2.0.0'
EXTRA_PATHS_COMPONENTS = [
('build', ),
('build', 'fuchsia', 'test'),
('build', 'util'),
('testing', ),
('third_party', 'blink', 'tools'),
('third_party', 'catapult', 'common', 'py_utils'),
('third_party', 'catapult', 'devil'),
('third_party', 'catapult', 'telemetry'),
('third_party', 'catapult', 'third_party', 'typ'),
('tools', 'perf'),
]
def _GetChromiumSrcPath(input_api):
"""Returns the path to the Chromium src directory."""
return input_api.os_path.realpath(
input_api.os_path.join(input_api.PresubmitLocalPath(), '..', '..', '..'))
def _GetGpuEnv(input_api):
"""Gets the common environment for running GPU tests."""
gpu_env = dict(input_api.environ)
current_path = input_api.PresubmitLocalPath()
chromium_src_path = _GetChromiumSrcPath(input_api)
testing_path = input_api.os_path.join(chromium_src_path, 'testing')
gpu_env.update({
'PYTHONPATH':
input_api.os_path.pathsep.join([testing_path, current_path]),
'PYTHONDONTWRITEBYTECODE':
'1',
})
return gpu_env
def CheckGpuTestsUnittests(input_api, output_api):
"""Runs the unittests for the gpu_tests directory."""
gpu_env = _GetGpuEnv(input_api)
command = input_api.Command(
name='run_content_test_gpu_unittests',
cmd=[input_api.python3_executable, 'run_unittests.py', 'gpu_tests'],
kwargs={'env': gpu_env},
message=output_api.PresubmitError,
python3=True)
return input_api.RunTests([command])
def CheckMachineTimesUnittests(input_api, output_api):
"""Runs the unittests for the machine_times directory."""
return input_api.canned_checks.RunUnitTestsInDirectory(
input_api,
output_api,
input_api.os_path.join(input_api.PresubmitLocalPath(),
'machine_times'), [r'^.+_unittest\.py$'],
env=_GetGpuEnv(input_api),
run_on_python2=False,
run_on_python3=True,
skip_shebang_check=True)
def CheckUnexpectedPassesUnittests(input_api, output_api):
"""Runs the unittests for the unexpected_passes directory."""
return input_api.canned_checks.RunUnitTestsInDirectory(
input_api,
output_api,
input_api.os_path.join(input_api.PresubmitLocalPath(),
'unexpected_passes'), [r'^.+_unittest\.py$'],
env=_GetGpuEnv(input_api))
def CheckFlakeSuppressorUnittests(input_api, output_api):
"""Runs the unittests for the flake_suppressor directory."""
return input_api.canned_checks.RunUnitTestsInDirectory(
input_api,
output_api,
input_api.os_path.join(input_api.PresubmitLocalPath(),
'flake_suppressor'), [r'^.+_unittest\.py$'],
env=_GetGpuEnv(input_api))
def CheckValidateTagConsistency(input_api, output_api):
"""Checks that GPU expectation tags are consistent across all files."""
command = input_api.Command(name='validate_tag_consistency',
cmd=[
input_api.python3_executable,
'validate_tag_consistency.py', 'validate'
],
kwargs={},
message=output_api.PresubmitError)
return input_api.RunTests([command])
def CheckForNewSkipExpectations(input_api, output_api):
"""Checks for and dissuades the addition of new Skip expectations."""
new_skips = []
expectation_file_dir = input_api.os_path.join(input_api.PresubmitLocalPath(),
'gpu_tests',
'test_expectations')
file_filter = lambda f: f.AbsoluteLocalPath().startswith(expectation_file_dir)
for affected_file in input_api.AffectedFiles(file_filter=file_filter):
for _, line in affected_file.ChangedContents():
if input_api.re.search(r'\[\s*Skip\s*\]', line):
new_skips.append((affected_file, line))
result = []
if new_skips:
warnings = []
for affected_file, line in new_skips:
warnings.append(' Line "%s" in file %s' %
(line, affected_file.LocalPath()))
result.append(
output_api.PresubmitPromptWarning(
'Suspected new Skip expectations found:\n%s\nPlease only use such '
'expectations when they are strictly necessary, e.g. the test is '
'impacting other tests. Otherwise, opt for a '
'Failure/RetryOnFailure expectation.' % '\n'.join(warnings)))
return result
def CheckPylint(input_api, output_api):
"""Runs pylint on all directory content and subdirectories."""
chromium_src_path = _GetChromiumSrcPath(input_api)
pylint_extra_paths = [
input_api.os_path.join(chromium_src_path, *component)
for component in EXTRA_PATHS_COMPONENTS
]
pylint_checks = input_api.canned_checks.GetPylint(
input_api,
output_api,
extra_paths_list=pylint_extra_paths,
pylintrc='pylintrc',
version='2.7')
return input_api.RunTests(pylint_checks)
def CheckPytypePathsInSync(input_api, output_api):
"""Checks that run_pytype.py's paths are in sync with PRESUBMIT.py's"""
filepath = input_api.os_path.join(input_api.PresubmitLocalPath(),
'run_pytype.py')
with open(filepath, encoding='utf-8') as infile:
contents = infile.read()
# Grab the EXTRA_PATHS_COMPONENTS = [...] portion as a string.
match = input_api.re.search(r'(EXTRA_PATHS_COMPONENTS\s*=\s*[^=]*\]\n)',
contents, input_api.re.DOTALL)
if not match:
return [
output_api.PresubmitError(
'Unable to find EXTRA_PATHS_COMPONENTS in run_pytype.py. Maybe '
'the code in PRESUBMIT.py needs to be updated?')
]
expression = match.group(0)
expression = expression.split('=', 1)[1]
expression = expression.lstrip()
pytype_path_components = input_api.ast.literal_eval(expression)
if EXTRA_PATHS_COMPONENTS != pytype_path_components:
return [
output_api.PresubmitError(
'EXTRA_PATHS_COMPONENTS is not synced between PRESUBMIT.py and '
'run_pytype.py, please ensure they are identical.')
]
return []