qsr | c6c612c | 2015-01-13 22:07:48 | [diff] [blame] | 1 | # Copyright 2015 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. |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 4 | |
| 5 | # ============================================================================== |
| 6 | # TEST SETUP |
| 7 | # ============================================================================== |
| 8 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 9 | import("//build/config/chromeos/ui_mode.gni") |
Mirko Bonadei | 4a0df43 | 2020-09-08 19:06:02 | [diff] [blame] | 10 | import("//build_overrides/build.gni") |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 11 | |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 12 | if (is_android) { |
| 13 | import("//build/config/android/config.gni") |
James Cook | 209256f | 2018-12-07 18:40:50 | [diff] [blame] | 14 | import("//build/config/android/extract_unwind_tables.gni") |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 15 | import("//build/config/android/rules.gni") |
Abhishek Arya | 2f5f734 | 2018-06-13 16:59:44 | [diff] [blame] | 16 | import("//build/config/sanitizers/sanitizers.gni") |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 17 | } |
| 18 | |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 19 | if (is_fuchsia) { |
Kevin Marshall | 184e909 | 2018-02-07 21:09:06 | [diff] [blame] | 20 | import("//build/config/chromecast_build.gni") |
Kevin Marshall | 55fd852 | 2019-10-04 22:47:01 | [diff] [blame] | 21 | import("//build/config/fuchsia/generate_runner_scripts.gni") |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 22 | import("//build/config/fuchsia/package.gni") |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 23 | } |
| 24 | |
Ben Pastene | 4c35c57 | 2018-04-30 23:21:48 | [diff] [blame] | 25 | if (is_chromeos) { |
| 26 | import("//build/config/chromeos/rules.gni") |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 27 | import("//build/util/generate_wrapper.gni") |
Ben Pastene | 4c35c57 | 2018-04-30 23:21:48 | [diff] [blame] | 28 | } |
| 29 | |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 30 | if (is_ios) { |
| 31 | import("//build/config/ios/ios_sdk.gni") |
| 32 | import("//build/config/ios/ios_test_runner_wrapper.gni") |
| 33 | import("//build/config/ios/rules.gni") |
| 34 | } |
| 35 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 36 | if ((is_linux && !is_chromeos) || is_mac || is_win || |
| 37 | chromeos_is_browser_only) { |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 38 | import("//build/config/sanitizers/sanitizers.gni") |
| 39 | import("//build/util/generate_wrapper.gni") |
| 40 | } |
| 41 | |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 42 | # Define a test as an executable (or apk on Android) with the "testonly" flag |
| 43 | # set. |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 44 | # Variable: |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 45 | # use_xvfb: (optional) whether to run the executable under Xvfb. |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 46 | # use_raw_android_executable: Use executable() rather than android_apk(). |
ynovikov | 389d9e44 | 2016-05-27 02:34:56 | [diff] [blame] | 47 | # use_native_activity: Test implements ANativeActivity_onCreate(). |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 48 | # is_xctest: (iOS, optional) whether to build the executable as XCTest. |
| 49 | # Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but |
| 50 | # for build targets. |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 51 | template("test") { |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 52 | if (!is_ios) { |
| 53 | assert(!defined(invoker.is_xctest) || !invoker.is_xctest, |
| 54 | "is_xctest can be set only for iOS builds") |
| 55 | } |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 56 | if (is_android) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 57 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 58 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 59 | _use_raw_android_executable = defined(invoker.use_raw_android_executable) && |
| 60 | invoker.use_raw_android_executable |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 61 | |
agrieve | 67855de | 2016-03-30 14:46:01 | [diff] [blame] | 62 | # output_name is used to allow targets with the same name but in different |
| 63 | # packages to still produce unique runner scripts. |
| 64 | _output_name = invoker.target_name |
mikecase | 56d80d7 | 2015-06-03 00:57:26 | [diff] [blame] | 65 | if (defined(invoker.output_name)) { |
agrieve | 67855de | 2016-03-30 14:46:01 | [diff] [blame] | 66 | _output_name = invoker.output_name |
mikecase | 56d80d7 | 2015-06-03 00:57:26 | [diff] [blame] | 67 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 68 | |
agrieve | b355ad15 | 2016-04-19 03:45:23 | [diff] [blame] | 69 | _test_runner_target = "${_output_name}__test_runner_script" |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 70 | _wrapper_script_vars = [ |
agrieve | e41ae190d | 2016-04-25 14:12:51 | [diff] [blame] | 71 | "ignore_all_data_deps", |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 72 | "shard_timeout", |
agrieve | e41ae190d | 2016-04-25 14:12:51 | [diff] [blame] | 73 | ] |
agrieve | 3ac557f0 | 2016-04-12 15:52:00 | [diff] [blame] | 74 | |
jbudorick | ced2a25 | 2016-06-09 16:38:54 | [diff] [blame] | 75 | assert(_use_raw_android_executable || enable_java_templates) |
| 76 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 77 | if (_use_raw_android_executable) { |
| 78 | _exec_target = "${target_name}__exec" |
| 79 | _dist_target = "${target_name}__dist" |
| 80 | _exec_output = |
| 81 | "$target_out_dir/${invoker.target_name}/${invoker.target_name}" |
| 82 | |
| 83 | executable(_exec_target) { |
| 84 | # Configs will always be defined since we set_defaults in BUILDCONFIG.gn. |
| 85 | configs = [] |
| 86 | data_deps = [] |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 87 | forward_variables_from(invoker, |
| 88 | "*", |
| 89 | _wrapper_script_vars + [ "extra_dist_files" ]) |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 90 | testonly = true |
| 91 | |
| 92 | # Thanks to the set_defaults() for test(), configs are initialized with |
| 93 | # the default shared_library configs rather than executable configs. |
Thomas Anderson | 11c1d982 | 2019-01-15 06:32:59 | [diff] [blame] | 94 | configs -= [ |
| 95 | "//build/config:shared_library_config", |
| 96 | "//build/config/android:hide_all_but_jni", |
| 97 | ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 98 | configs += [ "//build/config:executable_config" ] |
| 99 | |
| 100 | # Don't output to the root or else conflict with the group() below. |
| 101 | output_name = rebase_path(_exec_output, root_out_dir) |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | create_native_executable_dist(_dist_target) { |
| 105 | testonly = true |
| 106 | dist_dir = "$root_out_dir/$target_name" |
| 107 | binary = _exec_output |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 108 | deps = [ ":$_exec_target" ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 109 | if (defined(invoker.extra_dist_files)) { |
| 110 | extra_files = invoker.extra_dist_files |
| 111 | } |
| 112 | } |
| 113 | } else { |
Andrew Grieve | c61b8dff | 2019-10-21 16:32:02 | [diff] [blame] | 114 | _library_target = "${target_name}__library" |
| 115 | _apk_target = "${target_name}__apk" |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 116 | _apk_specific_vars = [ |
| 117 | "android_manifest", |
agrieve | c6811b42 | 2016-06-23 02:25:09 | [diff] [blame] | 118 | "android_manifest_dep", |
Clark DuVall | 1bee532 | 2020-06-10 05:51:55 | [diff] [blame] | 119 | "app_as_shared_lib", |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 120 | "enable_multidex", |
Benoît Lizé | d8b8f74 | 2019-11-07 12:50:07 | [diff] [blame] | 121 | "product_config_java_packages", |
Tibor Goldschwendt | 95db95d | 2019-06-17 20:32:02 | [diff] [blame] | 122 | "min_sdk_version", |
huapengl | c35ba6e | 2016-05-25 23:08:07 | [diff] [blame] | 123 | "proguard_configs", |
| 124 | "proguard_enabled", |
Fred Mello | 0cc91c6 | 2019-08-24 01:53:45 | [diff] [blame] | 125 | "srcjar_deps", |
Tibor Goldschwendt | 95db95d | 2019-06-17 20:32:02 | [diff] [blame] | 126 | "target_sdk_version", |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 127 | "use_default_launcher", |
ynovikov | 389d9e44 | 2016-05-27 02:34:56 | [diff] [blame] | 128 | "use_native_activity", |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 129 | ] |
Siddhartha | 764226b | 2018-03-13 02:32:55 | [diff] [blame] | 130 | |
| 131 | # Adds the unwind tables from unstripped binary as an asset file in the |
| 132 | # apk, if |add_unwind_tables_in_apk| is specified by the test. |
| 133 | if (defined(invoker.add_unwind_tables_in_apk) && |
| 134 | invoker.add_unwind_tables_in_apk) { |
| 135 | _unwind_table_asset_name = "${target_name}_unwind_assets" |
| 136 | unwind_table_asset(_unwind_table_asset_name) { |
| 137 | testonly = true |
| 138 | library_target = _library_target |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 139 | deps = [ ":$_library_target" ] |
Siddhartha | 764226b | 2018-03-13 02:32:55 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 143 | shared_library(_library_target) { |
| 144 | # Configs will always be defined since we set_defaults in BUILDCONFIG.gn. |
| 145 | configs = [] # Prevent list overwriting warning. |
| 146 | configs = invoker.configs |
| 147 | testonly = true |
| 148 | |
| 149 | deps = [] |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 150 | forward_variables_from( |
| 151 | invoker, |
| 152 | "*", |
| 153 | _apk_specific_vars + _wrapper_script_vars + [ "visibility" ]) |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 154 | |
| 155 | if (!defined(invoker.use_default_launcher) || |
| 156 | invoker.use_default_launcher) { |
Tom Anderson | ce772fa | 2018-05-30 22:20:37 | [diff] [blame] | 157 | deps += [ "//testing/android/native_test:native_test_native_code" ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | unittest_apk(_apk_target) { |
Daniel Bratell | fdda465 | 2019-01-31 15:45:54 | [diff] [blame] | 161 | forward_variables_from(invoker, _apk_specific_vars) |
agrieve | 48bd27e | 2016-06-22 21:04:07 | [diff] [blame] | 162 | shared_library = ":$_library_target" |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 163 | apk_name = invoker.target_name |
| 164 | if (defined(invoker.output_name)) { |
| 165 | apk_name = invoker.output_name |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 166 | install_script_name = "install_${invoker.output_name}" |
| 167 | } |
agrieve | b355ad15 | 2016-04-19 03:45:23 | [diff] [blame] | 168 | |
Daniel Bratell | fdda465 | 2019-01-31 15:45:54 | [diff] [blame] | 169 | if (defined(invoker.deps)) { |
| 170 | deps = invoker.deps |
| 171 | } else { |
| 172 | deps = [] |
| 173 | } |
| 174 | |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 175 | # Add the Java classes so that each target does not have to do it. |
| 176 | deps += [ "//base/test:test_support_java" ] |
| 177 | |
Siddhartha | 764226b | 2018-03-13 02:32:55 | [diff] [blame] | 178 | if (defined(_unwind_table_asset_name)) { |
| 179 | deps += [ ":${_unwind_table_asset_name}" ] |
| 180 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 181 | } |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 182 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 183 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 184 | test_runner_script(_test_runner_target) { |
| 185 | forward_variables_from(invoker, _wrapper_script_vars) |
estevenson | ce844392 | 2016-12-15 19:57:57 | [diff] [blame] | 186 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 187 | if (_use_raw_android_executable) { |
| 188 | executable_dist_dir = "$root_out_dir/$_dist_target" |
John Budorick | d5dccb2 | 2020-02-01 02:16:34 | [diff] [blame] | 189 | data_deps = [ ":$_exec_target" ] |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 190 | } else { |
| 191 | apk_target = ":$_apk_target" |
| 192 | incremental_apk = incremental_install |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 193 | |
| 194 | # Dep needed for the test runner .runtime_deps file to pick up data |
| 195 | # deps from the forward_variables_from(invoker, "*") on the library. |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 196 | data_deps = [ ":$_library_target" ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 197 | } |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 198 | test_name = _output_name |
| 199 | test_suite = _output_name |
| 200 | test_type = "gtest" |
mikecase | 56d80d7 | 2015-06-03 00:57:26 | [diff] [blame] | 201 | } |
| 202 | |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 203 | # Create a wrapper script rather than using a group() in order to ensure |
| 204 | # "ninja $target_name" always works. If this was a group(), then GN would |
| 205 | # not create a top-level alias for it if a target exists in another |
| 206 | # directory with the same $target_name. |
| 207 | # Also - bots run this script directly for "components_perftests". |
| 208 | generate_wrapper(target_name) { |
| 209 | testonly = true |
| 210 | executable = "$root_build_dir/bin/run_$_output_name" |
| 211 | wrapper_script = "$root_build_dir/$_output_name" |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 212 | deps = [ ":$_test_runner_target" ] |
jbudorick | 686094f6 | 2017-05-04 21:52:40 | [diff] [blame] | 213 | if (_use_raw_android_executable) { |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 214 | deps += [ ":$_dist_target" ] |
jbudorick | 686094f6 | 2017-05-04 21:52:40 | [diff] [blame] | 215 | } else { |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 216 | # Dep needed for the swarming .isolate file to pick up data |
| 217 | # deps from the forward_variables_from(invoker, "*") on the library. |
| 218 | deps += [ |
| 219 | ":$_apk_target", |
| 220 | ":$_library_target", |
| 221 | ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 222 | } |
agrieve | 1a02e58 | 2015-10-15 21:35:39 | [diff] [blame] | 223 | } |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 224 | } else if (is_fuchsia) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 225 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 226 | |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 227 | _output_name = invoker.target_name |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 228 | _pkg_target = "${_output_name}_pkg" |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 229 | _exec_target = "${_output_name}__exec" |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 230 | |
Kevin Marshall | 39b4aa8 | 2018-06-23 00:12:15 | [diff] [blame] | 231 | fuchsia_package_runner(target_name) { |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 232 | testonly = true |
Dirk Pranke | d5e9a1b2 | 2020-10-28 22:52:59 | [diff] [blame] | 233 | is_test_exe = true |
Fabrice de Gans-Riberi | 041a652 | 2018-12-11 00:20:53 | [diff] [blame] | 234 | forward_variables_from(invoker, |
| 235 | [ |
| 236 | "use_test_server", |
| 237 | "package_deps", |
| 238 | ]) |
Kevin Marshall | 39b4aa8 | 2018-06-23 00:12:15 | [diff] [blame] | 239 | runner_script = "//build/fuchsia/test_runner.py" |
| 240 | package = ":$_pkg_target" |
| 241 | package_name_override = _output_name |
Dimitri Glazkov | c95e6dd | 2018-08-24 23:39:42 | [diff] [blame] | 242 | |
Wez | dd593a5 | 2020-04-08 17:09:46 | [diff] [blame] | 243 | data_deps = [ "//testing/buildbot/filters:fuchsia_filters" ] |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 244 | } |
| 245 | |
Wez | abe2d75 | 2020-02-11 17:12:23 | [diff] [blame] | 246 | cr_fuchsia_package(_pkg_target) { |
Fabrice de Gans-Riberi | a16cac8 | 2019-06-03 19:03:20 | [diff] [blame] | 247 | testonly = true |
Fabrice de Gans-Riberi | cc810d3 | 2019-07-08 22:44:16 | [diff] [blame] | 248 | forward_variables_from(invoker, [ "manifest" ]) |
Fabrice de Gans-Riberi | a16cac8 | 2019-06-03 19:03:20 | [diff] [blame] | 249 | binary = ":$_exec_target" |
| 250 | package_name_override = _output_name |
| 251 | } |
| 252 | |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 253 | executable(_exec_target) { |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 254 | forward_variables_from(invoker, "*") |
Kevin Marshall | 39b4aa8 | 2018-06-23 00:12:15 | [diff] [blame] | 255 | testonly = true |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 256 | output_name = _exec_target |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 257 | } |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 258 | } else if (is_ios) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 259 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
Mirko Bonadei | 50e251d | 2020-09-14 18:05:46 | [diff] [blame] | 260 | _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps" |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 261 | |
Rohit Rao | f9b096d | 2019-09-09 22:26:23 | [diff] [blame] | 262 | declare_args() { |
| 263 | # Keep the unittest-as-xctest functionality defaulted to off until the |
| 264 | # bots are updated to handle it properly. |
| 265 | # TODO(crbug.com/1001667): Remove this arg once the iOS test runner |
| 266 | # supports running unittests with xctest. |
| 267 | enable_run_ios_unittests_with_xctest = false |
| 268 | } |
| 269 | |
sdefresne | 01285787 | 2016-03-16 10:55:37 | [diff] [blame] | 270 | _test_target = target_name |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 271 | _wrapper_output_name = "run_${target_name}" |
| 272 | ios_test_runner_wrapper(_wrapper_output_name) { |
| 273 | forward_variables_from(invoker, |
| 274 | [ |
| 275 | "data", |
| 276 | "data_deps", |
| 277 | "deps", |
| 278 | "executable_args", |
| 279 | "retries", |
| 280 | "shards", |
| 281 | ]) |
| 282 | |
| 283 | _root_build_dir = rebase_path("${root_build_dir}", root_build_dir) |
| 284 | |
| 285 | if (!defined(executable_args)) { |
| 286 | executable_args = [] |
| 287 | } |
| 288 | executable_args += [ |
| 289 | "--app", |
| 290 | "@WrappedPath(${_root_build_dir}/${_test_target}.app)", |
| 291 | ] |
| 292 | |
| 293 | wrapper_output_name = "${_wrapper_output_name}" |
| 294 | } |
| 295 | |
sdefresne | 01285787 | 2016-03-16 10:55:37 | [diff] [blame] | 296 | _resources_bundle_data = target_name + "_resources_bundle_data" |
| 297 | |
| 298 | bundle_data(_resources_bundle_data) { |
sdefresne | 047490e | 2016-07-22 08:49:34 | [diff] [blame] | 299 | visibility = [ ":$_test_target" ] |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 300 | sources = [ "//testing/gtest_ios/Default.png" ] |
| 301 | outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 302 | } |
| 303 | |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 304 | force_xctest = enable_run_ios_unittests_with_xctest || |
| 305 | (defined(invoker.is_xctest) && invoker.is_xctest) |
| 306 | |
| 307 | if (force_xctest) { |
Rohit Rao | f9b096d | 2019-09-09 22:26:23 | [diff] [blame] | 308 | ios_test_target_type = "ios_xctest_test" |
| 309 | } else { |
| 310 | ios_test_target_type = "ios_app_bundle" |
| 311 | } |
| 312 | |
| 313 | target(ios_test_target_type, _test_target) { |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 314 | testonly = true |
sdefresne | a828c28 | 2016-05-30 18:04:20 | [diff] [blame] | 315 | |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 316 | if (force_xctest && build_with_chromium) { |
Rohit Rao | f9b096d | 2019-09-09 22:26:23 | [diff] [blame] | 317 | xctest_module_target = "//base/test:google_test_runner" |
| 318 | } |
| 319 | |
sdefresne | 9e147e0 | 2016-06-07 00:10:13 | [diff] [blame] | 320 | forward_variables_from(invoker, "*", [ "testonly" ]) |
| 321 | |
| 322 | # Provide sensible defaults in case invoker did not define any of those |
| 323 | # required variables. |
sdefresne | 05b97ca | 2016-06-08 07:19:46 | [diff] [blame] | 324 | if (!defined(info_plist) && !defined(info_plist_target)) { |
sdefresne | 9e147e0 | 2016-06-07 00:10:13 | [diff] [blame] | 325 | info_plist = "//testing/gtest_ios/unittest-Info.plist" |
| 326 | } |
sdefresne | 9e147e0 | 2016-06-07 00:10:13 | [diff] [blame] | 327 | |
Olivier Robin | 9689c56 | 2020-04-17 14:03:57 | [diff] [blame] | 328 | _gtest_bundle_id_suffix = "${target_name}" |
| 329 | xcode_product_bundle_id = "gtest.$_gtest_bundle_id_suffix" |
Justin Cohen | a819c11 | 2019-08-17 02:19:19 | [diff] [blame] | 330 | |
sdefresne | 9e147e0 | 2016-06-07 00:10:13 | [diff] [blame] | 331 | if (!defined(extra_substitutions)) { |
| 332 | extra_substitutions = [] |
| 333 | } |
Olivier Robin | 9689c56 | 2020-04-17 14:03:57 | [diff] [blame] | 334 | extra_substitutions += |
| 335 | [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ] |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 336 | |
sdefresne | 047490e | 2016-07-22 08:49:34 | [diff] [blame] | 337 | if (!defined(bundle_deps)) { |
| 338 | bundle_deps = [] |
| 339 | } |
| 340 | bundle_deps += [ ":$_resources_bundle_data" ] |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 341 | |
| 342 | if (!defined(data_deps)) { |
| 343 | data_deps = [] |
| 344 | } |
| 345 | |
| 346 | # Include the generate_wrapper as part of data_deps |
| 347 | data_deps += [ ":${_wrapper_output_name}" ] |
Mirko Bonadei | 50e251d | 2020-09-14 18:05:46 | [diff] [blame] | 348 | write_runtime_deps = _runtime_deps_file |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 349 | } |
George Burgess IV | e62d7c5 | 2020-02-22 01:22:42 | [diff] [blame] | 350 | } else if (is_chromeos && cros_board != "") { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 351 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 352 | |
Ben Pastene | 1688203 | 2018-09-21 01:16:39 | [diff] [blame] | 353 | # Building for a cros board (ie: not linux-chromeos). |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 354 | |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 355 | _gen_runner_target = "${target_name}__runner" |
| 356 | _runtime_deps_file = |
| 357 | "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") + |
| 358 | "/" + get_label_info(target_name, "name") + ".runtime_deps" |
| 359 | |
Ben Pastene | 4ab9865 | 2018-12-17 18:33:18 | [diff] [blame] | 360 | generate_runner_script(_gen_runner_target) { |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 361 | testonly = true |
| 362 | generated_script = "$root_build_dir/bin/run_" + invoker.target_name |
Ben Pastene | 1688203 | 2018-09-21 01:16:39 | [diff] [blame] | 363 | test_exe = invoker.target_name |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 364 | runtime_deps_file = _runtime_deps_file |
| 365 | } |
| 366 | |
| 367 | executable(target_name) { |
| 368 | forward_variables_from(invoker, "*") |
| 369 | if (!defined(deps)) { |
| 370 | deps = [] |
| 371 | } |
| 372 | if (!defined(data)) { |
| 373 | data = [] |
| 374 | } |
| 375 | |
Ben Pastene | 4104178 | 2019-02-16 04:21:58 | [diff] [blame] | 376 | # We use a special trigger script for CrOS hardware tests. |
| 377 | data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ] |
| 378 | |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 379 | testonly = true |
| 380 | output_name = target_name |
| 381 | write_runtime_deps = _runtime_deps_file |
| 382 | data += [ _runtime_deps_file ] |
Tom Anderson | ce772fa | 2018-05-30 22:20:37 | [diff] [blame] | 383 | deps += [ ":$_gen_runner_target" ] |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 384 | } |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 385 | } else if (is_chromeos && cros_board == "") { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 386 | # TODO(crbug.com/816629) - Make use_xvfb work right in this situation. |
| 387 | not_needed([ "use_xvfb" ]) |
Dirk Pranke | 956c4dc | 2020-07-02 00:54:27 | [diff] [blame] | 388 | executable(target_name) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 389 | forward_variables_from(invoker, "*", [ "use_xvfb" ]) |
Dirk Pranke | 956c4dc | 2020-07-02 00:54:27 | [diff] [blame] | 390 | if (!defined(deps)) { |
| 391 | deps = [] |
| 392 | } |
| 393 | |
Dirk Pranke | 956c4dc | 2020-07-02 00:54:27 | [diff] [blame] | 394 | testonly = true |
Dirk Pranke | 956c4dc | 2020-07-02 00:54:27 | [diff] [blame] | 395 | } |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 396 | } else if (chromeos_is_browser_only) { |
| 397 | _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps" |
| 398 | _executable = target_name |
| 399 | _gen_runner_target = "${target_name}__runner" |
| 400 | |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 401 | if (defined(invoker.use_xvfb)) { |
| 402 | _use_xvfb = invoker.use_xvfb |
| 403 | } else { |
| 404 | _use_xvfb = false |
| 405 | } |
| 406 | |
Yuke Liao | d037abc | 2020-10-06 22:48:22 | [diff] [blame] | 407 | # When use_xvfb is set by the invoker, it indicates that running this test |
| 408 | # target requires a window, and in lacros build, ash-chrome serves as the |
| 409 | # display server. Note that even though the tests themselves do not require |
| 410 | # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner |
| 411 | # because ash-chrome is based on x11. |
| 412 | _use_ash_chrome = _use_xvfb |
| 413 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 414 | generate_wrapper(_gen_runner_target) { |
| 415 | testonly = true |
| 416 | wrapper_script = "$root_build_dir/bin/run_" + _executable |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 417 | |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 418 | data = [] |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 419 | if (_use_xvfb) { |
| 420 | executable = "//testing/xvfb.py" |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 421 | data += [ "//testing/xvfb.py" ] |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 422 | } else { |
| 423 | executable = "//testing/test_env.py" |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 424 | data += [ "//testing/test_env.py" ] |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 425 | } |
| 426 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 427 | executable_args = [ |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 428 | "@WrappedPath(../../build/lacros/test_runner.py)", |
Yuke Liao | 240816d | 2020-07-22 00:10:39 | [diff] [blame] | 429 | "test", |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 430 | "@WrappedPath(./${_executable})", |
| 431 | "--test-launcher-bot-mode", |
| 432 | ] |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 433 | |
Yuke Liao | f540c74 | 2020-07-29 16:28:34 | [diff] [blame] | 434 | if (_use_ash_chrome) { |
Yuke Liao | 8348aa4 | 2020-11-04 19:35:23 | [diff] [blame] | 435 | executable_args += [ "--ash-chrome-path=ash_clang_x64/chrome" ] |
Yuke Liao | 240816d | 2020-07-22 00:10:39 | [diff] [blame] | 436 | } |
| 437 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 438 | if (is_asan) { |
| 439 | executable_args += [ "--asan=true" ] |
| 440 | } |
| 441 | if (is_msan) { |
| 442 | executable_args += [ "--msan=true" ] |
| 443 | } |
| 444 | if (is_tsan) { |
| 445 | executable_args += [ "--tsan=true" ] |
| 446 | } |
| 447 | if (use_cfi_diag) { |
| 448 | executable_args += [ "--cfi-diag=true" ] |
| 449 | } |
| 450 | |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 451 | data += [ |
Yuke Liao | 240816d | 2020-07-22 00:10:39 | [diff] [blame] | 452 | "//build/lacros/test_runner.py", |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 453 | "//.vpython", |
| 454 | ] |
| 455 | } |
| 456 | |
| 457 | executable(target_name) { |
| 458 | forward_variables_from(invoker, "*") |
| 459 | if (!defined(deps)) { |
| 460 | deps = [] |
| 461 | } |
| 462 | |
Yuke Liao | d037abc | 2020-10-06 22:48:22 | [diff] [blame] | 463 | if (!defined(data_deps)) { |
| 464 | data_deps = [] |
| 465 | } |
| 466 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 467 | testonly = true |
| 468 | write_runtime_deps = _runtime_deps_file |
| 469 | deps += [ ":$_gen_runner_target" ] |
Yuke Liao | d037abc | 2020-10-06 22:48:22 | [diff] [blame] | 470 | if (_use_ash_chrome && also_build_ash_chrome) { |
| 471 | data_deps += |
| 472 | [ "//chrome:chrome(//build/toolchain/linux:ash_clang_x64)" ] |
| 473 | } |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 474 | } |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 475 | } else { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 476 | if (is_mac || is_win) { |
| 477 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 478 | } |
| 479 | |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 480 | if ((is_linux && !is_chromeos) || is_mac || is_win) { |
| 481 | _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps" |
| 482 | _executable = target_name |
| 483 | _gen_runner_target = "${target_name}__runner" |
| 484 | |
Sean McAllister | 88fbd90 | 2020-07-30 19:27:03 | [diff] [blame] | 485 | if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) { |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 486 | _use_xvfb = invoker.use_xvfb |
| 487 | } else { |
| 488 | _use_xvfb = false |
| 489 | } |
| 490 | |
| 491 | generate_wrapper(_gen_runner_target) { |
| 492 | testonly = true |
| 493 | wrapper_script = "$root_build_dir/bin/run_" + _executable |
| 494 | |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 495 | data = [] |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 496 | if (_use_xvfb) { |
| 497 | executable = "//testing/xvfb.py" |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 498 | data += [ "//testing/xvfb.py" ] |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 499 | } else { |
| 500 | executable = "//testing/test_env.py" |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 501 | data += [ "//testing/test_env.py" ] |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | executable_args = [ |
| 505 | "@WrappedPath(./${_executable})", |
| 506 | "--test-launcher-bot-mode", |
| 507 | ] |
| 508 | if (is_asan) { |
| 509 | executable_args += [ "--asan=true" ] |
| 510 | } |
| 511 | if (is_msan) { |
| 512 | executable_args += [ "--msan=true" ] |
| 513 | } |
| 514 | if (is_tsan) { |
| 515 | executable_args += [ "--tsan=true" ] |
| 516 | } |
| 517 | if (use_cfi_diag) { |
| 518 | executable_args += [ "--cfi-diag=true" ] |
| 519 | } |
| 520 | |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 521 | data += [ "//.vpython" ] |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | executable(target_name) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 526 | forward_variables_from(invoker, "*", [ "use_xvfb" ]) |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 527 | if (!defined(deps)) { |
| 528 | deps = [] |
| 529 | } |
| 530 | |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 531 | testonly = true |
| 532 | deps += [ |
| 533 | # Give tests the default manifest on Windows (a no-op elsewhere). |
| 534 | "//build/win:default_exe_manifest", |
| 535 | ] |
| 536 | |
Sean McAllister | 88fbd90 | 2020-07-30 19:27:03 | [diff] [blame] | 537 | if (is_linux || is_chromeos || is_mac || is_win) { |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 538 | write_runtime_deps = _runtime_deps_file |
| 539 | deps += [ ":$_gen_runner_target" ] |
| 540 | } |
| 541 | } |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 542 | } |
| 543 | } |
brettw | edb6ecc | 2016-07-14 23:37:03 | [diff] [blame] | 544 | |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 545 | # Defines a type of test that invokes a script to run, rather than |
| 546 | # invoking an executable. |
| 547 | # |
| 548 | # The script must implement the |
| 549 | # [test executable API](//docs/testing/test_executable_api.md). |
| 550 | # |
| 551 | # The template must be passed the `script` parameter, which specifies |
| 552 | # the path to the script to run. It may optionally be passed a |
| 553 | # `script_args` parameter, which can be used to include a list of |
| 554 | # args to be specified by default. The template will produce |
| 555 | # a `$root_build_dir/run_$target_name` wrapper and write the runtime_deps |
| 556 | # for the target to $root_build_dir/${target_name}.runtime_deps, as per |
| 557 | # the conventions listed in the |
| 558 | # [test wrapper API](//docs/testing/test_wrapper_api.md). |
| 559 | template("script_test") { |
| 560 | generate_wrapper(target_name) { |
| 561 | testonly = true |
| 562 | wrapper_script = "${root_build_dir}/bin/run_${target_name}" |
| 563 | |
| 564 | executable = "//testing/test_env.py" |
| 565 | |
| 566 | executable_args = |
| 567 | [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ] |
| 568 | if (defined(invoker.args)) { |
| 569 | executable_args += invoker.args |
| 570 | } |
| 571 | |
| 572 | data = [ |
| 573 | "//.vpython", |
| 574 | "//testing/test_env.py", |
| 575 | |
| 576 | # These aren't needed by *every* test, but they're likely needed often |
| 577 | # enough to just make it easier to declare them here. |
| 578 | "//testing/xvfb.py", |
| 579 | "//testing/scripts/common.py", |
| 580 | |
| 581 | invoker.script, |
| 582 | ] |
| 583 | if (defined(invoker.data)) { |
| 584 | data += invoker.data |
| 585 | } |
| 586 | data_deps = [] |
| 587 | if (defined(invoker.data_deps)) { |
| 588 | data_deps += invoker.data_deps |
| 589 | } |
| 590 | |
| 591 | forward_variables_from(invoker, |
| 592 | [ "*" ], |
| 593 | [ |
| 594 | "data", |
| 595 | "data_deps", |
| 596 | "script", |
| 597 | "script_args", |
| 598 | "testonly", |
| 599 | ]) |
| 600 | |
| 601 | write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps" |
| 602 | } |
| 603 | } |
| 604 | |
brettw | edb6ecc | 2016-07-14 23:37:03 | [diff] [blame] | 605 | # Test defaults. |
| 606 | set_defaults("test") { |
| 607 | if (is_android) { |
| 608 | configs = default_shared_library_configs |
Yipeng Wang | 158dbc5c | 2017-06-30 18:16:41 | [diff] [blame] | 609 | configs -= [ "//build/config/android:hide_all_but_jni_onload" ] |
Thomas Anderson | 11c1d982 | 2019-01-15 06:32:59 | [diff] [blame] | 610 | configs += [ "//build/config/android:hide_all_but_jni" ] |
brettw | edb6ecc | 2016-07-14 23:37:03 | [diff] [blame] | 611 | } else { |
| 612 | configs = default_executable_configs |
| 613 | } |
| 614 | } |