• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""Example test runner class."""
16
17
18from typing import List
19
20from atest.test_finders import test_info
21from atest.test_runners import test_runner_base
22
23
24class ExampleTestRunner(test_runner_base.TestRunnerBase):
25  """Base Test Runner class."""
26
27  NAME = 'ExampleTestRunner'
28  EXECUTABLE = 'echo'
29  _RUN_CMD = '{exe} ExampleTestRunner - test:{test}'
30  _BUILD_REQ = set()
31
32  # pylint: disable=unused-argument
33  def run_tests(self, test_infos, extra_args, reporter):
34    """Run the list of test_infos.
35
36    Args:
37        test_infos: List of TestInfo.
38        extra_args: Dict of extra args to add to test run.
39        reporter: An instance of result_report.ResultReporter
40    """
41    run_cmds = self.generate_run_commands(test_infos, extra_args)
42    for run_cmd in run_cmds:
43      super(ExampleTestRunner).run(run_cmd)
44
45  # pylint: disable=unnecessary-pass
46  # Please keep above disable flag to ensure host_env_check is overridden.
47  def host_env_check(self):
48    """Check that host env has everything we need.
49
50    We actually can assume the host env is fine because we have the same
51    requirements that atest has. Update this to check for android env vars
52    if that changes.
53    """
54    pass
55
56  def get_test_runner_build_reqs(self, test_infos: List[test_info.TestInfo]):
57    """Return the build requirements.
58
59    Args:
60        test_infos: List of TestInfo.
61
62    Returns:
63        Set of build targets.
64    """
65    return set()
66
67  # pylint: disable=unused-argument
68  def generate_run_commands(self, test_infos, extra_args, port=None):
69    """Generate a list of run commands from TestInfos.
70
71    Args:
72        test_infos: A set of TestInfo instances.
73        extra_args: A Dict of extra args to append.
74        port: Optional. An int of the port number to send events to. Subprocess
75          reporter in TF won't try to connect if it's None.
76
77    Returns:
78        A list of run commands to run the tests.
79    """
80    run_cmds = []
81    for test_info in test_infos:
82      run_cmd_dict = {'exe': self.EXECUTABLE, 'test': test_info.test_name}
83      run_cmds.extend(self._RUN_CMD.format(**run_cmd_dict))
84    return run_cmds
85