• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# repohooks/pre-upload.py currently does not run pylint. But for developers who
6# want to check their code manually we disable several harmless pylint warnings
7# which just distract from more serious remaining issues.
8#
9# The instance variable _android_cts is not defined in __init__().
10# pylint: disable=attribute-defined-outside-init
11#
12# Many short variable names don't follow the naming convention.
13# pylint: disable=invalid-name
14
15import logging
16import os
17
18from autotest_lib.client.common_lib import error
19from autotest_lib.server import hosts
20from autotest_lib.server import utils
21from autotest_lib.server.cros import camerabox_utils
22from autotest_lib.server.cros.tradefed import tradefed_constants as constants
23from autotest_lib.server.cros.tradefed import tradefed_test
24
25# Maximum default time allowed for each individual CTS module.
26_CTS_TIMEOUT_SECONDS = 3600
27
28# Public download locations for android cts bundles.
29_DL_CTS = 'https://dl.google.com/dl/android/cts/'
30_CTS_URI = {
31    'arm': _DL_CTS + 'android-cts-7.1_r29-linux_x86-arm.zip',
32    'x86': _DL_CTS + 'android-cts-7.1_r29-linux_x86-x86.zip',
33}
34_CTS_MEDIA_URI = _DL_CTS + 'android-cts-media-1.4.zip'
35_CTS_MEDIA_LOCALPATH = '/tmp/android-cts-media'
36
37
38class cheets_CTS_N(tradefed_test.TradefedTest):
39    """Sets up tradefed to run CTS tests."""
40    version = 1
41
42    _BRANCH_DEFAULT_RETRY = [(0, 10)]  # dev=beta=stable=10
43    _BRANCH_MAX_RETRY = [(0, 10),      # dev=beta=10, stable=99
44        (constants.APPROXIMATE_STABLE_BRANCH_NUMBER, 99)]
45    _SHARD_CMD = '--shards'
46    # TODO(pwang): b/110966363, remove it once scarlet is fixed.
47    _NEED_DEVICE_INFO_BOARDS = ['scarlet', 'veyron_tiger']
48    _SCENE_URI = ('https://storage.googleapis.com'
49                  '/chromiumos-test-assets-public/camerabox/scene.pdf')
50
51    def _tradefed_retry_command(self, template, session_id):
52        """Build tradefed 'retry' command from template."""
53        cmd = []
54        for arg in template:
55            if (arg == '--skip-device-info' and
56                self._get_board_name() in self._NEED_DEVICE_INFO_BOARDS):
57                continue
58            cmd.append(arg.format(session_id=session_id))
59        return cmd
60
61    def _tradefed_run_command(self, template):
62        """Build tradefed 'run' command from template."""
63        cmd = []
64        for arg in template:
65            if (arg == '--skip-device-info' and
66                self._get_board_name() in self._NEED_DEVICE_INFO_BOARDS):
67                continue
68            cmd.append(arg)
69        # If we are running outside of the lab we can collect more data.
70        if not utils.is_in_container():
71            logging.info('Running outside of lab, adding extra debug options.')
72            cmd.append('--log-level-display=DEBUG')
73            cmd.append('--screenshot-on-failure')
74            # TODO(ihf): Add log collection once b/28333587 fixed.
75            # cmd.append('--collect-deqp-logs')
76        return cmd
77
78    def _get_default_bundle_url(self, bundle):
79        return _CTS_URI[bundle]
80
81    def _get_tradefed_base_dir(self):
82        return 'android-cts'
83
84    def _tradefed_cmd_path(self):
85        return os.path.join(self._repository, 'tools', 'cts-tradefed')
86
87    def _should_skip_test(self, bundle):
88        """Some tests are expected to fail and are skipped."""
89        # novato* are x86 VMs without binary translation. Skip the ARM tests.
90        no_ARM_ABI_test_boards = ('novato', 'novato-arc64')
91        if self._get_board_name() in no_ARM_ABI_test_boards and bundle == 'arm':
92            return True
93        return False
94
95    def initialize_camerabox(self, camera_facing, cmdline_args):
96        """Configure DUT and chart running in camerabox environment.
97        @param camera_facing: the facing of the DUT used in testing
98                              (e.g. 'front', 'back').
99        """
100        chart_address = camerabox_utils.get_chart_address(
101                [h.hostname for h in self._hosts], cmdline_args)
102        if chart_address is None:
103            raise error.TestFail(
104                    'Error: missing option --args="chart=<CHART IP>"')
105        chart_hosts = [hosts.create_host(ip) for ip in chart_address]
106
107        self.chart_fixtures = [
108                camerabox_utils.ChartFixture(h, self._SCENE_URI)
109                for h in chart_hosts
110        ]
111        self.dut_fixtures = [
112                camerabox_utils.DUTFixture(self, h, camera_facing)
113                for h in self._hosts
114        ]
115
116        for chart in self.chart_fixtures:
117            chart.initialize()
118
119        for dut in self.dut_fixtures:
120            dut.initialize()
121
122    def initialize(self,
123                   camera_facing=None,
124                   bundle=None,
125                   uri=None,
126                   host=None,
127                   hosts=None,
128                   max_retry=None,
129                   load_waivers=True,
130                   retry_manual_tests=False,
131                   warn_on_test_retry=True,
132                   cmdline_args=None,
133                   hard_reboot_on_failure=False):
134        super(cheets_CTS_N, self).initialize(
135                bundle=bundle,
136                uri=uri,
137                host=host,
138                hosts=hosts,
139                max_retry=max_retry,
140                load_waivers=load_waivers,
141                retry_manual_tests=retry_manual_tests,
142                warn_on_test_retry=warn_on_test_retry,
143                hard_reboot_on_failure=hard_reboot_on_failure)
144        if camera_facing:
145            self.initialize_camerabox(camera_facing, cmdline_args)
146
147    def run_once(self,
148                 test_name,
149                 run_template,
150                 retry_template=None,
151                 target_module=None,
152                 target_plan=None,
153                 target_class=None,
154                 target_method=None,
155                 needs_push_media=False,
156                 enable_default_apps=False,
157                 bundle=None,
158                 extra_artifacts=[],
159                 extra_artifacts_host=[],
160                 precondition_commands=[],
161                 login_precondition_commands=[],
162                 timeout=_CTS_TIMEOUT_SECONDS):
163        """Runs the specified CTS once, but with several retries.
164
165        Run an arbitrary tradefed command.
166
167        @param test_name: the name of test. Used for logging.
168        @param run_template: the template to construct the run command.
169                             Example: ['run', 'commandAndExit', 'cts',
170                                       '--skip-media-download']
171        @param retry_template: the template to construct the retry command.
172                               Example: ['run', 'commandAndExit', 'retry',
173                                         '--skip-media-download', '--retry',
174                                         '{session_id}']
175        @param target_module: the name of test module to run.
176        @param target_plan: the name of the test plan to run.
177        @param target_class: the name of the class to be tested.
178        @param target_method: the name of the method to be tested.
179        @param needs_push_media: need to push test media streams.
180        @param bundle: the type of the CTS bundle: 'arm' or 'x86'
181        @param precondition_commands: a list of scripts to be run on the
182        dut before the test is run, the scripts must already be installed.
183        @param login_precondition_commands: a list of scripts to be run on the
184        dut before the log-in for the test is performed.
185        @param timeout: time after which tradefed can be interrupted.
186        """
187        self._run_tradefed_with_retries(
188            test_name=test_name,
189            run_template=run_template,
190            retry_template=retry_template,
191            timeout=timeout,
192            target_module=target_module,
193            target_plan=target_plan,
194            media_asset=tradefed_test.MediaAsset(
195                _CTS_MEDIA_URI if needs_push_media else None,
196                _CTS_MEDIA_LOCALPATH),
197            enable_default_apps=enable_default_apps,
198            bundle=bundle,
199            extra_artifacts=extra_artifacts,
200            extra_artifacts_host=extra_artifacts_host,
201            cts_uri=_CTS_URI,
202            login_precondition_commands=login_precondition_commands,
203            precondition_commands=precondition_commands)
204
205    def cleanup_camerabox(self):
206        """Cleanup configuration on DUT and chart tablet for running in
207        camerabox environment.
208        """
209        for dut in self.dut_fixtures:
210            dut.cleanup()
211
212        for chart in self.chart_fixtures:
213            chart.cleanup()
214
215    def cleanup(self):
216        if hasattr(self, 'dut_fixtures'):
217            self.cleanup_camerabox()
218
219        super(cheets_CTS_N, self).cleanup()
220