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 pylib
import constants
11 from pylib
import valgrind_tools
13 from pylib
.base
import base_setup
14 from pylib
.device
import device_utils
15 from pylib
.instrumentation
import test_package
16 from pylib
.instrumentation
import test_runner
18 DEVICE_DATA_DIR
= 'chrome/test/data'
20 ISOLATE_FILE_PATHS
= {
21 'AndroidWebViewTest': 'android_webview/android_webview_test_apk.isolate',
22 'ChromeShellTest': 'chrome/chrome_shell_test_apk.isolate',
23 'ContentShellTest': 'content/content_shell_test_apk.isolate',
26 DEPS_EXCLUSION_LIST
= []
28 # TODO(mikecase): Remove this function and the constant DEVICE_DATA_DIR
29 # once all data deps are pushed to the same location on the device.
30 def _PushExtraSuiteDataDeps(device
, test_apk
):
31 """Pushes some extra data files/dirs needed by some test suite.
34 test_apk: The test suite basename for which to return file paths.
36 if test_apk
in ['ChromeTest', 'ContentShellTest']:
37 test_files
= 'net/data/ssl/certificates'
38 host_device_file_tuple
= [
39 (os
.path
.join(constants
.DIR_SOURCE_ROOT
, test_files
),
40 os
.path
.join(device
.GetExternalStoragePath(), test_files
))]
41 device
.PushChangedFiles(host_device_file_tuple
)
44 # TODO(mikecase): Remove this function once everything uses
45 # base_setup.PushDataDeps to push data deps to the device.
46 def _PushDataDeps(device
, test_options
):
47 valgrind_tools
.PushFilesForTool(test_options
.tool
, device
)
49 host_device_file_tuples
= []
50 for dest_host_pair
in test_options
.test_data
:
51 dst_src
= dest_host_pair
.split(':', 1)
52 dst_layer
= dst_src
[0]
54 host_test_files_path
= os
.path
.join(constants
.DIR_SOURCE_ROOT
, host_src
)
55 if os
.path
.exists(host_test_files_path
):
56 host_device_file_tuples
+= [(
59 device
.GetExternalStoragePath(),
62 if host_device_file_tuples
:
63 device
.PushChangedFiles(host_device_file_tuples
)
66 def Setup(test_options
, devices
):
67 """Create and return the test runner factory and tests.
70 test_options: An InstrumentationOptions object.
73 A tuple of (TestRunnerFactory, tests).
75 if (test_options
.coverage_dir
and not
76 os
.path
.exists(test_options
.coverage_dir
)):
77 os
.makedirs(test_options
.coverage_dir
)
79 test_pkg
= test_package
.TestPackage(test_options
.test_apk_path
,
80 test_options
.test_apk_jar_path
,
81 test_options
.test_support_apk_path
)
82 tests
= test_pkg
.GetAllMatchingTests(
83 test_options
.annotations
,
84 test_options
.exclude_annotations
,
85 test_options
.test_filter
)
87 logging
.error('No instrumentation tests to run with current args.')
89 if test_options
.test_data
:
90 device_utils
.DeviceUtils
.parallel(devices
).pMap(
91 _PushDataDeps
, test_options
)
93 if test_options
.isolate_file_path
:
94 base_setup
.GenerateDepsDirUsingIsolate(test_options
.test_apk
,
95 test_options
.isolate_file_path
,
98 def push_data_deps_to_device_dir(device
):
99 base_setup
.PushDataDeps(device
, device
.GetExternalStoragePath(),
101 device_utils
.DeviceUtils
.parallel(devices
).pMap(
102 push_data_deps_to_device_dir
)
104 device_utils
.DeviceUtils
.parallel(devices
).pMap(
105 _PushExtraSuiteDataDeps
, test_options
.test_apk
)
107 def TestRunnerFactory(device
, shard_index
):
108 return test_runner
.TestRunner(test_options
, device
, shard_index
,
111 return (TestRunnerFactory
, tests
)