1# Lint as: python2, python3 2# Copyright 2020 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 18 19from autotest_lib.server import utils 20from autotest_lib.client.common_lib import error 21from autotest_lib.server import hosts 22from autotest_lib.server import utils 23from autotest_lib.server.cros import camerabox_utils 24from autotest_lib.server.cros.tradefed import tradefed_test 25 26# Maximum default time allowed for each individual CTS module. 27_CTS_TIMEOUT_SECONDS = 3600 28 29# Public download locations for android cts bundles. 30_PUBLIC_CTS = 'https://dl.google.com/dl/android/cts/' 31_INTERNAL_CTS = 'gs://chromeos-arc-images/cts/bundle/R/' 32_PARTNER_CTS = 'gs://chromeos-partner-gts/R/' 33_OFFICIAL_ZIP_NAME = 'android-cts-11_r8-linux_x86-%s.zip' 34_PREVIEW_ZIP_NAME = 'android-cts-8654967-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_R(tradefed_test.TradefedTest): 52 """Sets up tradefed to run CTS tests.""" 53 version = 1 54 55 _SCENE_URI = ( 56 'https://storage.googleapis.com/chromiumos-test-assets-public' 57 '/camerabox/cts_portrait_scene.jpg') 58 59 def _tradefed_retry_command(self, template, session_id): 60 """Build tradefed 'retry' command from template.""" 61 cmd = [] 62 for arg in template: 63 cmd.append(arg.format(session_id=session_id)) 64 return cmd 65 66 def _tradefed_run_command(self, template): 67 """Build tradefed 'run' command from template.""" 68 cmd = template[:] 69 # If we are running outside of the lab we can collect more data. 70 if not utils.is_in_container(): 71 logging.info('Running outside of lab, adding extra debug options.') 72 cmd.append('--log-level-display=DEBUG') 73 return cmd 74 75 def _get_bundle_url(self, uri, bundle): 76 if uri and (uri.startswith('http') or uri.startswith('gs')): 77 return uri 78 else: 79 return _BUNDLE_MAP[(uri, bundle)] 80 81 def _get_tradefed_base_dir(self): 82 return 'android-cts' 83 84 def _tradefed_cmd_path(self): 85 return os.path.join(self._repository, 'tools', 'cts-tradefed') 86 87 def initialize_camerabox(self, camera_facing, cmdline_args): 88 """Configure DUT and chart running in camerabox environment. 89 90 @param camera_facing: the facing of the DUT used in testing 91 (e.g. 'front', 'back'). 92 """ 93 chart_address = camerabox_utils.get_chart_address( 94 [h.hostname for h in self._hosts], cmdline_args) 95 if chart_address is None: 96 raise error.TestFail( 97 'Error: missing option --args="chart=<CHART IP>"') 98 chart_hosts = [hosts.create_host(ip) for ip in chart_address] 99 100 self.chart_fixtures = [ 101 camerabox_utils.ChartFixture(h, self._SCENE_URI) 102 for h in chart_hosts 103 ] 104 self.dut_fixtures = [ 105 camerabox_utils.DUTFixture(self, h, camera_facing) 106 for h in self._hosts 107 ] 108 109 for chart in self.chart_fixtures: 110 chart.initialize() 111 112 for dut in self.dut_fixtures: 113 dut.log_camera_scene() 114 dut.initialize() 115 116 for host in self._hosts: 117 host.run('cras_test_client --mute 1') 118 119 def initialize(self, 120 camera_facing=None, 121 bundle=None, 122 uri=None, 123 host=None, 124 hosts=None, 125 max_retry=None, 126 load_waivers=True, 127 retry_manual_tests=False, 128 warn_on_test_retry=True, 129 cmdline_args=None, 130 hard_reboot_on_failure=False, 131 use_jdk9=False, 132 use_old_adb=False): 133 super(cheets_CTS_R, 134 self).initialize(bundle=bundle, 135 uri=uri, 136 host=host, 137 hosts=hosts, 138 max_retry=max_retry, 139 load_waivers=load_waivers, 140 retry_manual_tests=retry_manual_tests, 141 warn_on_test_retry=warn_on_test_retry, 142 hard_reboot_on_failure=hard_reboot_on_failure, 143 use_jdk9=use_jdk9, 144 use_old_adb=use_old_adb) 145 if camera_facing: 146 self.initialize_camerabox(camera_facing, cmdline_args) 147 148 def run_once(self, 149 test_name, 150 run_template, 151 retry_template=None, 152 target_module=None, 153 target_plan=None, 154 needs_push_media=False, 155 use_helpers=False, 156 enable_default_apps=False, 157 executable_test_count=None, 158 bundle=None, 159 precondition_commands=[], 160 login_precondition_commands=[], 161 timeout=_CTS_TIMEOUT_SECONDS): 162 """Runs the specified CTS once, but with several retries. 163 164 Run an arbitrary tradefed command. 165 166 @param test_name: the name of test. Used for logging. 167 @param run_template: the template to construct the run command. 168 Example: ['run', 'commandAndExit', 'cts', 169 '--skip-media-download'] 170 @param retry_template: the template to construct the retry command. 171 Example: ['run', 'commandAndExit', 'retry', 172 '--skip-media-download', '--retry', 173 '{session_id}'] 174 @param target_module: the name of test module to run. 175 @param target_plan: the name of the test plan to run. 176 @param needs_push_media: need to push test media streams. 177 @param use_helpers: copy interaction helpers from the DUT. 178 @param executable_test_count: the known number of tests in the run 179 @param bundle: the type of the CTS bundle: 'arm' or 'x86' 180 @param precondition_commands: a list of scripts to be run on the 181 dut before the test is run, the scripts must already be installed. 182 @param login_precondition_commands: a list of scripts to be run on the 183 dut before the log-in for the test is performed. 184 @param timeout: time after which tradefed can be interrupted. 185 """ 186 self._run_tradefed_with_retries( 187 test_name=test_name, 188 run_template=run_template, 189 retry_template=retry_template, 190 timeout=timeout, 191 target_module=target_module, 192 target_plan=target_plan, 193 media_asset=tradefed_test.MediaAsset( 194 _CTS_MEDIA_URI if needs_push_media else None, 195 _CTS_MEDIA_LOCALPATH), 196 use_helpers=use_helpers, 197 enable_default_apps=enable_default_apps, 198 executable_test_count=executable_test_count, 199 bundle=bundle, 200 login_precondition_commands=login_precondition_commands, 201 precondition_commands=precondition_commands) 202 203 def cleanup_camerabox(self): 204 """Cleanup configuration on DUT and chart tablet for running in 205 206 camerabox environment. 207 """ 208 for dut in self.dut_fixtures: 209 dut.cleanup() 210 211 for chart in self.chart_fixtures: 212 chart.cleanup() 213 214 def cleanup(self): 215 if hasattr(self, 'dut_fixtures'): 216 self.cleanup_camerabox() 217 218 super(cheets_CTS_R, self).cleanup() 219