• 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_gts 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
17import re
18
19from autotest_lib.client.common_lib import error
20from autotest_lib.server import utils
21from autotest_lib.server.cros import tradefed_test
22
23_PARTNER_GTS_LOCATION = 'gs://chromeos-partner-gts/gts-4.1_r1-3556119.zip'
24
25
26class cheets_GTS(tradefed_test.TradefedTest):
27    """Sets up tradefed to run GTS tests."""
28    version = 1
29
30    def setup(self, uri=None):
31        """Set up GTS bundle from Google Storage.
32
33        @param uri: The location to pull the GTS bundle from.
34        """
35
36        if uri:
37            self._android_gts = self._install_bundle(uri)
38        else:
39            self._android_gts = self._install_bundle(_PARTNER_GTS_LOCATION)
40
41        self.waivers = self._get_expected_failures('expectations')
42
43
44    def _run_gts_tradefed(self, target_package):
45        """This tests runs the GTS(XTS) tradefed binary and collects results.
46
47        @param target_package: the name of test package to be run. If None is
48                set, full GTS set will run.
49        @raise TestFail: when a test failure is detected.
50        """
51        self._target_package = target_package
52        gts_tradefed = os.path.join(
53                self._android_gts,
54                'android-gts',
55                'tools',
56                'gts-tradefed')
57        logging.info('GTS-tradefed path: %s', gts_tradefed)
58        #TODO(dhaddock): remove --skip-device-info with GTS 4.1_r2 (b/32889514)
59        gts_tradefed_args = ['run', 'commandAndExit', 'gts',
60                             '--skip-device-info', '--module',
61                             self._target_package]
62        # Run GTS via tradefed and obtain stdout, sterr as output.
63        with tradefed_test.adb_keepalive(self._get_adb_target(),
64                                         self._install_paths):
65            output = self._run(
66                    gts_tradefed,
67                    args=gts_tradefed_args,
68                    verbose=True,
69                    # Make sure to tee tradefed stdout/stderr to autotest logs
70                    # already during the test run.
71                    stdout_tee=utils.TEE_TO_LOGS,
72                    stderr_tee=utils.TEE_TO_LOGS)
73        result_destination = os.path.join(self.resultsdir, 'android-gts')
74
75        # Gather the global log first. Datetime parsing below can abort the test
76        # if tradefed startup had failed. Even then the global log is useful.
77        self._collect_tradefed_global_log(output, result_destination)
78
79        # Parse stdout to obtain datetime IDs of directories into which tradefed
80        # wrote result xml files and logs.
81        datetime_id = self._parse_tradefed_datetime(output)
82        repository = os.path.join(self._android_gts, 'android-gts')
83        self._collect_logs(repository, datetime_id, result_destination)
84
85        # Result parsing must come after all other essential operations as test
86        # warnings, errors and failures can be raised here.
87        tests, passed, failed, not_executed, waived = self._parse_result_v2(
88            output, accumulative_count=True, waivers=self.waivers)
89        passed += waived
90        failed -= waived
91        if tests != passed or failed > 0 or not_executed > 0:
92            raise error.TestFail('Failed: Passed (%d), Failed (%d), '
93                                 'Not Executed (%d)' %
94                                 (passed, failed, not_executed))
95
96        # All test has passed successfully, here.
97        logging.info('The test has passed successfully.')
98
99    def _parse_tradefed_datetime(self, result):
100        """This parses the tradefed datetime object from the GTS output.
101        :param result: the tradefed result object
102        :return: the datetime
103        """
104        #TODO(dhaddock): Merge this into tradefed_test when N is working
105        match = re.search(r': Starting invocation for .+ (\S+) on device',
106                          result.stdout)
107        datetime_id = match.group(1)
108        logging.info('Tradefed identified results and logs with %s.',
109                     datetime_id)
110        return datetime_id
111
112    def run_once(self, target_package=None):
113        """Runs GTS target package exactly once."""
114        with self._login_chrome():
115            self._connect_adb()
116            self._disable_adb_install_dialog()
117            self._wait_for_arc_boot()
118            self._run_gts_tradefed(target_package)
119