blob: e7af776a1691984b716144334aee8fcfd480212d [file] [log] [blame]
Ilja H. Friedelde0c4652017-02-22 01:18:39 -08001# 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
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080015import logging
16import os
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080017
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080018from autotest_lib.server import utils
19from autotest_lib.server.cros import tradefed_test
20
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080021# Maximum default time allowed for each individual CTS module.
22_CTS_TIMEOUT_SECONDS = 3600
23
24# Public download locations for android cts bundles.
25_DL_CTS = 'https://dl.google.com/dl/android/cts/'
26_CTS_URI = {
Keith Haddow95b23fc2018-11-14 13:15:39 -080027 'arm': _DL_CTS + 'android-cts-7.1_r23-linux_x86-arm.zip',
28 'x86': _DL_CTS + 'android-cts-7.1_r23-linux_x86-x86.zip',
Kazuhiro Inaba9a57a522017-12-11 12:42:55 +090029 'media': _DL_CTS + 'android-cts-media-1.4.zip',
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080030}
31
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080032
Po-Hsien Wang01115002018-06-14 17:12:34 -070033class cheets_CTS_N(tradefed_test.TradefedTest):
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080034 """Sets up tradefed to run CTS tests."""
35 version = 1
36
Ilja H. Friedel29f2f9e2018-11-15 00:02:56 -080037 _BOARD_RETRY = {'betty': 0}
38 _CHANNEL_RETRY = {'dev': 9, 'beta': 9, 'stable': 9}
Po-Hsien Wangf72c7ad2018-03-23 15:55:39 -070039 _SHARD_CMD = '--shards'
Po-Hsien Wang32eb3ee2018-07-09 16:54:18 -070040 # TODO(pwang): b/110966363, remove it once scarlet is fixed.
Kazuhiro Inabaf72e1292018-11-20 15:37:08 +090041 _NEED_DEVICE_INFO_BOARDS = ['scarlet', 'veyron_tiger']
Po-Hsien Wang715d5e92017-09-29 17:12:00 -070042
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -070043 def _tradefed_retry_command(self, template, session_id):
44 """Build tradefed 'retry' command from template."""
45 cmd = []
46 for arg in template:
Po-Hsien Wang32eb3ee2018-07-09 16:54:18 -070047 if (arg == '--skip-device-info' and
48 self._get_board_name() in self._NEED_DEVICE_INFO_BOARDS):
49 continue
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -070050 cmd.append(arg.format(session_id=session_id))
51 return cmd
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080052
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -070053 def _tradefed_run_command(self, template):
54 """Build tradefed 'run' command from template."""
Po-Hsien Wang32eb3ee2018-07-09 16:54:18 -070055 cmd = []
56 for arg in template:
57 if (arg == '--skip-device-info' and
58 self._get_board_name() in self._NEED_DEVICE_INFO_BOARDS):
59 continue
60 cmd.append(arg)
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080061 # If we are running outside of the lab we can collect more data.
62 if not utils.is_in_container():
63 logging.info('Running outside of lab, adding extra debug options.')
64 cmd.append('--log-level-display=DEBUG')
65 cmd.append('--screenshot-on-failure')
66 # TODO(ihf): Add log collection once b/28333587 fixed.
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -070067 # cmd.append('--collect-deqp-logs')
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080068 return cmd
69
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -070070 def _get_default_bundle_url(self, bundle):
71 return _CTS_URI[bundle]
72
73 def _get_tradefed_base_dir(self):
74 return 'android-cts'
75
Kazuhiro Inaba20e34882017-11-07 15:56:37 +090076 def _run_tradefed(self, commands):
77 """Kick off CTS.
David Haddockf8b45772017-11-02 13:57:56 -070078
Kazuhiro Inaba20e34882017-11-07 15:56:37 +090079 @param commands: the command(s) to pass to CTS.
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080080 @param datetime_id: For 'continue' datetime of previous run is known.
Kazuhiro Inaba20e34882017-11-07 15:56:37 +090081 @return: The result object from utils.run.
Ilja H. Friedelde0c4652017-02-22 01:18:39 -080082 """
Kazuhiro Inaba20e34882017-11-07 15:56:37 +090083 cts_tradefed = os.path.join(self._repository, 'tools', 'cts-tradefed')
Po-Hsien Wang8fa0ea62018-02-27 15:30:22 -080084 with tradefed_test.adb_keepalive(self._get_adb_targets(),
Ilja H. Friedel69923812018-02-02 18:22:28 -080085 self._install_paths):
86 for command in commands:
87 logging.info('RUN: ./cts-tradefed %s', ' '.join(command))
88 output = self._run(
89 cts_tradefed,
90 args=tuple(command),
Kazuhiro Inabae322bed2018-07-27 14:51:20 +090091 timeout=self._timeout * self._timeout_factor,
Ilja H. Friedel69923812018-02-02 18:22:28 -080092 verbose=True,
93 ignore_status=False,
94 # Make sure to tee tradefed stdout/stderr to autotest logs
95 # continuously during the test run.
96 stdout_tee=utils.TEE_TO_LOGS,
97 stderr_tee=utils.TEE_TO_LOGS)
Po-Hsien Wang8fa0ea62018-02-27 15:30:22 -080098 logging.info('END: ./cts-tradefed %s\n', ' '.join(command))
Kazuhiro Inaba20e34882017-11-07 15:56:37 +090099 return output
Ilja H. Friedelde0c4652017-02-22 01:18:39 -0800100
Kazuhiro Inabaa8c33e52018-08-06 15:46:16 +0900101 def _should_skip_test(self, bundle):
Nicolas Norvez14a39782017-07-17 16:59:14 -0700102 """Some tests are expected to fail and are skipped."""
103 # newbie and novato are x86 VMs without binary translation. Skip the ARM
104 # tests.
Nicolas Norvez29a09602017-08-16 14:02:15 -0700105 no_ARM_ABI_test_boards = ('newbie', 'novato', 'novato-arc64')
Kazuhiro Inabaa8c33e52018-08-06 15:46:16 +0900106 if self._get_board_name() in no_ARM_ABI_test_boards and bundle == 'arm':
107 return True
Nicolas Norvez14a39782017-07-17 16:59:14 -0700108 return False
Keith Haddow3c6bb062017-07-01 13:58:50 -0700109
David Haddockf8b45772017-11-02 13:57:56 -0700110 def run_once(self,
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -0700111 test_name,
112 run_template,
113 retry_template=None,
David Haddockf8b45772017-11-02 13:57:56 -0700114 target_module=None,
115 target_plan=None,
116 target_class=None,
117 target_method=None,
118 needs_push_media=False,
Kazuhiro Inabae322bed2018-07-27 14:51:20 +0900119 bundle=None,
David Haddockf8b45772017-11-02 13:57:56 -0700120 precondition_commands=[],
121 login_precondition_commands=[],
122 timeout=_CTS_TIMEOUT_SECONDS):
123 """Runs the specified CTS once, but with several retries.
Ilja H. Friedelde0c4652017-02-22 01:18:39 -0800124
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -0700125 Run an arbitrary tradefed command.
Ilja H. Friedelde0c4652017-02-22 01:18:39 -0800126
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -0700127 @param test_name: the name of test. Used for logging.
128 @param run_template: the template to construct the run command.
129 Example: ['run', 'commandAndExit', 'cts',
130 '--skip-media-download']
131 @param retry_template: the template to construct the retry command.
132 Example: ['run', 'commandAndExit', 'retry',
133 '--skip-media-download', '--retry',
134 '{session_id}']
David Haddockf8b45772017-11-02 13:57:56 -0700135 @param target_module: the name of test module to run.
136 @param target_plan: the name of the test plan to run.
137 @param target_class: the name of the class to be tested.
138 @param target_method: the name of the method to be tested.
139 @param needs_push_media: need to push test media streams.
Kazuhiro Inabae322bed2018-07-27 14:51:20 +0900140 @param bundle: the type of the CTS bundle: 'arm' or 'x86'
David Haddockf8b45772017-11-02 13:57:56 -0700141 @param precondition_commands: a list of scripts to be run on the
142 dut before the test is run, the scripts must already be installed.
143 @param login_precondition_commands: a list of scripts to be run on the
144 dut before the log-in for the test is performed.
Kazuhiro Inabae322bed2018-07-27 14:51:20 +0900145 @param timeout: time after which tradefed can be interrupted.
David Haddockf8b45772017-11-02 13:57:56 -0700146 """
Ilja H. Friedelde0c4652017-02-22 01:18:39 -0800147
David Haddockf8b45772017-11-02 13:57:56 -0700148 # On dev and beta channels timeouts are sharp, lenient on stable.
149 self._timeout = timeout
Po-Hsien Wang8fa0ea62018-02-27 15:30:22 -0800150 if self._get_release_channel() == 'stable':
David Haddockf8b45772017-11-02 13:57:56 -0700151 self._timeout += 3600
Kazuhiro Inabae322bed2018-07-27 14:51:20 +0900152
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -0700153 self._run_tradefed_with_retries(
154 test_name=test_name,
155 run_template=run_template,
156 retry_template=retry_template,
157 target_module=target_module,
158 target_plan=target_plan,
159 needs_push_media=needs_push_media,
Kazuhiro Inabae322bed2018-07-27 14:51:20 +0900160 bundle=bundle,
Po-Hsien Wang4f9a9142018-06-14 17:09:38 -0700161 cts_uri=_CTS_URI,
162 login_precondition_commands=login_precondition_commands,
163 precondition_commands=precondition_commands)