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_gts 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 15 import logging 16 import os 17 18 from autotest_lib.server import utils 19 from autotest_lib.server.cros import tradefed_test 20 21 _PARTNER_GTS_LOCATION = 'gs://chromeos-partner-gts/gts-5.1_r3-4604229.zip' 22 23 24 class cheets_GTS(tradefed_test.TradefedTest): 25 """Sets up tradefed to run GTS tests.""" 26 version = 1 27 28 def _get_default_bundle_url(self, bundle): 29 return _PARTNER_GTS_LOCATION 30 31 32 def _get_tradefed_base_dir(self): 33 return 'android-gts' 34 35 36 def _tradefed_run_command(self, target_module=None, plan=None, 37 session_id=None): 38 """Builds the GTS command line. 39 40 @param target_module: the module to be run. 41 @param plan: the plan to be run. 42 @param session_id: tradfed session id to continue. 43 """ 44 args = ['run', 'commandAndExit', 'gts'] 45 if target_module is not None: 46 args += ['--module', target_module] 47 elif plan is not None and session_id is not None: 48 args += ['--plan', plan, '--retry', '%d' % session_id] 49 return args 50 51 52 def _run_tradefed(self, commands): 53 """Kick off GTS. 54 55 @param commands: the command(s) to pass to GTS. 56 @return: The result object from utils.run. 57 """ 58 gts_tradefed = os.path.join(self._repository, 'tools', 'gts-tradefed') 59 with tradefed_test.adb_keepalive(self._get_adb_target(), 60 self._install_paths): 61 for command in commands: 62 logging.info('RUN: ./gts-tradefed %s', ' '.join(command)) 63 output = self._run(gts_tradefed, 64 args=command, 65 verbose=True, 66 # Tee tradefed stdout/stderr to logs 67 # continuously during the test run. 68 stdout_tee=utils.TEE_TO_LOGS, 69 stderr_tee=utils.TEE_TO_LOGS) 70 logging.info('END: ./gts-tradefed %s\n', ' '.join(command)) 71 return output 72 73 74 def run_once(self, target_package=None, tradefed_args=None): 75 """Runs GTS with either a target module or a custom command line. 76 77 @param target_package: the name of test module to be run. 78 @param tradefed_args: used to pass any specific cmd to GTS binary. 79 """ 80 if tradefed_args: 81 test_command = tradefed_args 82 test_name = ' '.join(tradefed_args) 83 else: 84 test_command = self._tradefed_run_command(target_package) 85 test_name = 'module.%s' % target_package 86 self._run_tradefed_with_retries(target_package, test_command, test_name) 87