1 # Copyright 2013 The Chromium 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.
5 """Generates test runner factory and tests for instrumentation tests."""
10 from devil
.android
import device_utils
11 from pylib
import constants
12 from pylib
import valgrind_tools
13 from pylib
.base
import base_setup
14 from pylib
.instrumentation
import test_package
15 from pylib
.instrumentation
import test_runner
17 DEVICE_DATA_DIR
= 'chrome/test/data'
19 ISOLATE_FILE_PATHS
= {
20 'AndroidWebViewTest': 'android_webview/android_webview_test_apk.isolate',
21 'ContentShellTest': 'content/content_shell_test_apk.isolate',
24 DEPS_EXCLUSION_LIST
= []
26 # TODO(mikecase): Remove this function and the constant DEVICE_DATA_DIR
27 # once all data deps are pushed to the same location on the device.
28 def _PushExtraSuiteDataDeps(device
, test_apk
):
29 """Pushes some extra data files/dirs needed by some test suite.
32 test_apk: The test suite basename for which to return file paths.
34 if test_apk
in ['ChromeTest', 'ContentShellTest']:
35 test_files
= 'net/data/ssl/certificates'
36 host_device_file_tuple
= [
37 (os
.path
.join(constants
.DIR_SOURCE_ROOT
, test_files
),
38 os
.path
.join(device
.GetExternalStoragePath(), test_files
))]
39 device
.PushChangedFiles(host_device_file_tuple
)
42 # TODO(mikecase): Remove this function once everything uses
43 # base_setup.PushDataDeps to push data deps to the device.
44 def _PushDataDeps(device
, test_options
):
45 valgrind_tools
.PushFilesForTool(test_options
.tool
, device
)
47 host_device_file_tuples
= []
48 for dest_host_pair
in test_options
.test_data
:
49 dst_src
= dest_host_pair
.split(':', 1)
50 dst_layer
= dst_src
[0]
52 host_test_files_path
= os
.path
.join(constants
.DIR_SOURCE_ROOT
, host_src
)
53 if os
.path
.exists(host_test_files_path
):
54 host_device_file_tuples
+= [(
57 device
.GetExternalStoragePath(),
60 if host_device_file_tuples
:
61 device
.PushChangedFiles(host_device_file_tuples
)
64 def Setup(test_options
, devices
):
65 """Create and return the test runner factory and tests.
68 test_options: An InstrumentationOptions object.
71 A tuple of (TestRunnerFactory, tests).
73 if (test_options
.coverage_dir
and not
74 os
.path
.exists(test_options
.coverage_dir
)):
75 os
.makedirs(test_options
.coverage_dir
)
77 test_pkg
= test_package
.TestPackage(test_options
.test_apk_path
,
78 test_options
.test_apk_jar_path
,
79 test_options
.test_support_apk_path
)
80 tests
= test_pkg
.GetAllMatchingTests(
81 test_options
.annotations
,
82 test_options
.exclude_annotations
,
83 test_options
.test_filter
,
86 logging
.error('No instrumentation tests to run with current args.')
88 if test_options
.test_data
:
89 device_utils
.DeviceUtils
.parallel(devices
).pMap(
90 _PushDataDeps
, test_options
)
92 if test_options
.isolate_file_path
:
93 i
= base_setup
.GenerateDepsDirUsingIsolate(test_options
.test_apk
,
94 test_options
.isolate_file_path
,
97 def push_data_deps_to_device_dir(device
):
98 base_setup
.PushDataDeps(device
, device
.GetExternalStoragePath(),
100 device_utils
.DeviceUtils
.parallel(devices
).pMap(
101 push_data_deps_to_device_dir
)
105 device_utils
.DeviceUtils
.parallel(devices
).pMap(
106 _PushExtraSuiteDataDeps
, test_options
.test_apk
)
108 def TestRunnerFactory(device
, shard_index
):
109 return test_runner
.TestRunner(test_options
, device
, shard_index
,
112 return (TestRunnerFactory
, tests
)