blob: f68c001138e65c2cadbe9fe6d95e82dd3b2a128e [file] [log] [blame]
Avi Drissmandfd880852022-09-15 20:11:091# Copyright 2012 The Chromium Authors
[email protected]e615e9c2012-03-07 21:39:002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
[email protected]e615e9c2012-03-07 21:39:004"""Top-level presubmit script for testing.
5
tfarina78bb92f42015-01-31 00:20:486See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
7for more details on the presubmit API built into depot_tools.
[email protected]e615e9c2012-03-07 21:39:008"""
9
Brian Sheedyf4c13942023-01-25 00:19:4510PRESUBMIT_VERSION = '2.0.0'
[email protected]e615e9c2012-03-07 21:39:0011
Brian Sheedyfe2702e2024-12-13 21:48:2012PYLINT_PATHS_COMPONENTS = [
13 ('build', ),
14 ('build', 'android'),
15 ('build', 'util'),
16 ('content', 'test', 'gpu'),
17 ('testing', ),
18 ('testing', 'buildbot'),
19 ('testing', 'scripts'),
20 ('testing', 'variations', 'presubmit'),
21 ('third_party', ),
22 ('third_party', 'blink', 'renderer', 'bindings', 'scripts'),
23 ('third_party', 'blink', 'tools'),
24 ('third_party', 'catapult', 'telemetry'),
25 ('third_party', 'catapult', 'third_party', 'typ'),
26 ('third_party', 'catapult', 'tracing'),
27 ('third_party', 'domato', 'src'),
28 ('third_party', 'js_code_coverage'),
29 ('third_party', 'webdriver', 'pylib'),
30 ('tools', 'perf'),
31]
32
Brian Sheedyf4c13942023-01-25 00:19:4533
Brian Sheedyc68beba2024-07-24 02:29:2334def _GetChromiumSrcPath(input_api):
35 """Returns the path to the Chromium src directory."""
36 return input_api.os_path.realpath(
37 input_api.os_path.join(input_api.PresubmitLocalPath(), '..'))
38
39
Brian Sheedyf4c13942023-01-25 00:19:4540def _GetTestingEnv(input_api):
41 """Gets the common environment for running testing/ tests."""
Brian Sheedy75fc5152021-06-28 20:07:1342 testing_env = dict(input_api.environ)
Preethi Mohan8a6d7e82022-09-03 08:04:5743 testing_path = input_api.PresubmitLocalPath()
Alison Gale81f4f2c2024-04-22 19:33:3144 # TODO(crbug.com/40237086): This is temporary till gpu code in
Preethi Mohan8a6d7e82022-09-03 08:04:5745 # flake_suppressor_commonis moved to gpu dir.
46 # Only common code will reside under /testing.
Ben Pasteneb5c67262024-05-15 21:24:0147 gpu_test_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '..',
48 'content', 'test', 'gpu')
Brian Sheedyb10e844732025-03-21 17:03:3449 typ_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '..',
50 'third_party', 'catapult', 'third_party',
51 'typ')
Brian Sheedy75fc5152021-06-28 20:07:1352 testing_env.update({
Ben Pasteneb5c67262024-05-15 21:24:0153 'PYTHONPATH':
Brian Sheedyb10e844732025-03-21 17:03:3454 input_api.os_path.pathsep.join([testing_path, gpu_test_path, typ_path]),
Ben Pasteneb5c67262024-05-15 21:24:0155 'PYTHONDONTWRITEBYTECODE':
56 '1',
Brian Sheedy75fc5152021-06-28 20:07:1357 })
Brian Sheedyf4c13942023-01-25 00:19:4558 return testing_env
Brian Sheedy75fc5152021-06-28 20:07:1359
Brian Sheedyf4c13942023-01-25 00:19:4560
Brian Sheedyf4c13942023-01-25 00:19:4561def CheckFlakeSuppressorCommonUnittests(input_api, output_api):
62 """Runs unittests in the testing/flake_suppressor_common/ directory."""
63 return input_api.canned_checks.RunUnitTestsInDirectory(
Brian Sheedy75fc5152021-06-28 20:07:1364 input_api,
65 output_api,
66 input_api.os_path.join(input_api.PresubmitLocalPath(),
Ben Pasteneb5c67262024-05-15 21:24:0167 'flake_suppressor_common'), [r'^.+_unittest\.py$'],
Takuto Ikuta40def482023-06-02 02:23:4968 env=_GetTestingEnv(input_api))
Brian Sheedyf4c13942023-01-25 00:19:4569
70
71def CheckUnexpectedPassesCommonUnittests(input_api, output_api):
72 """Runs unittests in the testing/unexpected_passes_common/ directory."""
73 return input_api.canned_checks.RunUnitTestsInDirectory(
Preethi Mohan8a6d7e82022-09-03 08:04:5774 input_api,
75 output_api,
76 input_api.os_path.join(input_api.PresubmitLocalPath(),
Brian Sheedy75fc5152021-06-28 20:07:1377 'unexpected_passes_common'),
78 [r'^.+_unittest\.py$'],
Takuto Ikuta40def482023-06-02 02:23:4979 env=_GetTestingEnv(input_api))
Brian Sheedyf4c13942023-01-25 00:19:4580
81
82def CheckPylint(input_api, output_api):
83 """Runs pylint on all directory content and subdirectories."""
Bruce Dawson53f1d1c22022-05-23 18:29:0184 files_to_skip = input_api.DEFAULT_FILES_TO_SKIP
Brian Sheedyc68beba2024-07-24 02:29:2385 chromium_src_path = _GetChromiumSrcPath(input_api)
Brian Sheedyc68beba2024-07-24 02:29:2386 pylint_extra_paths = [
87 input_api.os_path.join(chromium_src_path, *component)
Brian Sheedyfe2702e2024-12-13 21:48:2088 for component in PYLINT_PATHS_COMPONENTS
Brian Sheedyc68beba2024-07-24 02:29:2389 ]
Bruce Dawson53f1d1c22022-05-23 18:29:0190 if input_api.is_windows:
91 # These scripts don't run on Windows and should not be linted on Windows -
92 # trying to do so will lead to spurious errors.
93 files_to_skip += ('xvfb.py', '.*host_info.py')
Brian Sheedyc68beba2024-07-24 02:29:2394 pylint_checks = input_api.canned_checks.GetPylint(
95 input_api,
96 output_api,
97 extra_paths_list=pylint_extra_paths,
98 files_to_skip=files_to_skip,
99 # TODO(crbug.com/355016915): Remove this directory-specific pylintrc
100 # file as the default one gets its disable list cleaned up.
101 pylintrc='pylintrc',
102 version='2.7')
Ben Pasteneb5c67262024-05-15 21:24:01103 return input_api.RunTests(pylint_checks)
104
105
106def CheckPatchFormatted(input_api, output_api):
107 return input_api.canned_checks.CheckPatchFormatted(
Joshua Hood7827f5f2022-03-01 16:31:00108 input_api,
109 output_api,
Ben Pasteneb5c67262024-05-15 21:24:01110 result_factory=output_api.PresubmitError,
111 )