• 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"""
16Regression Detection test runner class.
17"""
18
19from typing import List
20
21from atest import constants
22
23from atest.test_finders import test_info
24from atest.test_runners import test_runner_base
25
26
27class RegressionTestRunner(test_runner_base.TestRunnerBase):
28    """Regression Test Runner class."""
29    NAME = 'RegressionTestRunner'
30    EXECUTABLE = 'tradefed.sh'
31    _RUN_CMD = '{exe} run commandAndExit regression -n {args}'
32    _BUILD_REQ = {'tradefed-core', constants.ATEST_TF_MODULE}
33
34    def __init__(self, results_dir):
35        """Init stuff for base class."""
36        super(RegressionTestRunner).__init__(results_dir)
37        self.run_cmd_dict = {'exe': self.EXECUTABLE,
38                             'args': ''}
39
40    # pylint: disable=unused-argument
41    def run_tests(self, test_infos, extra_args, reporter):
42        """Run the list of test_infos.
43
44        Args:
45            test_infos: List of TestInfo.
46            extra_args: Dict of args to add to regression detection test run.
47            reporter: A ResultReporter instance.
48
49        Returns:
50            Return code of the process for running tests.
51        """
52        run_cmds = self.generate_run_commands(test_infos, extra_args)
53        proc = super(RegressionTestRunner).run(run_cmds[0],
54                                               output_to_stdout=True)
55        proc.wait()
56        return proc.returncode
57
58    # pylint: disable=unnecessary-pass
59    # Please keep above disable flag to ensure host_env_check is overriden.
60    def host_env_check(self):
61        """Check that host env has everything we need.
62
63        We actually can assume the host env is fine because we have the same
64        requirements that atest has. Update this to check for android env vars
65        if that changes.
66        """
67        pass
68
69    def get_test_runner_build_reqs(self, test_infos: List[test_info.TestInfo]):
70        """Return the build requirements.
71
72        Args:
73            test_infos: List of TestInfo.
74
75        Returns:
76            Set of build targets.
77        """
78        return self._BUILD_REQ
79
80    # pylint: disable=unused-argument
81    def generate_run_commands(self, test_infos, extra_args, port=None):
82        """Generate a list of run commands from TestInfos.
83
84        Args:
85            test_infos: A set of TestInfo instances.
86            extra_args: A Dict of extra args to append.
87            port: Optional. An int of the port number to send events to.
88                  Subprocess reporter in TF won't try to connect if it's None.
89
90        Returns:
91            A list that contains the string of atest tradefed run command.
92            Only one command is returned.
93        """
94        pre = extra_args.pop(constants.PRE_PATCH_FOLDER)
95        post = extra_args.pop(constants.POST_PATCH_FOLDER)
96        args = ['--pre-patch-metrics', pre, '--post-patch-metrics', post]
97        self.run_cmd_dict['args'] = ' '.join(args)
98        run_cmd = self._RUN_CMD.format(**self.run_cmd_dict)
99        return [run_cmd]
100