dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [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. |
| 4 | |
| 5 | # ============================================================================== |
| 6 | # TEST SETUP |
| 7 | # ============================================================================== |
| 8 | |
| 9 | # Define a test as an executable (or apk on Android) with the "testonly" flag |
| 10 | # set. |
| 11 | # Variable: |
| 12 | # use_raw_android_executable: Use executable() rather than android_apk(). |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 13 | # use_native_activity: Test implements ANativeActivity_onCreate(). |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 14 | template("test") { |
| 15 | if (is_android) { |
| 16 | import("//build/config/android/config.gni") |
| 17 | import("//build/config/android/rules.gni") |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 18 | import("//build/config/sanitizers/sanitizers.gni") |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 19 | |
| 20 | _use_raw_android_executable = defined(invoker.use_raw_android_executable) && |
| 21 | invoker.use_raw_android_executable |
| 22 | |
| 23 | # output_name is used to allow targets with the same name but in different |
| 24 | # packages to still produce unique runner scripts. |
| 25 | _output_name = invoker.target_name |
| 26 | if (defined(invoker.output_name)) { |
| 27 | _output_name = invoker.output_name |
| 28 | } |
| 29 | |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 30 | _test_runner_target = "${_output_name}__test_runner_script" |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 31 | _wrapper_script_vars = [ |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 32 | "ignore_all_data_deps", |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 33 | "shard_timeout", |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 34 | ] |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 35 | |
| 36 | assert(_use_raw_android_executable || enable_java_templates) |
| 37 | |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 38 | if (_use_raw_android_executable) { |
| 39 | _exec_target = "${target_name}__exec" |
| 40 | _dist_target = "${target_name}__dist" |
| 41 | _exec_output = |
| 42 | "$target_out_dir/${invoker.target_name}/${invoker.target_name}" |
| 43 | |
| 44 | executable(_exec_target) { |
| 45 | # Configs will always be defined since we set_defaults in BUILDCONFIG.gn. |
| 46 | configs = [] |
| 47 | data_deps = [] |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 48 | forward_variables_from(invoker, |
| 49 | "*", |
| 50 | _wrapper_script_vars + [ "extra_dist_files" ]) |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 51 | testonly = true |
| 52 | |
| 53 | # Thanks to the set_defaults() for test(), configs are initialized with |
| 54 | # the default shared_library configs rather than executable configs. |
| 55 | configs -= [ |
| 56 | "//build/config:shared_library_config", |
| 57 | "//build/config/android:hide_native_jni_exports", |
| 58 | ] |
| 59 | configs += [ "//build/config:executable_config" ] |
| 60 | |
| 61 | # Don't output to the root or else conflict with the group() below. |
| 62 | output_name = rebase_path(_exec_output, root_out_dir) |
| 63 | if (is_component_build || is_asan) { |
| 64 | data_deps += [ "//build/android:cpplib_stripped" ] |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | create_native_executable_dist(_dist_target) { |
| 69 | testonly = true |
| 70 | dist_dir = "$root_out_dir/$target_name" |
| 71 | binary = _exec_output |
| 72 | deps = [ |
| 73 | ":$_exec_target", |
| 74 | ] |
| 75 | if (defined(invoker.extra_dist_files)) { |
| 76 | extra_files = invoker.extra_dist_files |
| 77 | } |
| 78 | } |
| 79 | } else { |
| 80 | _library_target = "_${target_name}__library" |
| 81 | _apk_target = "${target_name}_apk" |
| 82 | _apk_specific_vars = [ |
| 83 | "android_manifest", |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 84 | "android_manifest_dep", |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 85 | "enable_multidex", |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 86 | "proguard_configs", |
| 87 | "proguard_enabled", |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 88 | "use_default_launcher", |
| 89 | "write_asset_list", |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 90 | "use_native_activity", |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 91 | ] |
| 92 | shared_library(_library_target) { |
| 93 | # Configs will always be defined since we set_defaults in BUILDCONFIG.gn. |
| 94 | configs = [] # Prevent list overwriting warning. |
| 95 | configs = invoker.configs |
| 96 | testonly = true |
| 97 | |
| 98 | deps = [] |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 99 | forward_variables_from( |
| 100 | invoker, |
| 101 | "*", |
| 102 | _apk_specific_vars + _wrapper_script_vars + [ "visibility" ]) |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 103 | |
| 104 | if (!defined(invoker.use_default_launcher) || |
| 105 | invoker.use_default_launcher) { |
| 106 | deps += [ "//testing/android/native_test:native_test_native_code" ] |
| 107 | } |
| 108 | } |
| 109 | unittest_apk(_apk_target) { |
| 110 | forward_variables_from(invoker, _apk_specific_vars + [ "deps" ]) |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 111 | shared_library = ":$_library_target" |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 112 | apk_name = invoker.target_name |
| 113 | if (defined(invoker.output_name)) { |
| 114 | apk_name = invoker.output_name |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 115 | install_script_name = "install_${invoker.output_name}" |
| 116 | } |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 117 | |
| 118 | # TODO(agrieve): Remove this data_dep once bots don't build the _apk |
| 119 | # target (post-GYP). |
| 120 | # It's a bit backwards for the apk to depend on the runner script, since |
| 121 | # the apk is conceptually a runtime_dep of the script. However, it is |
| 122 | # currently necessary because the bots build this _apk target directly |
| 123 | # rather than the group() below. |
| 124 | data_deps = [ |
| 125 | ":$_test_runner_target", |
| 126 | ] |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | # Incremental test targets work only for .apks. |
| 130 | _incremental_test_runner_target = |
| 131 | "${_output_name}_incremental__test_runner_script" |
| 132 | test_runner_script(_incremental_test_runner_target) { |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 133 | forward_variables_from(invoker, |
| 134 | _wrapper_script_vars + [ |
| 135 | "data", |
| 136 | "data_deps", |
| 137 | "deps", |
| 138 | "public_deps", |
| 139 | ]) |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 140 | apk_target = ":$_apk_target" |
| 141 | test_name = "${_output_name}_incremental" |
| 142 | test_type = "gtest" |
| 143 | test_suite = _output_name |
| 144 | incremental_install = true |
| 145 | } |
| 146 | group("${target_name}_incremental") { |
| 147 | testonly = true |
| 148 | datadeps = [ |
| 149 | ":$_incremental_test_runner_target", |
| 150 | ] |
| 151 | deps = [ |
| 152 | ":${_apk_target}_incremental", |
| 153 | ] |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | _test_runner_target = "${_output_name}__test_runner_script" |
| 158 | test_runner_script(_test_runner_target) { |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 159 | forward_variables_from(invoker, |
| 160 | _wrapper_script_vars + [ |
| 161 | "data", |
| 162 | "data_deps", |
| 163 | "deps", |
| 164 | "public_deps", |
| 165 | ]) |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 166 | |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 167 | if (_use_raw_android_executable) { |
| 168 | executable_dist_dir = "$root_out_dir/$_dist_target" |
| 169 | } else { |
| 170 | apk_target = ":$_apk_target" |
| 171 | } |
| 172 | test_name = _output_name |
| 173 | test_type = "gtest" |
| 174 | test_suite = _output_name |
| 175 | } |
| 176 | |
| 177 | group(target_name) { |
| 178 | testonly = true |
| 179 | deps = [ |
| 180 | ":$_test_runner_target", |
| 181 | ] |
| 182 | if (_use_raw_android_executable) { |
| 183 | deps += [ ":$_dist_target" ] |
| 184 | } else { |
| 185 | deps += [ ":$_apk_target" ] |
| 186 | } |
| 187 | } |
| 188 | |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 189 | # TODO(GYP_GONE): Delete this after we've converted everything to GN. |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 190 | # The _run targets exist only for compatibility w/ GYP. |
| 191 | group("${target_name}_apk_run") { |
| 192 | testonly = true |
| 193 | deps = [ |
| 194 | ":${invoker.target_name}", |
| 195 | ] |
| 196 | } |
| 197 | } else if (is_ios) { |
| 198 | import("//build/config/ios/rules.gni") |
| 199 | |
| 200 | _test_target = target_name |
| 201 | _resources_bundle_data = target_name + "_resources_bundle_data" |
| 202 | |
| 203 | bundle_data(_resources_bundle_data) { |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 204 | visibility = [ ":$_test_target" ] |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 205 | sources = [ |
| 206 | "//testing/gtest_ios/Default.png", |
| 207 | ] |
| 208 | outputs = [ |
| 209 | "{{bundle_resources_dir}}/{{source_file_part}}", |
| 210 | ] |
| 211 | } |
| 212 | |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 213 | ios_app_bundle(_test_target) { |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 214 | testonly = true |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 215 | |
| 216 | # See above call. |
| 217 | set_sources_assignment_filter([]) |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 218 | forward_variables_from(invoker, "*", [ "testonly" ]) |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 219 | |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 220 | # Provide sensible defaults in case invoker did not define any of those |
| 221 | # required variables. |
| 222 | if (!defined(info_plist) && !defined(info_plist_target)) { |
| 223 | info_plist = "//testing/gtest_ios/unittest-Info.plist" |
| 224 | } |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 225 | |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 226 | _bundle_id_suffix = target_name |
| 227 | if (ios_automatically_manage_certs) { |
| 228 | # Use the same bundle identifier for all unit tests when managing |
| 229 | # certificates automatically as the number of free certs is limited. |
| 230 | _bundle_id_suffix = "generic-unit-test" |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 231 | } |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 232 | if (!defined(extra_substitutions)) { |
| 233 | extra_substitutions = [] |
| 234 | } |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 235 | extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ] |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 236 | |
| 237 | if (!defined(deps)) { |
| 238 | deps = [] |
| 239 | } |
| 240 | deps += [ |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 241 | # All shared libraries must have the sanitizer deps to properly link in |
| 242 | # asan mode (this target will be empty in other cases). |
| 243 | "//build/config/sanitizers:deps", |
| 244 | ] |
jbudorick | f6ee820 | 2016-12-05 06:50:50 -0800 | [diff] [blame^] | 245 | if (!defined(bundle_deps)) { |
| 246 | bundle_deps = [] |
| 247 | } |
| 248 | bundle_deps += [ ":$_resources_bundle_data" ] |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 249 | } |
| 250 | } else { |
| 251 | executable(target_name) { |
| 252 | deps = [] |
| 253 | forward_variables_from(invoker, "*") |
| 254 | |
| 255 | testonly = true |
| 256 | deps += [ |
| 257 | # All shared libraries must have the sanitizer deps to properly link in |
| 258 | # asan mode (this target will be empty in other cases). |
| 259 | "//build/config/sanitizers:deps", |
| 260 | |
| 261 | # Give tests the default manifest on Windows (a no-op elsewhere). |
| 262 | "//build/win:default_exe_manifest", |
| 263 | ] |
| 264 | } |
| 265 | |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 266 | # TODO(GYP_GONE): Delete this after we've converted everything to GN. |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 267 | # The _run targets exist only for compatibility with GYP. |
| 268 | group("${target_name}_run") { |
| 269 | testonly = true |
| 270 | deps = [ |
| 271 | ":${invoker.target_name}", |
| 272 | ] |
| 273 | } |
jbudorick | 7f3a15f | 2016-06-10 06:28:40 -0700 | [diff] [blame] | 274 | |
| 275 | if (defined(invoker.output_name) && target_name != invoker.output_name) { |
| 276 | group("${invoker.output_name}_run") { |
| 277 | testonly = true |
| 278 | deps = [ |
| 279 | ":${invoker.target_name}", |
| 280 | ] |
| 281 | } |
| 282 | } |
dsinclair | 685bb88 | 2016-04-20 07:32:39 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
thestig | c65e11e | 2016-08-30 21:56:33 -0700 | [diff] [blame] | 285 | |
| 286 | # Test defaults. |
| 287 | set_defaults("test") { |
| 288 | if (is_android) { |
| 289 | configs = default_shared_library_configs |
| 290 | } else { |
| 291 | configs = default_executable_configs |
| 292 | } |
| 293 | } |