Avi Drissman | dfd88085 | 2022-09-15 20:11:09 | [diff] [blame] | 1 | # Copyright 2012 The Chromium Authors |
[email protected] | e615e9c | 2012-03-07 21:39:00 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
[email protected] | e615e9c | 2012-03-07 21:39:00 | [diff] [blame] | 4 | """Top-level presubmit script for testing. |
| 5 | |
tfarina | 78bb92f4 | 2015-01-31 00:20:48 | [diff] [blame] | 6 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 7 | for more details on the presubmit API built into depot_tools. |
[email protected] | e615e9c | 2012-03-07 21:39:00 | [diff] [blame] | 8 | """ |
| 9 | |
Brian Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 10 | PRESUBMIT_VERSION = '2.0.0' |
[email protected] | e615e9c | 2012-03-07 21:39:00 | [diff] [blame] | 11 | |
Brian Sheedy | fe2702e | 2024-12-13 21:48:20 | [diff] [blame] | 12 | PYLINT_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 Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 33 | |
Brian Sheedy | c68beba | 2024-07-24 02:29:23 | [diff] [blame] | 34 | def _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 Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 40 | def _GetTestingEnv(input_api): |
| 41 | """Gets the common environment for running testing/ tests.""" |
Brian Sheedy | 75fc515 | 2021-06-28 20:07:13 | [diff] [blame] | 42 | testing_env = dict(input_api.environ) |
Preethi Mohan | 8a6d7e8 | 2022-09-03 08:04:57 | [diff] [blame] | 43 | testing_path = input_api.PresubmitLocalPath() |
Alison Gale | 81f4f2c | 2024-04-22 19:33:31 | [diff] [blame] | 44 | # TODO(crbug.com/40237086): This is temporary till gpu code in |
Preethi Mohan | 8a6d7e8 | 2022-09-03 08:04:57 | [diff] [blame] | 45 | # flake_suppressor_commonis moved to gpu dir. |
| 46 | # Only common code will reside under /testing. |
Ben Pastene | b5c6726 | 2024-05-15 21:24:01 | [diff] [blame] | 47 | gpu_test_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '..', |
| 48 | 'content', 'test', 'gpu') |
Brian Sheedy | b10e84473 | 2025-03-21 17:03:34 | [diff] [blame] | 49 | typ_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '..', |
| 50 | 'third_party', 'catapult', 'third_party', |
| 51 | 'typ') |
Brian Sheedy | 75fc515 | 2021-06-28 20:07:13 | [diff] [blame] | 52 | testing_env.update({ |
Ben Pastene | b5c6726 | 2024-05-15 21:24:01 | [diff] [blame] | 53 | 'PYTHONPATH': |
Brian Sheedy | b10e84473 | 2025-03-21 17:03:34 | [diff] [blame] | 54 | input_api.os_path.pathsep.join([testing_path, gpu_test_path, typ_path]), |
Ben Pastene | b5c6726 | 2024-05-15 21:24:01 | [diff] [blame] | 55 | 'PYTHONDONTWRITEBYTECODE': |
| 56 | '1', |
Brian Sheedy | 75fc515 | 2021-06-28 20:07:13 | [diff] [blame] | 57 | }) |
Brian Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 58 | return testing_env |
Brian Sheedy | 75fc515 | 2021-06-28 20:07:13 | [diff] [blame] | 59 | |
Brian Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 60 | |
Brian Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 61 | def CheckFlakeSuppressorCommonUnittests(input_api, output_api): |
| 62 | """Runs unittests in the testing/flake_suppressor_common/ directory.""" |
| 63 | return input_api.canned_checks.RunUnitTestsInDirectory( |
Brian Sheedy | 75fc515 | 2021-06-28 20:07:13 | [diff] [blame] | 64 | input_api, |
| 65 | output_api, |
| 66 | input_api.os_path.join(input_api.PresubmitLocalPath(), |
Ben Pastene | b5c6726 | 2024-05-15 21:24:01 | [diff] [blame] | 67 | 'flake_suppressor_common'), [r'^.+_unittest\.py$'], |
Takuto Ikuta | 40def48 | 2023-06-02 02:23:49 | [diff] [blame] | 68 | env=_GetTestingEnv(input_api)) |
Brian Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 69 | |
| 70 | |
| 71 | def CheckUnexpectedPassesCommonUnittests(input_api, output_api): |
| 72 | """Runs unittests in the testing/unexpected_passes_common/ directory.""" |
| 73 | return input_api.canned_checks.RunUnitTestsInDirectory( |
Preethi Mohan | 8a6d7e8 | 2022-09-03 08:04:57 | [diff] [blame] | 74 | input_api, |
| 75 | output_api, |
| 76 | input_api.os_path.join(input_api.PresubmitLocalPath(), |
Brian Sheedy | 75fc515 | 2021-06-28 20:07:13 | [diff] [blame] | 77 | 'unexpected_passes_common'), |
| 78 | [r'^.+_unittest\.py$'], |
Takuto Ikuta | 40def48 | 2023-06-02 02:23:49 | [diff] [blame] | 79 | env=_GetTestingEnv(input_api)) |
Brian Sheedy | f4c1394 | 2023-01-25 00:19:45 | [diff] [blame] | 80 | |
| 81 | |
| 82 | def CheckPylint(input_api, output_api): |
| 83 | """Runs pylint on all directory content and subdirectories.""" |
Bruce Dawson | 53f1d1c2 | 2022-05-23 18:29:01 | [diff] [blame] | 84 | files_to_skip = input_api.DEFAULT_FILES_TO_SKIP |
Brian Sheedy | c68beba | 2024-07-24 02:29:23 | [diff] [blame] | 85 | chromium_src_path = _GetChromiumSrcPath(input_api) |
Brian Sheedy | c68beba | 2024-07-24 02:29:23 | [diff] [blame] | 86 | pylint_extra_paths = [ |
| 87 | input_api.os_path.join(chromium_src_path, *component) |
Brian Sheedy | fe2702e | 2024-12-13 21:48:20 | [diff] [blame] | 88 | for component in PYLINT_PATHS_COMPONENTS |
Brian Sheedy | c68beba | 2024-07-24 02:29:23 | [diff] [blame] | 89 | ] |
Bruce Dawson | 53f1d1c2 | 2022-05-23 18:29:01 | [diff] [blame] | 90 | 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 Sheedy | c68beba | 2024-07-24 02:29:23 | [diff] [blame] | 94 | 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 Pastene | b5c6726 | 2024-05-15 21:24:01 | [diff] [blame] | 103 | return input_api.RunTests(pylint_checks) |
| 104 | |
| 105 | |
| 106 | def CheckPatchFormatted(input_api, output_api): |
| 107 | return input_api.canned_checks.CheckPatchFormatted( |
Joshua Hood | 7827f5f | 2022-03-01 16:31:00 | [diff] [blame] | 108 | input_api, |
| 109 | output_api, |
Ben Pastene | b5c6726 | 2024-05-15 21:24:01 | [diff] [blame] | 110 | result_factory=output_api.PresubmitError, |
| 111 | ) |