1# Copyright 2020 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_vts 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 15import logging 16import os 17 18from autotest_lib.server import utils 19from autotest_lib.server.cros.tradefed import tradefed_test 20 21# Maximum default time allowed for each individual CTS module. 22_CTS_TIMEOUT_SECONDS = 3600 23 24# Internal download locations for android vts bundles. 25_INTERNAL_VTS = 'gs://chromeos-arc-images/vts/' 26_VTS_URI = { 27 'arm': _INTERNAL_VTS + 'android-vts-6722941-linux_x86-arm.zip', 28 'x86': _INTERNAL_VTS + 'android-vts-6722941-linux_x86-x86.zip', 29} 30 31 32class cheets_VTS_R(tradefed_test.TradefedTest): 33 """Sets up tradefed to run VTS tests.""" 34 version = 1 35 36 _SHARD_CMD = '--shard-count' 37 38 def _tradefed_retry_command(self, template, session_id): 39 """Build tradefed 'retry' command from template.""" 40 cmd = [] 41 for arg in template: 42 cmd.append(arg.format(session_id=session_id)) 43 return cmd 44 45 def _tradefed_run_command(self, template): 46 """Build tradefed 'run' command from template.""" 47 cmd = template[:] 48 # If we are running outside of the lab we can collect more data. 49 if not utils.is_in_container(): 50 logging.info('Running outside of lab, adding extra debug options.') 51 cmd.append('--log-level-display=DEBUG') 52 return cmd 53 54 def _get_default_bundle_url(self, bundle): 55 return _VTS_URI[bundle] 56 57 def _get_tradefed_base_dir(self): 58 return 'android-vts' 59 60 def _tradefed_cmd_path(self): 61 return os.path.join(self._repository, 'tools', 'vts-tradefed') 62 63 def _should_skip_test(self, bundle): 64 """Some tests are expected to fail and are skipped.""" 65 # novato* are x86 VMs without binary translation. Skip the ARM tests. 66 no_ARM_ABI_test_boards = ('novato', 'novato-arc64', 'novato-arcnext') 67 if self._get_board_name( 68 ) in no_ARM_ABI_test_boards and bundle == 'arm': 69 return True 70 return False 71 72 def run_once(self, 73 test_name, 74 run_template, 75 retry_template=None, 76 target_module=None, 77 target_plan=None, 78 needs_push_media=False, 79 bundle=None, 80 precondition_commands=[], 81 login_precondition_commands=[], 82 timeout=_CTS_TIMEOUT_SECONDS): 83 """Runs the specified CTS once, but with several retries. 84 85 Run an arbitrary tradefed command. 86 87 @param test_name: the name of test. Used for logging. 88 @param run_template: the template to construct the run command. 89 Example: ['run', 'commandAndExit', 'cts', 90 '--skip-media-download'] 91 @param retry_template: the template to construct the retry command. 92 Example: ['run', 'commandAndExit', 'retry', 93 '--skip-media-download', '--retry', 94 '{session_id}'] 95 @param target_module: the name of test module to run. 96 @param target_plan: the name of the test plan to run. 97 @param needs_push_media: need to push test media streams. 98 @param bundle: the type of the CTS bundle: 'arm' or 'x86' 99 @param precondition_commands: a list of scripts to be run on the 100 dut before the test is run, the scripts must already be installed. 101 @param login_precondition_commands: a list of scripts to be run on the 102 dut before the log-in for the test is performed. 103 @param timeout: time after which tradefed can be interrupted. 104 """ 105 self._run_tradefed_with_retries( 106 test_name=test_name, 107 run_template=run_template, 108 retry_template=retry_template, 109 timeout=timeout, 110 target_module=target_module, 111 target_plan=target_plan, 112 bundle=bundle, 113 cts_uri=_VTS_URI, 114 login_precondition_commands=login_precondition_commands, 115 precondition_commands=precondition_commands) 116