Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 1 | # Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | # repohooks/pre-upload.py currently does not run pylint. But for developers who |
| 6 | # want to check their code manually we disable several harmless pylint warnings |
| 7 | # which just distract from more serious remaining issues. |
| 8 | # |
| 9 | # The instance variable _android_cts is not defined in __init__(). |
| 10 | # pylint: disable=attribute-defined-outside-init |
| 11 | # |
| 12 | # Many short variable names don't follow the naming convention. |
| 13 | # pylint: disable=invalid-name |
| 14 | |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 15 | import logging |
| 16 | import os |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 17 | |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 18 | from autotest_lib.server import utils |
| 19 | from autotest_lib.server.cros import tradefed_test |
| 20 | |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 21 | # Maximum default time allowed for each individual CTS module. |
| 22 | _CTS_TIMEOUT_SECONDS = 3600 |
| 23 | |
| 24 | # Public download locations for android cts bundles. |
| 25 | _DL_CTS = 'https://dl.google.com/dl/android/cts/' |
| 26 | _CTS_URI = { |
Keith Haddow | 95b23fc | 2018-11-14 13:15:39 -0800 | [diff] [blame] | 27 | 'arm': _DL_CTS + 'android-cts-7.1_r23-linux_x86-arm.zip', |
| 28 | 'x86': _DL_CTS + 'android-cts-7.1_r23-linux_x86-x86.zip', |
Kazuhiro Inaba | 9a57a52 | 2017-12-11 12:42:55 +0900 | [diff] [blame] | 29 | 'media': _DL_CTS + 'android-cts-media-1.4.zip', |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 30 | } |
| 31 | |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 32 | |
Po-Hsien Wang | 0111500 | 2018-06-14 17:12:34 -0700 | [diff] [blame] | 33 | class cheets_CTS_N(tradefed_test.TradefedTest): |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 34 | """Sets up tradefed to run CTS tests.""" |
| 35 | version = 1 |
| 36 | |
Ilja H. Friedel | 29f2f9e | 2018-11-15 00:02:56 -0800 | [diff] [blame] | 37 | _BOARD_RETRY = {'betty': 0} |
| 38 | _CHANNEL_RETRY = {'dev': 9, 'beta': 9, 'stable': 9} |
Po-Hsien Wang | f72c7ad | 2018-03-23 15:55:39 -0700 | [diff] [blame] | 39 | _SHARD_CMD = '--shards' |
Po-Hsien Wang | 32eb3ee | 2018-07-09 16:54:18 -0700 | [diff] [blame] | 40 | # TODO(pwang): b/110966363, remove it once scarlet is fixed. |
Kazuhiro Inaba | f72e129 | 2018-11-20 15:37:08 +0900 | [diff] [blame^] | 41 | _NEED_DEVICE_INFO_BOARDS = ['scarlet', 'veyron_tiger'] |
Po-Hsien Wang | 715d5e9 | 2017-09-29 17:12:00 -0700 | [diff] [blame] | 42 | |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 43 | def _tradefed_retry_command(self, template, session_id): |
| 44 | """Build tradefed 'retry' command from template.""" |
| 45 | cmd = [] |
| 46 | for arg in template: |
Po-Hsien Wang | 32eb3ee | 2018-07-09 16:54:18 -0700 | [diff] [blame] | 47 | if (arg == '--skip-device-info' and |
| 48 | self._get_board_name() in self._NEED_DEVICE_INFO_BOARDS): |
| 49 | continue |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 50 | cmd.append(arg.format(session_id=session_id)) |
| 51 | return cmd |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 52 | |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 53 | def _tradefed_run_command(self, template): |
| 54 | """Build tradefed 'run' command from template.""" |
Po-Hsien Wang | 32eb3ee | 2018-07-09 16:54:18 -0700 | [diff] [blame] | 55 | cmd = [] |
| 56 | for arg in template: |
| 57 | if (arg == '--skip-device-info' and |
| 58 | self._get_board_name() in self._NEED_DEVICE_INFO_BOARDS): |
| 59 | continue |
| 60 | cmd.append(arg) |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 61 | # If we are running outside of the lab we can collect more data. |
| 62 | if not utils.is_in_container(): |
| 63 | logging.info('Running outside of lab, adding extra debug options.') |
| 64 | cmd.append('--log-level-display=DEBUG') |
| 65 | cmd.append('--screenshot-on-failure') |
| 66 | # TODO(ihf): Add log collection once b/28333587 fixed. |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 67 | # cmd.append('--collect-deqp-logs') |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 68 | return cmd |
| 69 | |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 70 | def _get_default_bundle_url(self, bundle): |
| 71 | return _CTS_URI[bundle] |
| 72 | |
| 73 | def _get_tradefed_base_dir(self): |
| 74 | return 'android-cts' |
| 75 | |
Kazuhiro Inaba | 20e3488 | 2017-11-07 15:56:37 +0900 | [diff] [blame] | 76 | def _run_tradefed(self, commands): |
| 77 | """Kick off CTS. |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 78 | |
Kazuhiro Inaba | 20e3488 | 2017-11-07 15:56:37 +0900 | [diff] [blame] | 79 | @param commands: the command(s) to pass to CTS. |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 80 | @param datetime_id: For 'continue' datetime of previous run is known. |
Kazuhiro Inaba | 20e3488 | 2017-11-07 15:56:37 +0900 | [diff] [blame] | 81 | @return: The result object from utils.run. |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 82 | """ |
Kazuhiro Inaba | 20e3488 | 2017-11-07 15:56:37 +0900 | [diff] [blame] | 83 | cts_tradefed = os.path.join(self._repository, 'tools', 'cts-tradefed') |
Po-Hsien Wang | 8fa0ea6 | 2018-02-27 15:30:22 -0800 | [diff] [blame] | 84 | with tradefed_test.adb_keepalive(self._get_adb_targets(), |
Ilja H. Friedel | 6992381 | 2018-02-02 18:22:28 -0800 | [diff] [blame] | 85 | self._install_paths): |
| 86 | for command in commands: |
| 87 | logging.info('RUN: ./cts-tradefed %s', ' '.join(command)) |
| 88 | output = self._run( |
| 89 | cts_tradefed, |
| 90 | args=tuple(command), |
Kazuhiro Inaba | e322bed | 2018-07-27 14:51:20 +0900 | [diff] [blame] | 91 | timeout=self._timeout * self._timeout_factor, |
Ilja H. Friedel | 6992381 | 2018-02-02 18:22:28 -0800 | [diff] [blame] | 92 | verbose=True, |
| 93 | ignore_status=False, |
| 94 | # Make sure to tee tradefed stdout/stderr to autotest logs |
| 95 | # continuously during the test run. |
| 96 | stdout_tee=utils.TEE_TO_LOGS, |
| 97 | stderr_tee=utils.TEE_TO_LOGS) |
Po-Hsien Wang | 8fa0ea6 | 2018-02-27 15:30:22 -0800 | [diff] [blame] | 98 | logging.info('END: ./cts-tradefed %s\n', ' '.join(command)) |
Kazuhiro Inaba | 20e3488 | 2017-11-07 15:56:37 +0900 | [diff] [blame] | 99 | return output |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 100 | |
Kazuhiro Inaba | a8c33e5 | 2018-08-06 15:46:16 +0900 | [diff] [blame] | 101 | def _should_skip_test(self, bundle): |
Nicolas Norvez | 14a3978 | 2017-07-17 16:59:14 -0700 | [diff] [blame] | 102 | """Some tests are expected to fail and are skipped.""" |
| 103 | # newbie and novato are x86 VMs without binary translation. Skip the ARM |
| 104 | # tests. |
Nicolas Norvez | 29a0960 | 2017-08-16 14:02:15 -0700 | [diff] [blame] | 105 | no_ARM_ABI_test_boards = ('newbie', 'novato', 'novato-arc64') |
Kazuhiro Inaba | a8c33e5 | 2018-08-06 15:46:16 +0900 | [diff] [blame] | 106 | if self._get_board_name() in no_ARM_ABI_test_boards and bundle == 'arm': |
| 107 | return True |
Nicolas Norvez | 14a3978 | 2017-07-17 16:59:14 -0700 | [diff] [blame] | 108 | return False |
Keith Haddow | 3c6bb06 | 2017-07-01 13:58:50 -0700 | [diff] [blame] | 109 | |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 110 | def run_once(self, |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 111 | test_name, |
| 112 | run_template, |
| 113 | retry_template=None, |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 114 | target_module=None, |
| 115 | target_plan=None, |
| 116 | target_class=None, |
| 117 | target_method=None, |
| 118 | needs_push_media=False, |
Kazuhiro Inaba | e322bed | 2018-07-27 14:51:20 +0900 | [diff] [blame] | 119 | bundle=None, |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 120 | precondition_commands=[], |
| 121 | login_precondition_commands=[], |
| 122 | timeout=_CTS_TIMEOUT_SECONDS): |
| 123 | """Runs the specified CTS once, but with several retries. |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 124 | |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 125 | Run an arbitrary tradefed command. |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 126 | |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 127 | @param test_name: the name of test. Used for logging. |
| 128 | @param run_template: the template to construct the run command. |
| 129 | Example: ['run', 'commandAndExit', 'cts', |
| 130 | '--skip-media-download'] |
| 131 | @param retry_template: the template to construct the retry command. |
| 132 | Example: ['run', 'commandAndExit', 'retry', |
| 133 | '--skip-media-download', '--retry', |
| 134 | '{session_id}'] |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 135 | @param target_module: the name of test module to run. |
| 136 | @param target_plan: the name of the test plan to run. |
| 137 | @param target_class: the name of the class to be tested. |
| 138 | @param target_method: the name of the method to be tested. |
| 139 | @param needs_push_media: need to push test media streams. |
Kazuhiro Inaba | e322bed | 2018-07-27 14:51:20 +0900 | [diff] [blame] | 140 | @param bundle: the type of the CTS bundle: 'arm' or 'x86' |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 141 | @param precondition_commands: a list of scripts to be run on the |
| 142 | dut before the test is run, the scripts must already be installed. |
| 143 | @param login_precondition_commands: a list of scripts to be run on the |
| 144 | dut before the log-in for the test is performed. |
Kazuhiro Inaba | e322bed | 2018-07-27 14:51:20 +0900 | [diff] [blame] | 145 | @param timeout: time after which tradefed can be interrupted. |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 146 | """ |
Ilja H. Friedel | de0c465 | 2017-02-22 01:18:39 -0800 | [diff] [blame] | 147 | |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 148 | # On dev and beta channels timeouts are sharp, lenient on stable. |
| 149 | self._timeout = timeout |
Po-Hsien Wang | 8fa0ea6 | 2018-02-27 15:30:22 -0800 | [diff] [blame] | 150 | if self._get_release_channel() == 'stable': |
David Haddock | f8b4577 | 2017-11-02 13:57:56 -0700 | [diff] [blame] | 151 | self._timeout += 3600 |
Kazuhiro Inaba | e322bed | 2018-07-27 14:51:20 +0900 | [diff] [blame] | 152 | |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 153 | self._run_tradefed_with_retries( |
| 154 | test_name=test_name, |
| 155 | run_template=run_template, |
| 156 | retry_template=retry_template, |
| 157 | target_module=target_module, |
| 158 | target_plan=target_plan, |
| 159 | needs_push_media=needs_push_media, |
Kazuhiro Inaba | e322bed | 2018-07-27 14:51:20 +0900 | [diff] [blame] | 160 | bundle=bundle, |
Po-Hsien Wang | 4f9a914 | 2018-06-14 17:09:38 -0700 | [diff] [blame] | 161 | cts_uri=_CTS_URI, |
| 162 | login_precondition_commands=login_precondition_commands, |
| 163 | precondition_commands=precondition_commands) |