• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright 2016 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# repohooks/pre-upload.py currently does not run pylint. But for developers who
7# want to check their code manually we disable several harmless pylint warnings
8# which just distract from more serious remaining issues.
9#
10# The instance variable _android_cts is not defined in __init__().
11# pylint: disable=attribute-defined-outside-init
12#
13# Many short variable names don't follow the naming convention.
14# pylint: disable=invalid-name
15
16import logging
17import os
18import subprocess
19
20from autotest_lib.client.bin import utils as client_utils
21from autotest_lib.server import utils
22from autotest_lib.server.cros.tradefed import tradefed_test
23
24# Maximum default time allowed for each individual CTS module.
25_CTS_TIMEOUT_SECONDS = 3600
26
27_PUBLIC_CTS = 'https://dl.google.com/dl/android/cts/'
28_INTERNAL_CTS = 'gs://chromeos-arc-images/cts/bundle/P/'
29_BUNDLE_MAP = {
30        (None, 'arm'):
31        _PUBLIC_CTS + 'android-cts_instant-9.0_r20-linux_x86-arm.zip',
32        (None, 'x86'):
33        _PUBLIC_CTS + 'android-cts_instant-9.0_r20-linux_x86-x86.zip',
34        ('LATEST', 'arm'):
35        _INTERNAL_CTS + 'android-cts_instant-9.0_r20-linux_x86-arm.zip',
36        ('LATEST', 'x86'):
37        _INTERNAL_CTS + 'android-cts_instant-9.0_r20-linux_x86-x86.zip',
38        # No 'DEV' job for CTS_Instant for now.
39}
40_CTS_MEDIA_URI = _PUBLIC_CTS + 'android-cts-media-1.5.zip'
41_CTS_MEDIA_LOCALPATH = '/tmp/android-cts-media'
42
43class cheets_CTS_Instant(tradefed_test.TradefedTest):
44    """Sets up tradefed to run CTS tests."""
45    version = 1
46
47    _SHARD_CMD = '--shard-count'
48
49    def _tradefed_retry_command(self, template, session_id):
50        """Build tradefed 'retry' command from template."""
51        cmd = []
52        for arg in template:
53            cmd.append(arg.format(session_id=session_id))
54        # See b/149681932. Pass empty url to force using local config, instead
55        # of doing a network access (which anyway returns an empty config.)
56        cmd.append('--dynamic-config-url=')
57        return cmd
58
59    def _tradefed_run_command(self, template):
60        """Build tradefed 'run' command from template."""
61        cmd = template[:]
62        # See b/149681932. Pass empty url to force using local config, instead
63        # of doing a network access (which anyway returns an empty config.)
64        cmd.append('--dynamic-config-url=')
65        # If we are running outside of the lab we can collect more data.
66        if not utils.is_in_container():
67            logging.info('Running outside of lab, adding extra debug options.')
68            cmd.append('--log-level-display=DEBUG')
69            # Apply this PATH change only for chroot environment
70            if not client_utils.is_moblab():
71                try:
72                    os.environ['JAVA_HOME'] = '/opt/icedtea-bin-3.4.0'
73                    os.environ['PATH'] = os.environ['JAVA_HOME']\
74                                       + '/bin:' + os.environ['PATH']
75                    logging.info(
76                            subprocess.check_output(['java', '-version'],
77                                                    stderr=subprocess.STDOUT))
78                    # TODO(jiyounha): remove once crbug.com/1105515 is resolved.
79                    logging.info(
80                            subprocess.check_output(['whereis', 'java'],
81                                                    stderr=subprocess.STDOUT))
82                except OSError:
83                    logging.error('Can\'t change current PATH directory')
84        # Suppress redundant output from tradefed.
85        cmd.append('--quiet-output=true')
86        return cmd
87
88    def _get_bundle_url(self, uri, bundle):
89        if uri and (uri.startswith('http') or uri.startswith('gs')):
90            return uri
91        else:
92            return _BUNDLE_MAP[(uri, bundle)]
93
94    def _get_tradefed_base_dir(self):
95        return 'android-cts_instant'
96
97    def _tradefed_cmd_path(self):
98        return os.path.join(self._repository, 'tools', 'cts-instant-tradefed')
99
100    def _should_skip_test(self, bundle):
101        """Some tests are expected to fail and are skipped."""
102        # novato* are x86 VMs without binary translation. Skip the ARM tests.
103        no_ARM_ABI_test_boards = ('novato', 'novato-arc64', 'novato-arcnext')
104        if self._get_board_name() in no_ARM_ABI_test_boards and bundle == 'arm':
105            return True
106        return False
107
108    def run_once(self,
109                 test_name,
110                 run_template,
111                 retry_template=None,
112                 target_module=None,
113                 target_plan=None,
114                 needs_push_media=False,
115                 bundle=None,
116                 precondition_commands=[],
117                 login_precondition_commands=[],
118                 timeout=_CTS_TIMEOUT_SECONDS):
119        """Runs the specified CTS once, but with several retries.
120
121        Run an arbitrary tradefed command.
122
123        @param test_name: the name of test. Used for logging.
124        @param run_template: the template to construct the run command.
125                             Example: ['run', 'commandAndExit', 'cts',
126                                       '--skip-media-download']
127        @param retry_template: the template to construct the retry command.
128                               Example: ['run', 'commandAndExit', 'retry',
129                                         '--skip-media-download', '--retry',
130                                         '{session_id}']
131        @param target_module: the name of test module to run.
132        @param target_plan: the name of the test plan to run.
133        @param needs_push_media: need to push test media streams.
134        @param bundle: the type of the CTS bundle: 'arm' or 'x86'
135        @param precondition_commands: a list of scripts to be run on the
136        dut before the test is run, the scripts must already be installed.
137        @param login_precondition_commands: a list of scripts to be run on the
138        dut before the log-in for the test is performed.
139        @param timeout: time after which tradefed can be interrupted.
140        """
141        self._run_tradefed_with_retries(
142            test_name=test_name,
143            run_template=run_template,
144            retry_template=retry_template,
145            timeout=timeout,
146            target_module=target_module,
147            target_plan=target_plan,
148            media_asset=tradefed_test.MediaAsset(
149                _CTS_MEDIA_URI if needs_push_media else None,
150                _CTS_MEDIA_LOCALPATH),
151            bundle=bundle,
152            login_precondition_commands=login_precondition_commands,
153            precondition_commands=precondition_commands)
154