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