Kuang-che Wu | 875c89a | 2020-01-08 14:30:55 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
| 3 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """Evaluate ChromeOS autotest. |
| 7 | |
| 8 | Note that by default 'test_that' will install dependency packages of autotest |
Kuang-che Wu | fd2ea5e | 2019-06-10 20:40:17 +0800 | [diff] [blame] | 9 | if the package checksum mismatch. If you want to override content of autotest |
| 10 | package, e.g. chrome's test binary, please make sure the autotest version |
| 11 | matches. Otherwise your test binary will be overwritten. |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 12 | """ |
| 13 | from __future__ import print_function |
| 14 | import argparse |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 15 | import logging |
| 16 | import os |
| 17 | import re |
| 18 | import subprocess |
| 19 | import sys |
| 20 | |
Kuang-che Wu | 4f0dc23 | 2019-05-10 18:28:06 +0800 | [diff] [blame] | 21 | from bisect_kit import catapult_util |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 22 | from bisect_kit import cli |
| 23 | from bisect_kit import common |
| 24 | from bisect_kit import configure |
Kuang-che Wu | 2ac9a92 | 2020-09-03 16:50:12 +0800 | [diff] [blame] | 25 | from bisect_kit import cros_lab_util |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 26 | from bisect_kit import cros_util |
| 27 | from bisect_kit import util |
| 28 | |
| 29 | logger = logging.getLogger(__name__) |
| 30 | |
| 31 | OLD = 'old' |
| 32 | NEW = 'new' |
| 33 | SKIP = 'skip' |
| 34 | FATAL = 'fatal' |
| 35 | |
| 36 | EXIT_CODE_MAP = { |
Kuang-che Wu | 0476d1f | 2019-03-04 19:27:01 +0800 | [diff] [blame] | 37 | OLD: cli.EXIT_CODE_OLD, |
| 38 | NEW: cli.EXIT_CODE_NEW, |
| 39 | SKIP: cli.EXIT_CODE_SKIP, |
| 40 | FATAL: cli.EXIT_CODE_FATAL, |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | |
| 44 | def create_argument_parser(): |
Kuang-che Wu | d2d6e41 | 2021-01-28 16:26:41 +0800 | [diff] [blame] | 45 | parents = [common.common_argument_parser, common.session_optional_parser] |
| 46 | parser = argparse.ArgumentParser(description=__doc__, parents=parents) |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 47 | cli.patching_argparser_exit(parser) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 48 | parser.add_argument( |
| 49 | 'dut', |
| 50 | nargs='?', |
| 51 | type=cli.argtype_notempty, |
| 52 | metavar='DUT', |
| 53 | default=configure.get('DUT', '')) |
| 54 | parser.add_argument( |
| 55 | '--chromeos_root', |
| 56 | type=cli.argtype_dir_path, |
| 57 | metavar='CHROMEOS_ROOT', |
| 58 | default=configure.get('CHROMEOS_ROOT', ''), |
| 59 | help='ChromeOS tree root') |
| 60 | parser.add_argument( |
Kuang-che Wu | d4603d7 | 2018-11-29 17:51:21 +0800 | [diff] [blame] | 61 | '--chrome_root', |
| 62 | metavar='CHROME_ROOT', |
| 63 | type=cli.argtype_dir_path, |
| 64 | default=configure.get('CHROME_ROOT'), |
| 65 | help='Chrome tree root; necessary for telemetry tests') |
| 66 | parser.add_argument( |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 67 | '--prebuilt', |
| 68 | action='store_true', |
| 69 | help='Run autotest using existing prebuilt package if specified; ' |
| 70 | 'otherwise use the default one') |
| 71 | parser.add_argument( |
| 72 | '--reinstall', |
| 73 | action='store_true', |
| 74 | help='Remove existing autotest folder on the DUT first') |
Kuang-che Wu | da3abfe | 2019-03-21 14:48:12 +0800 | [diff] [blame] | 75 | parser.add_argument( |
| 76 | '--reboot_before_test', |
| 77 | action='store_true', |
| 78 | help='Reboot before test run') |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 79 | |
| 80 | group = parser.add_argument_group(title='Options for normal autotest tests') |
| 81 | group.add_argument( |
| 82 | '--test_name', help='Test name, like "video_VideoDecodeAccelerator.h264"') |
| 83 | group.add_argument( |
Kuang-che Wu | 0a4304a | 2019-01-19 01:32:11 +0800 | [diff] [blame] | 84 | '--fail_to_pass', |
| 85 | action='store_true', |
| 86 | help='For functional tests: old behavior is FAIL and new behavior is ' |
| 87 | 'PASS; If not specified, default = old behavior is PASS and new ' |
| 88 | 'behavior is FAIL') |
| 89 | group.add_argument( |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 90 | '--metric', |
Kuang-che Wu | d1b7415 | 2020-05-20 08:46:46 +0800 | [diff] [blame] | 91 | help='Metric name of performance test; example: ' |
| 92 | '"cheets_SystemRawImageSize"') |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 93 | group.add_argument( |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 94 | '--args', |
| 95 | help='Extra args passed to "test_that --args"; Overrides the default') |
| 96 | |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 97 | group = parser.add_argument_group(title='Options for CTS/GTS tests') |
| 98 | group.add_argument('--cts_revision', help='CTS revision, like "9.0_r3"') |
Kuang-che Wu | 63f836a | 2019-02-21 16:33:32 +0000 | [diff] [blame] | 99 | group.add_argument('--cts_abi', choices=['arm', 'x86']) |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 100 | group.add_argument( |
| 101 | '--cts_prefix', |
| 102 | help='Prefix of autotest test name, ' |
| 103 | 'like cheets_CTS_N, cheets_CTS_P, cheets_GTS') |
| 104 | group.add_argument( |
| 105 | '--cts_module', help='CTS/GTS module name, like "CtsCameraTestCases"') |
| 106 | group.add_argument( |
| 107 | '--cts_test', |
| 108 | help='CTS/GTS test name, like ' |
| 109 | '"android.hardware.cts.CameraTest#testDisplayOrientation"') |
| 110 | group.add_argument('--cts_timeout', type=float, help='timeout, in seconds') |
| 111 | |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 112 | return parser |
| 113 | |
| 114 | |
| 115 | def parse_test_report_log(result_log, metric): |
| 116 | """Parses autotest result log. |
| 117 | |
| 118 | Args: |
| 119 | result_log: content of test_report.log |
| 120 | metric: what metric to capture if not None |
| 121 | |
| 122 | Returns: |
| 123 | passed, values: |
| 124 | passed: True if test run successfully |
| 125 | values: captured metric values; None if test failed or metric is None |
| 126 | """ |
| 127 | m = re.search(r'Total PASS: (\d+)/(\d+)', result_log) |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 128 | passed = (m and m.group(1) == m.group(2)) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 129 | |
| 130 | if not metric: |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 131 | return passed, None |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 132 | |
| 133 | values = [] |
| 134 | for line in result_log.splitlines(): |
| 135 | m = re.match(r'^(\S+)\s+(\w+)(?:\{\d+\})?\s+(\d+\.\d+)$', line) |
| 136 | if not m: |
| 137 | continue |
| 138 | if m.group(2) == metric: |
| 139 | values.append(float(m.group(3))) |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 140 | return passed, values |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 141 | |
| 142 | |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 143 | def get_additional_test_args(test_name): |
| 144 | """Gets extra arguments to specific test. |
| 145 | |
| 146 | Some tests may require special arguments to run. |
| 147 | |
| 148 | Args: |
| 149 | test_name: test name |
| 150 | |
| 151 | Returns: |
| 152 | arguments (str) |
| 153 | """ |
| 154 | if test_name.startswith('telemetry_'): |
| 155 | return 'local=True' |
| 156 | return '' |
| 157 | |
| 158 | |
Kuang-che Wu | 6c5a5b2 | 2019-01-17 18:09:50 +0800 | [diff] [blame] | 159 | def prepare_to_run_test(opts): |
| 160 | # Some versions of ChromeOS SDK is broken and ship bad 'ssh' executable. This |
Kuang-che Wu | 9fcf108 | 2019-03-04 11:24:04 +0800 | [diff] [blame] | 161 | # works around the issue. See crbug/906289 for detail. |
| 162 | # TODO(kcwu): remove this workaround once we no longer support bisecting |
| 163 | # versions earlier than R73-11445.0.0. |
| 164 | ssh_path = os.path.join(opts.chromeos_root, 'chroot/usr/bin/ssh') |
Kuang-che Wu | 4fbd2d3 | 2019-03-07 01:07:57 +0800 | [diff] [blame] | 165 | if os.path.exists(ssh_path): |
Kuang-che Wu | d3a4e84 | 2019-12-11 12:15:23 +0800 | [diff] [blame] | 166 | with open(ssh_path, 'rb') as f: |
Kuang-che Wu | a572349 | 2019-11-25 20:59:34 +0800 | [diff] [blame] | 167 | if b'file descriptor passing not supported' in f.read(): |
| 168 | cros_util.cros_sdk(opts.chromeos_root, 'sudo', 'emerge', |
| 169 | 'net-misc/openssh') |
Kuang-che Wu | 6c5a5b2 | 2019-01-17 18:09:50 +0800 | [diff] [blame] | 170 | |
Kuang-che Wu | e9fc9e9 | 2020-09-11 20:28:13 +0800 | [diff] [blame] | 171 | # Special handling for audio tests (b/136136270). |
| 172 | if opts.prebuilt: |
| 173 | autotest_dir = os.path.join(opts.chromeos_root, |
| 174 | cros_util.prebuilt_autotest_dir) |
| 175 | else: |
| 176 | autotest_dir = os.path.join(opts.chromeos_root, |
Kuang-che Wu | 721e890 | 2021-03-19 12:18:53 +0800 | [diff] [blame^] | 177 | cros_util.in_tree_autotest_dir) |
| 178 | cros_util.override_autotest_config(autotest_dir) |
Kuang-che Wu | e9fc9e9 | 2020-09-11 20:28:13 +0800 | [diff] [blame] | 179 | sox_path = os.path.join(opts.chromeos_root, 'chroot/usr/bin/sox') |
| 180 | if not os.path.exists(sox_path): |
Kuang-che Wu | cc65e4e | 2020-09-22 19:55:36 +0800 | [diff] [blame] | 181 | try: |
| 182 | cros_util.cros_sdk(opts.chromeos_root, 'sudo', 'emerge', 'sox') |
| 183 | except subprocess.CalledProcessError: |
| 184 | # It's known that installing sox would fail for earlier version of |
| 185 | # chromeos (b/136136270), so ignore the failure. |
| 186 | logger.debug('Sox is only required by some audio tests. ' |
| 187 | 'Assume the failure of installing sox is harmless') |
Kuang-che Wu | e9fc9e9 | 2020-09-11 20:28:13 +0800 | [diff] [blame] | 188 | |
Kuang-che Wu | f0ad9ac | 2019-09-06 13:05:04 +0800 | [diff] [blame] | 189 | # test_that may use this ssh key and ssh complains its permission is too open. |
Kuang-che Wu | 4a81ea7 | 2019-10-05 15:35:17 +0800 | [diff] [blame] | 190 | # chmod every time just before run test_that because the permission may change |
Kuang-che Wu | f0ad9ac | 2019-09-06 13:05:04 +0800 | [diff] [blame] | 191 | # after some git operations. |
| 192 | util.check_call( |
| 193 | 'chmod', |
| 194 | 'o-r,g-r', |
| 195 | 'src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa', |
| 196 | cwd=opts.chromeos_root) |
| 197 | |
Kuang-che Wu | 6c5a5b2 | 2019-01-17 18:09:50 +0800 | [diff] [blame] | 198 | if opts.reinstall: |
Kuang-che Wu | 4427814 | 2019-03-04 11:33:57 +0800 | [diff] [blame] | 199 | util.ssh_cmd(opts.dut, 'rm', '-rf', '/usr/local/autotest') |
Kuang-che Wu | 6c5a5b2 | 2019-01-17 18:09:50 +0800 | [diff] [blame] | 200 | |
Kuang-che Wu | da3abfe | 2019-03-21 14:48:12 +0800 | [diff] [blame] | 201 | if opts.reboot_before_test: |
Kuang-che Wu | 2ac9a92 | 2020-09-03 16:50:12 +0800 | [diff] [blame] | 202 | cros_util.reboot( |
| 203 | opts.dut, force_reboot_callback=cros_lab_util.reboot_via_servo) |
Kuang-che Wu | da3abfe | 2019-03-21 14:48:12 +0800 | [diff] [blame] | 204 | |
Kuang-che Wu | 6c5a5b2 | 2019-01-17 18:09:50 +0800 | [diff] [blame] | 205 | |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 206 | def run_test(opts): |
| 207 | """Runs an autotest test. |
| 208 | |
| 209 | Args: |
| 210 | opts: An argparse.Namespace to hold command line arguments. |
| 211 | |
| 212 | Returns: |
| 213 | path of test result (outside chroot) |
| 214 | """ |
Kuang-che Wu | 7f82c6f | 2019-08-12 14:29:28 +0800 | [diff] [blame] | 215 | prebuilt_autotest_dir = os.path.join(cros_util.chromeos_root_inside_chroot, |
| 216 | cros_util.prebuilt_autotest_dir) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 217 | # Set results dir inside source tree, so it's easier to access them outside |
| 218 | # chroot. |
| 219 | results_dir = os.path.join(cros_util.chromeos_root_inside_chroot, |
| 220 | 'tmp/autotest_results_tmp') |
Kuang-che Wu | 7f82c6f | 2019-08-12 14:29:28 +0800 | [diff] [blame] | 221 | if opts.prebuilt: |
| 222 | test_that_bin = os.path.join(prebuilt_autotest_dir, |
| 223 | 'site_utils/test_that.py') |
| 224 | else: |
| 225 | test_that_bin = '/usr/bin/test_that' |
Kuang-che Wu | f3d03ca | 2019-03-11 17:31:40 +0800 | [diff] [blame] | 226 | cmd = [ |
| 227 | test_that_bin, opts.dut, opts.test_name, '--debug', '--results_dir', |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 228 | results_dir |
Kuang-che Wu | f3d03ca | 2019-03-11 17:31:40 +0800 | [diff] [blame] | 229 | ] |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 230 | if opts.prebuilt: |
Kuang-che Wu | 7f82c6f | 2019-08-12 14:29:28 +0800 | [diff] [blame] | 231 | cmd += ['--autotest_dir', prebuilt_autotest_dir] |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 232 | |
| 233 | args = get_additional_test_args(opts.test_name) |
| 234 | if opts.args: |
| 235 | if args: |
Kuang-che Wu | 74768d3 | 2018-09-07 12:03:24 +0800 | [diff] [blame] | 236 | logger.info( |
| 237 | 'default test_that args `%s` is overridden by ' |
| 238 | 'command line option `%s`', args, opts.args) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 239 | cmd += ['--args', opts.args] |
| 240 | elif args: |
| 241 | cmd += ['--args', args] |
| 242 | |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 243 | try: |
Kuang-che Wu | d4603d7 | 2018-11-29 17:51:21 +0800 | [diff] [blame] | 244 | output = cros_util.cros_sdk( |
| 245 | opts.chromeos_root, *cmd, chrome_root=opts.chrome_root) |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 246 | except subprocess.CalledProcessError as e: |
Kuang-che Wu | 6267701 | 2020-07-13 14:25:18 +0800 | [diff] [blame] | 247 | if e.output is None: |
| 248 | logger.error('cros_sdk failed before test started') |
| 249 | return None |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 250 | output = e.output |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 251 | |
| 252 | m = re.search(r'Finished running tests. Results can be found in (\S+)', |
| 253 | output) |
| 254 | if not m: |
| 255 | logger.error('result dir is unknown') |
| 256 | return None |
| 257 | assert m.group(1) == results_dir |
| 258 | return results_dir.replace(cros_util.chromeos_root_inside_chroot, |
| 259 | opts.chromeos_root) |
| 260 | |
| 261 | |
| 262 | def gather_test_result(opts, result_dir): |
| 263 | result_log_path = os.path.join(result_dir, 'test_report.log') |
Kuang-che Wu | a572349 | 2019-11-25 20:59:34 +0800 | [diff] [blame] | 264 | with open(result_log_path) as f: |
| 265 | result_log = f.read() |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 266 | |
| 267 | passed, values = parse_test_report_log(result_log, opts.metric) |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 268 | if opts.metric and not values: |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 269 | values = [] |
| 270 | for root, _, files in os.walk(result_dir): |
| 271 | for filename in files: |
| 272 | if filename != 'results-chart.json': |
| 273 | continue |
| 274 | full_path = os.path.join(root, filename) |
Kuang-che Wu | 4f0dc23 | 2019-05-10 18:28:06 +0800 | [diff] [blame] | 275 | values = catapult_util.get_benchmark_values(full_path, opts.metric) |
| 276 | return passed, values |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 277 | |
| 278 | return passed, values |
| 279 | |
| 280 | |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 281 | @cli.fatal_error_handler |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 282 | def main(args=None): |
| 283 | common.init() |
| 284 | parser = create_argument_parser() |
| 285 | opts = parser.parse_args(args) |
| 286 | common.config_logging(opts) |
| 287 | |
| 288 | if not cros_util.is_dut(opts.dut): |
Kuang-che Wu | 4a75f95 | 2019-03-26 17:22:42 +0800 | [diff] [blame] | 289 | logger.error('%r is not a valid DUT address', opts.dut) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 290 | return FATAL |
Kuang-che Wu | c8c495d | 2019-08-19 17:48:58 +0800 | [diff] [blame] | 291 | dut_os_version = cros_util.query_dut_short_version(opts.dut) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 292 | |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 293 | is_cts = ( |
| 294 | opts.cts_revision or opts.cts_abi or opts.cts_prefix or opts.cts_module or |
Kuang-che Wu | e07bff5 | 2019-10-29 20:50:45 +0800 | [diff] [blame] | 295 | opts.cts_test or opts.cts_timeout) |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 296 | if is_cts: |
| 297 | if opts.test_name or opts.metric or opts.args: |
| 298 | parser.error( |
| 299 | 'do not specify --test_name, --metric, --args for CTS/GTS tests') |
Kuang-che Wu | b91b151 | 2019-05-29 15:16:29 +0800 | [diff] [blame] | 300 | if not opts.cts_prefix: |
| 301 | parser.error('--cts_prefix should be specified for CTS/GTS tests') |
| 302 | if not opts.cts_module: |
| 303 | parser.error('--cts_module should be specified for CTS/GTS tests') |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 304 | opts.test_name = '%s.tradefed-run-test' % opts.cts_prefix |
Kuang-che Wu | e07bff5 | 2019-10-29 20:50:45 +0800 | [diff] [blame] | 305 | opts.args = 'module=%s test=%s max_retry=0' % (opts.cts_module, |
| 306 | opts.cts_test) |
Kuang-che Wu | 85c613c | 2019-01-09 15:46:11 +0800 | [diff] [blame] | 307 | if opts.cts_revision: |
| 308 | opts.args += ' revision=%s' % opts.cts_revision |
| 309 | if opts.cts_abi: |
| 310 | opts.args += ' abi=%s' % opts.cts_abi |
| 311 | if opts.cts_timeout: |
| 312 | opts.args += ' timeout=%s' % opts.cts_timeout |
| 313 | else: |
| 314 | if not opts.test_name: |
| 315 | parser.error('argument --test_name is required') |
| 316 | |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 317 | # Verify command line options. |
| 318 | if opts.metric: |
Kuang-che Wu | 0a4304a | 2019-01-19 01:32:11 +0800 | [diff] [blame] | 319 | if opts.fail_to_pass: |
| 320 | logger.error('--fail_to_pass is not for benchmark test (--metric)') |
| 321 | return FATAL |
Kuang-che Wu | d4603d7 | 2018-11-29 17:51:21 +0800 | [diff] [blame] | 322 | if opts.test_name.startswith('telemetry_'): |
| 323 | if not opts.chrome_root: |
| 324 | logger.error('--chrome_root is mandatory for telemetry tests') |
| 325 | return FATAL |
Kuang-che Wu | a641cb1 | 2021-01-27 19:27:25 +0800 | [diff] [blame] | 326 | if opts.prebuilt: |
| 327 | autotest_dir = os.path.join(opts.chromeos_root, |
| 328 | cros_util.prebuilt_autotest_dir) |
| 329 | if not os.path.exists(autotest_dir): |
| 330 | parser.error('--prebuilt: no autotest prebuilt installed (%s); ' |
| 331 | 'please run switch_autotest_prebuilt.py first' % |
| 332 | autotest_dir) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 333 | |
Kuang-che Wu | 6c5a5b2 | 2019-01-17 18:09:50 +0800 | [diff] [blame] | 334 | try: |
| 335 | prepare_to_run_test(opts) |
| 336 | except Exception: |
| 337 | logger.exception('failed when prepare, assume it is temporary; SKIP') |
| 338 | return SKIP |
Kuang-che Wu | e47162d | 2018-10-29 17:24:04 +0800 | [diff] [blame] | 339 | |
Kuang-che Wu | 171dcb6 | 2018-10-25 12:37:05 +0800 | [diff] [blame] | 340 | result_dir = run_test(opts) |
| 341 | if not result_dir: |
Kuang-che Wu | dd80267 | 2018-08-10 19:40:14 +0800 | [diff] [blame] | 342 | return FATAL |
| 343 | |
Kuang-che Wu | c986b1d | 2019-04-15 16:45:20 +0800 | [diff] [blame] | 344 | try: |
| 345 | passed, values = gather_test_result(opts, result_dir) |
| 346 | except Exception: |
| 347 | logger.exception('failed to parse test result') |
| 348 | return FATAL |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 349 | |
Kuang-che Wu | c8c495d | 2019-08-19 17:48:58 +0800 | [diff] [blame] | 350 | # Sanity check. The OS version should not change. |
Kuang-che Wu | 523bdf2 | 2019-08-20 12:11:09 +0800 | [diff] [blame] | 351 | assert dut_os_version == cros_util.query_dut_short_version(opts.dut), \ |
Kuang-che Wu | 5940031 | 2020-11-10 14:53:54 +0800 | [diff] [blame] | 352 | 'Someone else reflashed the DUT. DUT locking is not respected?' |
Kuang-che Wu | c8c495d | 2019-08-19 17:48:58 +0800 | [diff] [blame] | 353 | |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 354 | if opts.metric: |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 355 | if not values: |
| 356 | logger.warning('no values found; SKIP') |
| 357 | return SKIP |
| 358 | |
Kuang-che Wu | c89f2a2 | 2019-11-26 15:30:50 +0800 | [diff] [blame] | 359 | print('BISECT_RESULT_VALUES=', ' '.join(str(v) for v in values)) |
Kuang-che Wu | 81cde45 | 2019-04-08 16:56:51 +0800 | [diff] [blame] | 360 | logger.info('values=%s', values) |
| 361 | # The exit code doesn't matter. |
| 362 | return OLD |
Kuang-che Wu | 084eef2 | 2020-03-11 18:29:48 +0800 | [diff] [blame] | 363 | |
| 364 | if opts.fail_to_pass: |
| 365 | if passed: |
| 366 | logger.info('passed') |
Kuang-che Wu | 0a4304a | 2019-01-19 01:32:11 +0800 | [diff] [blame] | 367 | return NEW |
Kuang-che Wu | 084eef2 | 2020-03-11 18:29:48 +0800 | [diff] [blame] | 368 | logger.info('failed') |
| 369 | return OLD |
| 370 | if passed: |
| 371 | logger.info('passed') |
| 372 | return OLD |
| 373 | logger.info('failed') |
| 374 | return NEW |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 375 | |
| 376 | |
| 377 | if __name__ == '__main__': |
| 378 | sys.exit(EXIT_CODE_MAP[main()]) |