1# Lint as: python2, python3 2# Copyright 2016 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6# repohooks/pre-upload.py currently does not run pylint. But for developers who 7# want to check their code manually we disable several harmless pylint warnings 8# which just distract from more serious remaining issues. 9# 10# The instance variable _android_cts is not defined in __init__(). 11# pylint: disable=attribute-defined-outside-init 12# 13# Many short variable names don't follow the naming convention. 14# pylint: disable=invalid-name 15 16import logging 17import os 18import subprocess 19 20from autotest_lib.client.bin import utils as client_utils 21from autotest_lib.client.common_lib import error 22from autotest_lib.server import hosts 23from autotest_lib.server import utils 24from autotest_lib.server.cros import camerabox_utils 25from autotest_lib.server.cros.tradefed import tradefed_test 26 27# Maximum default time allowed for each individual CTS module. 28_CTS_TIMEOUT_SECONDS = 3600 29 30_PUBLIC_CTS = 'https://dl.google.com/dl/android/cts/' 31_INTERNAL_CTS = 'gs://chromeos-arc-images/cts/bundle/P/' 32_PARTNER_CTS = 'gs://chromeos-partner-gts/P/' 33_OFFICIAL_ZIP_NAME = 'android-cts-9.0_r20-linux_x86-%s.zip' 34_PREVIEW_ZIP_NAME = 'android-cts-8480133-linux_x86-%s.zip' 35_BUNDLE_MAP = { 36 (None, 'arm'): _PUBLIC_CTS + _OFFICIAL_ZIP_NAME % 'arm', 37 (None, 'x86'): _PUBLIC_CTS + _OFFICIAL_ZIP_NAME % 'x86', 38 ('DEV_MOBLAB', 'arm'): _PARTNER_CTS + _PREVIEW_ZIP_NAME % 'arm', 39 ('DEV_MOBLAB', 'x86'): _PARTNER_CTS + _PREVIEW_ZIP_NAME % 'x86', 40 ('LATEST', 'arm'): _INTERNAL_CTS + _OFFICIAL_ZIP_NAME % 'arm', 41 ('LATEST', 'x86'): _INTERNAL_CTS + _OFFICIAL_ZIP_NAME % 'x86', 42 ('DEV', 'arm'): _INTERNAL_CTS + _PREVIEW_ZIP_NAME % 'arm', 43 ('DEV', 'x86'): _INTERNAL_CTS + _PREVIEW_ZIP_NAME % 'x86', 44 ('DEV_WAIVER', 'arm'): _INTERNAL_CTS + _PREVIEW_ZIP_NAME % 'arm', 45 ('DEV_WAIVER', 'x86'): _INTERNAL_CTS + _PREVIEW_ZIP_NAME % 'x86', 46} 47_CTS_MEDIA_URI = _PUBLIC_CTS + 'android-cts-media-1.5.zip' 48_CTS_MEDIA_LOCALPATH = '/tmp/android-cts-media' 49 50 51class cheets_CTS_P(tradefed_test.TradefedTest): 52 """Sets up tradefed to run CTS tests.""" 53 version = 1 54 55 _SHARD_CMD = '--shard-count' 56 _SCENE_URI = ( 57 'https://storage.googleapis.com/chromiumos-test-assets-public' 58 '/camerabox/cts_portrait_scene.jpg') 59 60 def _tradefed_retry_command(self, template, session_id): 61 """Build tradefed 'retry' command from template.""" 62 cmd = [] 63 for arg in template: 64 cmd.append(arg.format(session_id=session_id)) 65 return cmd 66 67 def _tradefed_run_command(self, template): 68 """Build tradefed 'run' command from template.""" 69 cmd = template[:] 70 # If we are running outside of the lab we can collect more data. 71 if not utils.is_in_container(): 72 logging.info('Running outside of lab, adding extra debug options.') 73 cmd.append('--log-level-display=DEBUG') 74 # Apply this PATH change only for chroot environment 75 if not client_utils.is_moblab(): 76 try: 77 os.environ['JAVA_HOME'] = '/opt/icedtea-bin-3.4.0' 78 os.environ['PATH'] = os.environ['JAVA_HOME']\ 79 + '/bin:' + os.environ['PATH'] 80 logging.info(subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)) 81 # TODO(jiyounha): remove once crbug.com/1105515 is resolved. 82 logging.info(subprocess.check_output(['whereis', 'java'], stderr=subprocess.STDOUT)) 83 except OSError: 84 logging.error('Can\'t change current PATH directory') 85 86 # Suppress redundant output from tradefed. 87 cmd.append('--quiet-output=true') 88 return cmd 89 90 def _get_bundle_url(self, uri, bundle): 91 if uri and (uri.startswith('http') or uri.startswith('gs')): 92 return uri 93 else: 94 return _BUNDLE_MAP[(uri, bundle)] 95 96 def _get_tradefed_base_dir(self): 97 return 'android-cts' 98 99 def _tradefed_cmd_path(self): 100 return os.path.join(self._repository, 'tools', 'cts-tradefed') 101 102 def _should_skip_test(self, bundle): 103 """Some tests are expected to fail and are skipped.""" 104 # novato* are x86 VMs without binary translation. Skip the ARM tests. 105 no_ARM_ABI_test_boards = ('novato', 'novato-arc64', 'novato-arcnext') 106 if self._get_board_name() in no_ARM_ABI_test_boards and bundle == 'arm': 107 return True 108 return False 109 110 def initialize_camerabox(self, camera_facing, cmdline_args): 111 """Configure DUT and chart running in camerabox environment. 112 113 @param camera_facing: the facing of the DUT used in testing 114 (e.g. 'front', 'back'). 115 """ 116 chart_address = camerabox_utils.get_chart_address( 117 [h.hostname for h in self._hosts], cmdline_args) 118 if chart_address is None: 119 raise error.TestFail( 120 'Error: missing option --args="chart=<CHART IP>"') 121 chart_hosts = [hosts.create_host(ip) for ip in chart_address] 122 123 self.chart_fixtures = [ 124 camerabox_utils.ChartFixture(h, self._SCENE_URI, self.job) 125 for h in chart_hosts 126 ] 127 self.dut_fixtures = [ 128 camerabox_utils.DUTFixture(self, h, camera_facing) 129 for h in self._hosts 130 ] 131 132 for chart in self.chart_fixtures: 133 chart.initialize() 134 135 for dut in self.dut_fixtures: 136 dut.log_camera_scene() 137 dut.initialize() 138 139 for host in self._hosts: 140 host.run('cras_test_client --mute 1') 141 142 def initialize(self, 143 camera_facing=None, 144 bundle=None, 145 uri=None, 146 host=None, 147 hosts=None, 148 max_retry=None, 149 load_waivers=True, 150 retry_manual_tests=False, 151 warn_on_test_retry=True, 152 cmdline_args=None, 153 hard_reboot_on_failure=False): 154 super(cheets_CTS_P, self).initialize( 155 bundle=bundle, 156 uri=uri, 157 host=host, 158 hosts=hosts, 159 max_retry=max_retry, 160 load_waivers=load_waivers, 161 retry_manual_tests=retry_manual_tests, 162 warn_on_test_retry=warn_on_test_retry, 163 hard_reboot_on_failure=hard_reboot_on_failure) 164 if camera_facing: 165 self.initialize_camerabox(camera_facing, cmdline_args) 166 167 def run_once(self, 168 test_name, 169 run_template, 170 retry_template=None, 171 target_module=None, 172 target_plan=None, 173 needs_push_media=False, 174 enable_default_apps=False, 175 executable_test_count=None, 176 bundle=None, 177 extra_artifacts=[], 178 extra_artifacts_host=[], 179 precondition_commands=[], 180 login_precondition_commands=[], 181 prerequisites=[], 182 timeout=_CTS_TIMEOUT_SECONDS): 183 """Runs the specified CTS once, but with several retries. 184 185 Run an arbitrary tradefed command. 186 187 @param test_name: the name of test. Used for logging. 188 @param run_template: the template to construct the run command. 189 Example: ['run', 'commandAndExit', 'cts', 190 '--skip-media-download'] 191 @param retry_template: the template to construct the retry command. 192 Example: ['run', 'commandAndExit', 'retry', 193 '--skip-media-download', '--retry', 194 '{session_id}'] 195 @param target_module: the name of test module to run. 196 @param target_plan: the name of the test plan to run. 197 @param needs_push_media: need to push test media streams. 198 @param executable_test_count: the known number of tests in the run 199 @param bundle: the type of the CTS bundle: 'arm' or 'x86' 200 @param precondition_commands: a list of scripts to be run on the 201 dut before the test is run, the scripts must already be installed. 202 @param login_precondition_commands: a list of scripts to be run on the 203 dut before the log-in for the test is performed. 204 @param prerequisites: a list of prerequisites that identify rogue DUTs. 205 @param timeout: time after which tradefed can be interrupted. 206 """ 207 self._run_tradefed_with_retries( 208 test_name=test_name, 209 run_template=run_template, 210 retry_template=retry_template, 211 timeout=timeout, 212 target_module=target_module, 213 target_plan=target_plan, 214 media_asset=tradefed_test.MediaAsset( 215 _CTS_MEDIA_URI if needs_push_media else None, 216 _CTS_MEDIA_LOCALPATH), 217 enable_default_apps=enable_default_apps, 218 executable_test_count=executable_test_count, 219 bundle=bundle, 220 extra_artifacts=extra_artifacts, 221 extra_artifacts_host=extra_artifacts_host, 222 login_precondition_commands=login_precondition_commands, 223 precondition_commands=precondition_commands, 224 prerequisites=prerequisites) 225 226 def cleanup_camerabox(self): 227 """Cleanup configuration on DUT and chart tablet for running in 228 229 camerabox environment. 230 """ 231 for dut in self.dut_fixtures: 232 dut.cleanup() 233 234 for chart in self.chart_fixtures: 235 chart.cleanup() 236 237 def cleanup(self): 238 if hasattr(self, 'dut_fixtures'): 239 self.cleanup_camerabox() 240 241 super(cheets_CTS_P, self).cleanup() 242