1 # Copyright 2018, The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 """ 16 VTS Tradefed test runner class. 17 """ 18 19 import copy 20 import logging 21 22 # pylint: disable=import-error 23 import atest_tf_test_runner 24 import atest_utils 25 import constants 26 27 28 class VtsTradefedTestRunner(atest_tf_test_runner.AtestTradefedTestRunner): 29 """TradeFed Test Runner class.""" 30 NAME = 'VtsTradefedTestRunner' 31 EXECUTABLE = 'vts-tradefed' 32 _RUN_CMD = ('{exe} run commandAndExit vts-staging-default -m {test} {args}') 33 _BUILD_REQ = {'vts-tradefed-standalone'} 34 _DEFAULT_ARGS = ['--skip-all-system-status-check', 35 '--skip-preconditions', 36 '--primary-abi-only'] 37 38 def __init__(self, results_dir, **kwargs): 39 """Init stuff for vts tradefed runner class.""" 40 super(VtsTradefedTestRunner, self).__init__(results_dir, **kwargs) 41 self.run_cmd_dict = {'exe': self.EXECUTABLE, 42 'test': '', 43 'args': ''} 44 45 def get_test_runner_build_reqs(self): 46 """Return the build requirements. 47 48 Returns: 49 Set of build targets. 50 """ 51 build_req = self._BUILD_REQ 52 build_req |= super(VtsTradefedTestRunner, 53 self).get_test_runner_build_reqs() 54 return build_req 55 56 def run_tests(self, test_infos, extra_args): 57 """Run the list of test_infos. 58 59 Args: 60 test_infos: List of TestInfo. 61 extra_args: Dict of extra args to add to test run. 62 """ 63 run_cmds = self._generate_run_commands(test_infos, extra_args) 64 for run_cmd in run_cmds: 65 super(VtsTradefedTestRunner, self).run(run_cmd) 66 67 def _parse_extra_args(self, extra_args): 68 """Convert the extra args into something vts-tf can understand. 69 70 We want to transform the top-level args from atest into specific args 71 that vts-tradefed supports. The only arg we take as is is EXTRA_ARG 72 since that is what the user intentionally wants to pass to the test 73 runner. 74 75 Args: 76 extra_args: Dict of args 77 78 Returns: 79 List of args to append. 80 """ 81 args_to_append = [] 82 args_not_supported = [] 83 for arg in extra_args: 84 if constants.SERIAL == arg: 85 args_to_append.append('--serial') 86 args_to_append.append(extra_args[arg]) 87 continue 88 if constants.CUSTOM_ARGS == arg: 89 args_to_append.extend(extra_args[arg]) 90 continue 91 args_not_supported.append(arg) 92 if args_not_supported: 93 logging.info('%s does not support the following args: %s', 94 self.EXECUTABLE, args_not_supported) 95 return args_to_append 96 97 # pylint: disable=arguments-differ 98 def _generate_run_commands(self, test_infos, extra_args): 99 """Generate a list of run commands from TestInfos. 100 101 Args: 102 test_infos: List of TestInfo tests to run. 103 extra_args: Dict of extra args to add to test run. 104 105 Returns: 106 A List of strings that contains the vts-tradefed run command. 107 """ 108 cmds = [] 109 args = self._DEFAULT_ARGS 110 args.extend(self._parse_extra_args(extra_args)) 111 args.extend(atest_utils.get_result_server_args()) 112 for test_info in test_infos: 113 cmd_dict = copy.deepcopy(self.run_cmd_dict) 114 cmd_dict['test'] = test_info.test_name 115 cmd_dict['args'] = ' '.join(args) 116 cmds.append(self._RUN_CMD.format(**cmd_dict)) 117 return cmds 118