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