• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 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
5import os
6
7import common
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib import global_config
10from autotest_lib.server import afe_utils
11from autotest_lib.server import test
12from autotest_lib.site_utils import acts_lib
13
14CONFIG_FOLDER_LOCATION = global_config.global_config.get_config_value(
15    'ACTS', 'acts_config_folder', default='')
16
17TEST_CONFIG_FILE_FOLDER = os.path.join(CONFIG_FOLDER_LOCATION,
18                                       'autotest_config')
19TEST_CAMPAIGN_FILE_FOLDER = os.path.join(CONFIG_FOLDER_LOCATION,
20                                         'autotest_campaign')
21
22DEFAULT_TEST_RELATIVE_LOG_PATH = 'results/logs'
23
24
25class android_ACTS(test.test):
26    """Run an Android CTS test case.
27
28    Component relationship:
29    Workstation ----(ssh)---> TestStation -----(adb)-----> Android DUT
30    This code runs on Workstation.
31    """
32    version = 1
33
34    def run_once(self,
35                 testbed=None,
36                 config_file=None,
37                 testbed_name=None,
38                 test_case=None,
39                 test_file=None,
40                 additional_configs=[],
41                 additional_apks=[],
42                 override_build_url=None,
43                 override_acts_zip=None,
44                 override_internal_acts_dir=None,
45                 override_python_bin='python',
46                 acts_timeout=7200,
47                 perma_path=None,
48                 additional_cmd_line_params=None,
49                 testtracker_project_id=None):
50        """Runs an acts test case.
51
52        @param testbed: The testbed to test on.
53        @config_file: The main config file to use for running the test. This
54                      should be relative to the autotest_config folder.
55        @param test_case: The test case to run. Should be None when test_file
56                          is given.
57        @param test_file: The campaign file to run. Should be None when
58                          test_case is given. This should be relative to the
59                          autotest_campaign folder. If multiple are given,
60                          multiple test cases will be run.
61        @param additional_configs: Any additional config files to use.
62                                   These should be relative to the
63                                   autotest_config folder.
64        @param additional_apks: An array of apk info dictionaries.
65                                apk = Name of the apk (eg. sl4a.apk)
66                                package = Name of the package (eg. test.tools)
67                                artifact = Name of the artifact, if not given
68                                           package is used.
69        @param override_build_url: The build url to fetch acts from. If None
70                                   then the build url of the first adb device
71                                   is used.
72        @param override_acts_zip: If given a zip file on the drone is used
73                                  rather than pulling a build.
74        @param override_internal_acts_dir: The directory within the artifact
75                                           where the acts framework folder
76                                           lives.
77        @param override_python_bin: Overrides the default python binary that
78                                    is used.
79        @param acts_timeout: How long to wait for acts to finish.
80        @param perma_path: If given a permantent path will be used rather than
81                           a temp path.
82        @parm testtracker_project_id: ID to use for test tracker project.
83        """
84        host = next(v for v in testbed.get_adb_devices().values())
85
86        if not host:
87            raise error.TestError('No hosts defined for this test, cannot'
88                                  ' determine build to grab artifact from.')
89
90        job_repo_url = afe_utils.get_host_attribute(
91            host, host.job_repo_url_attribute)
92        test_station = testbed.teststation
93        if not perma_path:
94            ts_tempfolder = test_station.get_tmp_dir()
95        else:
96            test_station.run('rm -fr "%s"' % perma_path)
97            test_station.run('mkdir "%s"' % perma_path)
98            ts_tempfolder = perma_path
99        target_zip = os.path.join(ts_tempfolder, 'acts.zip')
100
101        if override_acts_zip and override_build_url:
102            raise error.TestError('Cannot give both a url and zip override.')
103        elif override_acts_zip:
104            package = acts_lib.create_acts_package_from_zip(
105                test_station, override_acts_zip, target_zip)
106        elif override_build_url:
107            build_url_pieces = override_build_url.split('/')
108            if len(build_url_pieces) != 3:
109                raise error.TestError(
110                    'Override build url must be formatted as '
111                    '<branch>/<target>/<build_id>')
112
113            branch = build_url_pieces[0]
114            target = build_url_pieces[1]
115            build_id = build_url_pieces[2]
116            package = acts_lib.create_acts_package_from_artifact(
117                test_station, branch, target, build_id, job_repo_url,
118                target_zip)
119        else:
120            package = acts_lib.create_acts_package_from_current_artifact(
121                test_station, job_repo_url, target_zip)
122
123        test_env = package.create_enviroment(
124            testbed=testbed,
125            container_directory=ts_tempfolder,
126            testbed_name=testbed_name,
127            internal_acts_directory=override_internal_acts_dir)
128
129        test_env.install_sl4a_apk()
130
131        for apk in additional_apks:
132            test_env.install_apk(apk)
133
134        test_env.setup_enviroment(python_bin=override_python_bin)
135
136        test_env.upload_config(config_file)
137
138        if additional_configs:
139            for additional_config in additional_configs:
140                test_env.upload_config(additional_config)
141
142        if test_file:
143            test_env.upload_campaign(test_file)
144
145        results = test_env.run_test(
146            config_file,
147            campaign=test_file,
148            test_case=test_case,
149            python_bin=override_python_bin,
150            timeout=acts_timeout,
151            additional_cmd_line_params=additional_cmd_line_params)
152
153        results.log_output()
154        results.report_to_autotest(self)
155        results.save_test_info(self)
156        results.rethrow_exception()
157