Avi Drissman | dfd88085 | 2022-09-15 20:11:09 | [diff] [blame] | 1 | # Copyright 2015 The Chromium Authors |
qsr | c6c612c | 2015-01-13 22:07:48 | [diff] [blame] | 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 | 2a9b2f0e | 2021-04-16 00:40:11 | [diff] [blame] | 9 | import("//build/config/chromeos/args.gni") |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 10 | import("//build/config/chromeos/ui_mode.gni") |
Kevin Marshall | 36c602c | 2021-11-04 16:16:21 | [diff] [blame] | 11 | import("//build/config/devtools.gni") |
Dirk Pranke | b404c3b | 2021-06-14 19:57:50 | [diff] [blame] | 12 | import("//build/config/gclient_args.gni") |
Greg Guterman | 28b3cba | 2021-05-12 22:21:03 | [diff] [blame] | 13 | import("//build/config/rts.gni") |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 14 | import("//build/rust/rust_static_library.gni") |
Mirko Bonadei | 4a0df43 | 2020-09-08 19:06:02 | [diff] [blame] | 15 | import("//build_overrides/build.gni") |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 16 | |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 17 | declare_args() { |
Dirk Pranke | b404c3b | 2021-06-14 19:57:50 | [diff] [blame] | 18 | # Some component repos (e.g. ANGLE) import //testing but do not have |
| 19 | # "location_tags.json", and so we don't want to try and upload the tags |
| 20 | # for their tests. |
| 21 | # And, some build configs may simply turn off generation altogether. |
| 22 | tests_have_location_tags = generate_location_tags |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 23 | } |
| 24 | |
David Dorwin | 621c507 | 2022-03-30 00:32:53 | [diff] [blame] | 25 | # On Fuchsia, the test executable has a suffix and is a dependency of the |
| 26 | # common |target_name| target. For `visibility`, the executable must be |
| 27 | # specified. Cross-platform targets that include `test` targets in their |
| 28 | # visibility lists, add `${exec_target_suffix}` immediately after the test |
| 29 | # target name. This is not necessary when the target is a `source_set`. |
| 30 | if (is_fuchsia) { |
| 31 | exec_target_suffix = "__exec" |
| 32 | } else { |
| 33 | exec_target_suffix = "" |
| 34 | } |
| 35 | |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 36 | if (is_android) { |
| 37 | import("//build/config/android/config.gni") |
Charlie Hu | d98dc69 | 2021-12-08 01:01:02 | [diff] [blame] | 38 | import("//build/config/android/create_unwind_table.gni") |
James Cook | 209256f | 2018-12-07 18:40:50 | [diff] [blame] | 39 | import("//build/config/android/extract_unwind_tables.gni") |
Sam Maier | 7acb8d6b | 2023-05-15 14:00:22 | [diff] [blame^] | 40 | import("//build/config/android/jni.gni") |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 41 | import("//build/config/android/rules.gni") |
Abhishek Arya | 2f5f734 | 2018-06-13 16:59:44 | [diff] [blame] | 42 | import("//build/config/sanitizers/sanitizers.gni") |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 43 | } else if (is_fuchsia) { |
Kevin Marshall | 184e909 | 2018-02-07 21:09:06 | [diff] [blame] | 44 | import("//build/config/chromecast_build.gni") |
Kevin Marshall | 55fd852 | 2019-10-04 22:47:01 | [diff] [blame] | 45 | import("//build/config/fuchsia/generate_runner_scripts.gni") |
Chong Gu | 26908f4e | 2021-01-29 03:13:07 | [diff] [blame] | 46 | import("//third_party/fuchsia-sdk/sdk/build/cmc.gni") |
Greg Thompson | 76d83b4 | 2022-09-15 14:30:35 | [diff] [blame] | 47 | import("//third_party/fuchsia-sdk/sdk/build/component.gni") |
| 48 | import("//third_party/fuchsia-sdk/sdk/build/package.gni") |
Nico Weber | d73c9038 | 2022-03-30 20:37:50 | [diff] [blame] | 49 | } else if (is_chromeos && is_chromeos_device) { |
Ben Pastene | 4c35c57 | 2018-04-30 23:21:48 | [diff] [blame] | 50 | import("//build/config/chromeos/rules.gni") |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 51 | import("//build/config/sanitizers/sanitizers.gni") |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 52 | import("//build/util/generate_wrapper.gni") |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 53 | } else if (is_ios) { |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 54 | import("//build/config/ios/ios_sdk.gni") |
| 55 | import("//build/config/ios/ios_test_runner_wrapper.gni") |
| 56 | import("//build/config/ios/rules.gni") |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 57 | } else { |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 58 | import("//build/config/sanitizers/sanitizers.gni") |
| 59 | import("//build/util/generate_wrapper.gni") |
| 60 | } |
| 61 | |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 62 | # This template generates the test target (of type `target_type`) but also |
| 63 | # generates a rust library that includes all .rs files found in sources and |
| 64 | # depends on that from the test target. |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 65 | template("mixed_test") { |
| 66 | assert(defined(invoker.target_type) && invoker.target_type != "") |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 67 | |
danakj | ca3cae6 | 2023-04-12 15:20:57 | [diff] [blame] | 68 | # The crate_root variable would transform the target into a Rust binary |
| 69 | # which is incorrect. To not use a generated crate root set: |
| 70 | # ``` |
| 71 | # test_crate_root = "path/to/root.rs" |
| 72 | # ``` |
| 73 | assert(!defined(invoker.crate_root)) |
| 74 | |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 75 | _rs_vars = [ |
| 76 | "sources", # We split this list into two. |
| 77 | "crate_name", # Android test template overrides the crate name. |
| 78 | ] |
danakj | aa85aad | 2022-03-10 18:45:10 | [diff] [blame] | 79 | |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 80 | if (defined(invoker.sources)) { |
| 81 | _rs_sources = filter_include(invoker.sources, [ "*.rs" ]) |
| 82 | _cc_sources = filter_exclude(invoker.sources, [ "*.rs" ]) |
| 83 | } else { |
| 84 | _rs_sources = [] |
| 85 | _cc_sources = [] |
| 86 | } |
| 87 | |
| 88 | if (_rs_sources != []) { |
danakj | c858ce7 | 2022-12-20 21:39:51 | [diff] [blame] | 89 | if (defined(invoker.crate_name)) { |
| 90 | _rust_target_name = "${invoker.crate_name}_rust_objects" |
| 91 | } else { |
| 92 | _rust_target_name = "${target_name}_rust_objects" |
| 93 | } |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 94 | |
| 95 | # We could automatically add `deps += [ "//testing/rust_gtest_interop" ]` |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 96 | # if `rs_sources` is non-empty. But we don't automatically provide |
| 97 | # //testing/gtest either so it would be asymmetric and could break in that |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 98 | # case. So, we act instead as if //testing/rust_gtest_interop is part of |
| 99 | # the //testing/gtest dependency. If you add one, and have `rs_sources` |
| 100 | # listed, you get both. |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 101 | _gtest_is_in_deps = false |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 102 | if (defined(invoker.deps) && invoker.deps != []) { |
| 103 | foreach(dep, invoker.deps) { |
danakj | c1f000c | 2022-11-18 19:31:06 | [diff] [blame] | 104 | if (get_label_info(dep, "label_no_toolchain") == |
| 105 | "//testing/gtest:gtest") { |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 106 | _gtest_is_in_deps = true |
| 107 | } |
| 108 | } |
| 109 | } |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 110 | |
| 111 | # TODO(danakj): This could be a rust_source_set perhaps, the point being |
| 112 | # that we need to link in all the .o object files inside the library, |
| 113 | # instead of dropping unreachable ones during linking (which would drop the |
| 114 | # tests). Alternatively we could use a special name suffix or other similar |
| 115 | # trick perhaps to ensure that all object files are linked in here. |
| 116 | rust_static_library(_rust_target_name) { |
| 117 | forward_variables_from(invoker, |
| 118 | TESTONLY_AND_VISIBILITY + [ |
danakj | ca3cae6 | 2023-04-12 15:20:57 | [diff] [blame] | 119 | "allow_unsafe", |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 120 | "deps", |
danakj | ca3cae6 | 2023-04-12 15:20:57 | [diff] [blame] | 121 | "generate_crate_root", |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 122 | "public_deps", |
| 123 | ]) |
| 124 | configs += [ "//build/rust:test" ] |
danakj | ca3cae6 | 2023-04-12 15:20:57 | [diff] [blame] | 125 | if (defined(invoker.test_crate_root)) { |
| 126 | crate_root = invoker.test_crate_root |
| 127 | } else { |
| 128 | generate_crate_root = true |
| 129 | } |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 130 | sources = _rs_sources |
danakj | ca3cae6 | 2023-04-12 15:20:57 | [diff] [blame] | 131 | |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 132 | if (_gtest_is_in_deps) { |
| 133 | deps += [ "//testing/rust_gtest_interop" ] |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 134 | } |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 135 | } |
| 136 | } else { |
| 137 | not_needed(invoker, _rs_vars) |
| 138 | } |
| 139 | |
| 140 | target(invoker.target_type, target_name) { |
| 141 | forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + _rs_vars) |
| 142 | forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) |
| 143 | sources = _cc_sources |
| 144 | if (!defined(deps)) { |
| 145 | deps = [] |
| 146 | } |
danakj | ca3cae6 | 2023-04-12 15:20:57 | [diff] [blame] | 147 | if (!defined(ldflags)) { |
| 148 | ldflags = [] |
| 149 | } |
| 150 | |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 151 | if (_rs_sources != []) { |
| 152 | deps += [ ":${_rust_target_name}" ] |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 153 | } |
danakj | ca3cae6 | 2023-04-12 15:20:57 | [diff] [blame] | 154 | |
| 155 | if (current_os != "aix" && !is_win) { |
| 156 | # Inform the build system that this binary contains Rust unit tests. The |
| 157 | # test-containing rlibs linked into it must not be discarded by the linker |
| 158 | # even if there will be no edges going into them. |
| 159 | # |
| 160 | # For C++ this is done by not putting them in a library at all, but Rust |
| 161 | # must be compiled into an rlib. |
| 162 | # |
| 163 | # On AIX there's no flag to avoid pruning unit tests in this library from |
| 164 | # the linking step. On Windows, there's no need for it. |
| 165 | if (_rs_sources != []) { |
| 166 | ldflags += |
| 167 | [ "-LinkWrapper,add-whole-archive=${_rust_target_name}.rlib" ] |
| 168 | } |
| 169 | |
| 170 | # Do the same for any Rust dependencies with unit tests in them. This will |
| 171 | # only match rust targets by looking for rlib extensions. |
| 172 | foreach(d, deps) { |
| 173 | _dep_target_name = get_label_info(d, "name") |
| 174 | ldflags += [ "-LinkWrapper,add-whole-archive=${_dep_target_name}.rlib" ] |
| 175 | } |
| 176 | } |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 180 | # Define a test as an executable (or apk on Android) with the "testonly" flag |
| 181 | # set. |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 182 | # Variable: |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 183 | # use_xvfb: (optional) whether to run the executable under Xvfb. |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 184 | # use_raw_android_executable: Use executable() rather than android_apk(). |
ynovikov | 389d9e44 | 2016-05-27 02:34:56 | [diff] [blame] | 185 | # use_native_activity: Test implements ANativeActivity_onCreate(). |
Greg Thompson | 318cd69 | 2022-03-28 08:12:06 | [diff] [blame] | 186 | # test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test |
Greg Thompson | fd26965 | 2022-10-28 12:06:55 | [diff] [blame] | 187 | # runner shard rather than the default shard for the ELF runner when |
| 188 | # assembling the test component. This is useful, for example, to use the |
| 189 | # elf_test_ambient_exec_runner for tests that require |
| 190 | # job_policy_ambient_mark_vmo_exec. |
| 191 | # fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component() |
| 192 | # targets that this test package contains. |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 193 | # is_xctest: (iOS, optional) whether to build the executable as XCTest. |
| 194 | # Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but |
| 195 | # for build targets. |
Stefano Duo | 4128b6b | 2021-08-02 21:24:43 | [diff] [blame] | 196 | # allow_cleartext_traffic: (Android, optional) whether to allow cleartext |
| 197 | # network requests during the test. |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 198 | template("test") { |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 199 | # Ensures the rts file exists and if not, creates a dummy file |
| 200 | if (use_rts) { |
| 201 | action("${target_name}__rts_filters") { |
| 202 | script = "//build/add_rts_filters.py" |
Greg Guterman | 49a4217 | 2021-04-08 22:04:53 | [diff] [blame] | 203 | rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter" |
Struan Shrimpton | 570c8784 | 2022-08-16 22:30:05 | [diff] [blame] | 204 | inverted_rts_file = |
| 205 | "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter" |
| 206 | args = [ |
| 207 | rebase_path(rts_file, root_build_dir), |
| 208 | rebase_path(inverted_rts_file, root_build_dir), |
| 209 | ] |
| 210 | outputs = [ |
| 211 | rts_file, |
| 212 | inverted_rts_file, |
| 213 | ] |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 217 | testonly = true |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 218 | if (!is_ios) { |
| 219 | assert(!defined(invoker.is_xctest) || !invoker.is_xctest, |
| 220 | "is_xctest can be set only for iOS builds") |
| 221 | } |
Stefano Duo | 4128b6b | 2021-08-02 21:24:43 | [diff] [blame] | 222 | if (!is_android) { |
| 223 | assert(!defined(invoker.allow_cleartext_traffic), |
| 224 | "allow_cleartext_traffic can be set only for Android tests") |
| 225 | } |
| 226 | |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 227 | if (is_android) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 228 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 229 | |
Peter Kotwicz | 10742f8 | 2021-04-15 22:32:50 | [diff] [blame] | 230 | _use_default_launcher = |
| 231 | !defined(invoker.use_default_launcher) || invoker.use_default_launcher |
| 232 | if (!defined(invoker.use_raw_android_executable)) { |
| 233 | # Checkouts where build_with_chromium == false often have a custom GN |
| 234 | # template wrapper around test() which sets use_default_launcher == false. |
| 235 | # Set the _use_raw_android_executable default so that test() targets which |
| 236 | # do not use the custom wrapper |
| 237 | # (1) Do not cause "gn gen" to fail |
| 238 | # (2) Do not need to be moved into if(build_with_chromium) block. |
| 239 | _use_raw_android_executable = |
| 240 | !build_with_chromium && _use_default_launcher |
| 241 | } else { |
| 242 | not_needed([ "_use_default_launcher" ]) |
| 243 | _use_raw_android_executable = invoker.use_raw_android_executable |
| 244 | } |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 245 | |
agrieve | 67855de | 2016-03-30 14:46:01 | [diff] [blame] | 246 | # output_name is used to allow targets with the same name but in different |
| 247 | # packages to still produce unique runner scripts. |
| 248 | _output_name = invoker.target_name |
mikecase | 56d80d7 | 2015-06-03 00:57:26 | [diff] [blame] | 249 | if (defined(invoker.output_name)) { |
agrieve | 67855de | 2016-03-30 14:46:01 | [diff] [blame] | 250 | _output_name = invoker.output_name |
mikecase | 56d80d7 | 2015-06-03 00:57:26 | [diff] [blame] | 251 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 252 | |
agrieve | b355ad15 | 2016-04-19 03:45:23 | [diff] [blame] | 253 | _test_runner_target = "${_output_name}__test_runner_script" |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 254 | _wrapper_script_vars = [ |
Jamie Madill | 73b9af33 | 2022-08-03 19:27:47 | [diff] [blame] | 255 | "android_test_runner_script", |
agrieve | e41ae190d | 2016-04-25 14:12:51 | [diff] [blame] | 256 | "ignore_all_data_deps", |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 257 | "shard_timeout", |
agrieve | e41ae190d | 2016-04-25 14:12:51 | [diff] [blame] | 258 | ] |
agrieve | 3ac557f0 | 2016-04-12 15:52:00 | [diff] [blame] | 259 | |
jbudorick | ced2a25 | 2016-06-09 16:38:54 | [diff] [blame] | 260 | assert(_use_raw_android_executable || enable_java_templates) |
| 261 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 262 | if (_use_raw_android_executable) { |
Peter Kotwicz | 13a827a6 | 2021-04-22 22:34:49 | [diff] [blame] | 263 | not_needed(invoker, [ "add_unwind_tables_in_apk" ]) |
| 264 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 265 | _exec_target = "${target_name}__exec" |
| 266 | _dist_target = "${target_name}__dist" |
| 267 | _exec_output = |
| 268 | "$target_out_dir/${invoker.target_name}/${invoker.target_name}" |
| 269 | |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 270 | mixed_test(_exec_target) { |
| 271 | target_type = "executable" |
| 272 | |
danakj | e94f40d | 2022-02-16 18:13:53 | [diff] [blame] | 273 | # Configs will always be defined since we set_defaults in |
| 274 | # BUILDCONFIG.gn. |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 275 | configs = [] |
Dirk Pranke | 19a5873 | 2021-03-24 22:26:22 | [diff] [blame] | 276 | forward_variables_from( |
| 277 | invoker, |
| 278 | "*", |
| 279 | TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [ |
| 280 | "data_deps", |
| 281 | "extra_dist_files", |
| 282 | ]) |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 283 | |
| 284 | # Thanks to the set_defaults() for test(), configs are initialized with |
| 285 | # the default shared_library configs rather than executable configs. |
Thomas Anderson | 11c1d982 | 2019-01-15 06:32:59 | [diff] [blame] | 286 | configs -= [ |
| 287 | "//build/config:shared_library_config", |
| 288 | "//build/config/android:hide_all_but_jni", |
| 289 | ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 290 | configs += [ "//build/config:executable_config" ] |
| 291 | |
Dirk Pranke | 19a5873 | 2021-03-24 22:26:22 | [diff] [blame] | 292 | if (defined(invoker.data_deps)) { |
| 293 | data_deps = invoker.data_deps |
| 294 | } else { |
| 295 | data_deps = [] |
| 296 | } |
| 297 | if (!defined(data)) { |
| 298 | data = [] |
| 299 | } |
Jamie Madill | dd60ee6 | 2021-04-13 19:25:52 | [diff] [blame] | 300 | if (tests_have_location_tags) { |
| 301 | data += [ "//testing/location_tags.json" ] |
| 302 | } |
Dirk Pranke | 19a5873 | 2021-03-24 22:26:22 | [diff] [blame] | 303 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 304 | # Don't output to the root or else conflict with the group() below. |
| 305 | output_name = rebase_path(_exec_output, root_out_dir) |
Greg Guterman | 50ed4b4 | 2021-04-08 01:15:11 | [diff] [blame] | 306 | |
| 307 | if (use_rts) { |
| 308 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 309 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | create_native_executable_dist(_dist_target) { |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 313 | dist_dir = "$root_out_dir/$target_name" |
| 314 | binary = _exec_output |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 315 | deps = [ ":$_exec_target" ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 316 | if (defined(invoker.extra_dist_files)) { |
| 317 | extra_files = invoker.extra_dist_files |
| 318 | } |
Greg Guterman | 50ed4b4 | 2021-04-08 01:15:11 | [diff] [blame] | 319 | |
| 320 | if (use_rts) { |
| 321 | if (!defined(data_deps)) { |
| 322 | data_deps = [] |
| 323 | } |
| 324 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 325 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 326 | } |
| 327 | } else { |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 328 | _library_target_name = "${target_name}__library" |
danakj | 98e07372 | 2022-02-24 21:01:49 | [diff] [blame] | 329 | _library_crate_name = "${target_name}_library" |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 330 | _apk_target_name = "${target_name}__apk" |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 331 | _apk_specific_vars = [ |
Stefano Duo | 4128b6b | 2021-08-02 21:24:43 | [diff] [blame] | 332 | "allow_cleartext_traffic", |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 333 | "android_manifest", |
agrieve | c6811b42 | 2016-06-23 02:25:09 | [diff] [blame] | 334 | "android_manifest_dep", |
Peter Kotwicz | ab1b542 | 2021-03-30 22:58:27 | [diff] [blame] | 335 | "android_manifest_template", |
Clark DuVall | 1bee532 | 2020-06-10 05:51:55 | [diff] [blame] | 336 | "app_as_shared_lib", |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 337 | "enable_multidex", |
Peter Kotwicz | 10742f8 | 2021-04-15 22:32:50 | [diff] [blame] | 338 | "generate_final_jni", |
Benoît Lizé | d8b8f74 | 2019-11-07 12:50:07 | [diff] [blame] | 339 | "product_config_java_packages", |
Andrew Grieve | 43f24fd0 | 2022-04-06 23:04:04 | [diff] [blame] | 340 | "loadable_modules", |
| 341 | "loadable_module_deps", |
Tibor Goldschwendt | 95db95d | 2019-06-17 20:32:02 | [diff] [blame] | 342 | "min_sdk_version", |
huapengl | c35ba6e | 2016-05-25 23:08:07 | [diff] [blame] | 343 | "proguard_configs", |
| 344 | "proguard_enabled", |
Fred Mello | 0cc91c6 | 2019-08-24 01:53:45 | [diff] [blame] | 345 | "srcjar_deps", |
Tibor Goldschwendt | 95db95d | 2019-06-17 20:32:02 | [diff] [blame] | 346 | "target_sdk_version", |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 347 | "use_default_launcher", |
ynovikov | 389d9e44 | 2016-05-27 02:34:56 | [diff] [blame] | 348 | "use_native_activity", |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 349 | ] |
Siddhartha | 764226b | 2018-03-13 02:32:55 | [diff] [blame] | 350 | |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 351 | _add_unwind_tables_in_apk = |
| 352 | defined(invoker.add_unwind_tables_in_apk) && |
| 353 | invoker.add_unwind_tables_in_apk && target_cpu == "arm" |
Andrew Grieve | d5fdf2af | 2022-08-23 07:47:55 | [diff] [blame] | 354 | |
Siddhartha | 764226b | 2018-03-13 02:32:55 | [diff] [blame] | 355 | # Adds the unwind tables from unstripped binary as an asset file in the |
| 356 | # apk, if |add_unwind_tables_in_apk| is specified by the test. |
Andrew Grieve | d5fdf2af | 2022-08-23 07:47:55 | [diff] [blame] | 357 | if (_add_unwind_tables_in_apk) { |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 358 | # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when |
Tushar Agarwal | dcafb62 | 2022-11-30 17:32:27 | [diff] [blame] | 359 | # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`. |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 360 | _unwind_table_name = "${_library_target_name}_unwind_v1" |
| 361 | unwind_table_v1(_unwind_table_name) { |
| 362 | library_target = ":$_library_target_name" |
| 363 | } |
| 364 | |
Arthur Sonzogni | 54424e9 | 2022-09-23 13:30:45 | [diff] [blame] | 365 | if (use_android_unwinder_v2) { |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 366 | _unwind_table_v2_name = "${_library_target_name}_unwind_v2" |
| 367 | unwind_table_v2(_unwind_table_v2_name) { |
| 368 | library_target = ":$_library_target_name" |
Arthur Sonzogni | 54424e9 | 2022-09-23 13:30:45 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 372 | _unwind_table_asset_name = "${target_name}__unwind_assets" |
| 373 | android_assets(_unwind_table_asset_name) { |
| 374 | sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ] |
| 375 | disable_compression = true |
| 376 | deps = [ ":$_unwind_table_name" ] |
| 377 | if (use_android_unwinder_v2) { |
| 378 | sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ] |
| 379 | deps += [ ":$_unwind_table_v2_name" ] |
| 380 | } |
Siddhartha | 764226b | 2018-03-13 02:32:55 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 384 | mixed_test(_library_target_name) { |
Sam Maier | 7acb8d6b | 2023-05-15 14:00:22 | [diff] [blame^] | 385 | target_type = "shared_library_with_jni" |
| 386 | java_targets = [ ":$_apk_target_name" ] |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 387 | |
danakj | 98e07372 | 2022-02-24 21:01:49 | [diff] [blame] | 388 | # Configs will always be defined since we set_defaults in |
| 389 | # BUILDCONFIG.gn. |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 390 | configs = [] # Prevent list overwriting warning. |
| 391 | configs = invoker.configs |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 392 | |
Andrew Grieve | d5fdf2af | 2022-08-23 07:47:55 | [diff] [blame] | 393 | if (_add_unwind_tables_in_apk) { |
| 394 | # Remove -gz if present, as dump_syms does not support it. |
| 395 | # Add and then remove because "-=" removes all, but errors if none are found. |
| 396 | configs += [ "//build/config:compress_debug_sections" ] |
| 397 | configs -= [ "//build/config:compress_debug_sections" ] |
| 398 | } |
| 399 | |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 400 | forward_variables_from( |
| 401 | invoker, |
| 402 | "*", |
Andrew Grieve | d5fdf2af | 2022-08-23 07:47:55 | [diff] [blame] | 403 | [ |
| 404 | "configs", |
| 405 | "deps", |
| 406 | ] + _apk_specific_vars + _wrapper_script_vars + |
Peter Wen | 2052bd1 | 2020-12-03 20:15:07 | [diff] [blame] | 407 | TESTONLY_AND_VISIBILITY) |
| 408 | |
danakj | 482580a | 2022-11-18 18:00:59 | [diff] [blame] | 409 | # Use a crate name that avoids creating a warning due to double |
| 410 | # underscore (ie. `__`). |
| 411 | crate_name = _library_crate_name |
| 412 | |
Peter Wen | 2052bd1 | 2020-12-03 20:15:07 | [diff] [blame] | 413 | # Native targets do not need to depend on java targets. Filter them out |
| 414 | # so that the shared library can be built without needing to wait for |
| 415 | # dependent java targets. |
| 416 | deps = [] |
| 417 | if (defined(invoker.deps)) { |
Andrew Grieve | 841ed07 | 2022-08-23 16:42:33 | [diff] [blame] | 418 | deps = filter_exclude(invoker.deps, java_target_patterns) |
Peter Wen | 2052bd1 | 2020-12-03 20:15:07 | [diff] [blame] | 419 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 420 | |
Peter Kotwicz | b9957d6 | 2021-04-12 21:09:43 | [diff] [blame] | 421 | if (_use_default_launcher) { |
Tom Anderson | ce772fa | 2018-05-30 22:20:37 | [diff] [blame] | 422 | deps += [ "//testing/android/native_test:native_test_native_code" ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 423 | } |
| 424 | } |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 425 | unittest_apk(_apk_target_name) { |
Daniel Bratell | fdda465 | 2019-01-31 15:45:54 | [diff] [blame] | 426 | forward_variables_from(invoker, _apk_specific_vars) |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 427 | shared_library = ":$_library_target_name" |
Sam Maier | 7acb8d6b | 2023-05-15 14:00:22 | [diff] [blame^] | 428 | srcjar_deps = [ "${shared_library}__jni_registration" ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 429 | apk_name = invoker.target_name |
| 430 | if (defined(invoker.output_name)) { |
| 431 | apk_name = invoker.output_name |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 432 | install_script_name = "install_${invoker.output_name}" |
| 433 | } |
agrieve | b355ad15 | 2016-04-19 03:45:23 | [diff] [blame] | 434 | |
Daniel Bratell | fdda465 | 2019-01-31 15:45:54 | [diff] [blame] | 435 | if (defined(invoker.deps)) { |
| 436 | deps = invoker.deps |
| 437 | } else { |
| 438 | deps = [] |
| 439 | } |
Andrew Grieve | 43f24fd0 | 2022-04-06 23:04:04 | [diff] [blame] | 440 | if (defined(loadable_module_deps)) { |
| 441 | deps += loadable_module_deps |
| 442 | } |
Daniel Bratell | fdda465 | 2019-01-31 15:45:54 | [diff] [blame] | 443 | |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 444 | # Add the Java classes so that each target does not have to do it. |
Peter Kotwicz | b9957d6 | 2021-04-12 21:09:43 | [diff] [blame] | 445 | if (_use_default_launcher) { |
| 446 | deps += [ "//base/test:test_support_java" ] |
| 447 | } |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 448 | |
Siddhartha | 764226b | 2018-03-13 02:32:55 | [diff] [blame] | 449 | if (defined(_unwind_table_asset_name)) { |
| 450 | deps += [ ":${_unwind_table_asset_name}" ] |
| 451 | } |
Greg Guterman | 50ed4b4 | 2021-04-08 01:15:11 | [diff] [blame] | 452 | |
| 453 | if (use_rts) { |
| 454 | data_deps = [ ":${invoker.target_name}__rts_filters" ] |
| 455 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 456 | } |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 457 | } |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 458 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 459 | test_runner_script(_test_runner_target) { |
| 460 | forward_variables_from(invoker, _wrapper_script_vars) |
estevenson | ce844392 | 2016-12-15 19:57:57 | [diff] [blame] | 461 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 462 | if (_use_raw_android_executable) { |
| 463 | executable_dist_dir = "$root_out_dir/$_dist_target" |
John Budorick | d5dccb2 | 2020-02-01 02:16:34 | [diff] [blame] | 464 | data_deps = [ ":$_exec_target" ] |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 465 | } else { |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 466 | apk_target = ":$_apk_target_name" |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 467 | incremental_apk = incremental_install |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 468 | |
| 469 | # Dep needed for the test runner .runtime_deps file to pick up data |
| 470 | # deps from the forward_variables_from(invoker, "*") on the library. |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 471 | data_deps = [ ":$_library_target_name" ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 472 | } |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 473 | test_name = _output_name |
| 474 | test_suite = _output_name |
| 475 | test_type = "gtest" |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 476 | |
| 477 | if (use_rts) { |
| 478 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 479 | } |
mikecase | 56d80d7 | 2015-06-03 00:57:26 | [diff] [blame] | 480 | } |
| 481 | |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 482 | # Create a wrapper script rather than using a group() in order to ensure |
| 483 | # "ninja $target_name" always works. If this was a group(), then GN would |
| 484 | # not create a top-level alias for it if a target exists in another |
| 485 | # directory with the same $target_name. |
| 486 | # Also - bots run this script directly for "components_perftests". |
| 487 | generate_wrapper(target_name) { |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 488 | forward_variables_from(invoker, [ "visibility" ]) |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 489 | executable = "$root_build_dir/bin/run_$_output_name" |
| 490 | wrapper_script = "$root_build_dir/$_output_name" |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 491 | deps = [ ":$_test_runner_target" ] |
jbudorick | 686094f6 | 2017-05-04 21:52:40 | [diff] [blame] | 492 | if (_use_raw_android_executable) { |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 493 | deps += [ ":$_dist_target" ] |
jbudorick | 686094f6 | 2017-05-04 21:52:40 | [diff] [blame] | 494 | } else { |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 495 | # Dep needed for the swarming .isolate file to pick up data |
| 496 | # deps from the forward_variables_from(invoker, "*") on the library. |
| 497 | deps += [ |
Andrew Grieve | ee8aa44d | 2022-09-23 17:14:38 | [diff] [blame] | 498 | ":$_apk_target_name", |
| 499 | ":$_library_target_name", |
Andrew Grieve | 7ca6de3 | 2019-10-18 03:57:47 | [diff] [blame] | 500 | ] |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 501 | } |
Dirk Pranke | 19a5873 | 2021-03-24 22:26:22 | [diff] [blame] | 502 | |
| 503 | if (defined(invoker.data_deps)) { |
| 504 | data_deps = invoker.data_deps |
| 505 | } else { |
| 506 | data_deps = [] |
| 507 | } |
Kevin Marshall | 2352936 | 2022-02-23 16:50:36 | [diff] [blame] | 508 | |
| 509 | data_deps += [ "//testing:test_scripts_shared" ] |
| 510 | |
Jamie Madill | dd60ee6 | 2021-04-13 19:25:52 | [diff] [blame] | 511 | if (tests_have_location_tags) { |
| 512 | data = [ "//testing/location_tags.json" ] |
| 513 | } |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 514 | |
| 515 | if (use_rts) { |
| 516 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 517 | } |
agrieve | 1a02e58 | 2015-10-15 21:35:39 | [diff] [blame] | 518 | } |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 519 | } else if (is_fuchsia) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 520 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 521 | |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 522 | _output_name = invoker.target_name |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 523 | _pkg_target = "${_output_name}_pkg" |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 524 | _exec_target = "${_output_name}__exec" |
Greg Thompson | 9765eeb4 | 2022-04-05 12:30:35 | [diff] [blame] | 525 | _program_name = get_label_info(":${_exec_target}", "name") |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 526 | |
Greg Thompson | 2f1e376 | 2022-10-17 19:53:44 | [diff] [blame] | 527 | # Generate a CML fragment that provides the program name. |
| 528 | _test_program_fragment_target = "${target_name}_program-fragment" |
| 529 | _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml" |
| 530 | generated_file(_test_program_fragment_target) { |
| 531 | contents = { |
| 532 | program = { |
| 533 | binary = _program_name |
Kevin Marshall | 2ec6003 | 2022-05-09 17:38:28 | [diff] [blame] | 534 | } |
Greg Thompson | 2651659 | 2021-12-16 08:34:45 | [diff] [blame] | 535 | } |
Greg Thompson | 2f1e376 | 2022-10-17 19:53:44 | [diff] [blame] | 536 | outputs = [ _test_program_fragment ] |
| 537 | output_conversion = "json" |
Greg Thompson | 9765eeb4 | 2022-04-05 12:30:35 | [diff] [blame] | 538 | } |
| 539 | |
Greg Thompson | 2f1e376 | 2022-10-17 19:53:44 | [diff] [blame] | 540 | _test_runner_shard = |
| 541 | "//build/config/fuchsia/test/elf_test_runner.shard.test-cml" |
| 542 | if (defined(invoker.test_runner_shard)) { |
| 543 | _test_runner_shard = invoker.test_runner_shard |
Wez | 6879f8a | 2021-09-07 20:27:02 | [diff] [blame] | 544 | } |
| 545 | |
Greg Thompson | 2f1e376 | 2022-10-17 19:53:44 | [diff] [blame] | 546 | # Collate the complete set of elements to include in the test component's |
| 547 | # manifest. |
David Dorwin | 2c4872c | 2023-02-22 20:00:56 | [diff] [blame] | 548 | |
Greg Thompson | 2f1e376 | 2022-10-17 19:53:44 | [diff] [blame] | 549 | _manifest_fragments = [ |
Greg Thompson | 2f1e376 | 2022-10-17 19:53:44 | [diff] [blame] | 550 | _test_program_fragment, |
| 551 | _test_runner_shard, |
| 552 | ] |
| 553 | |
David Dorwin | 2c4872c | 2023-02-22 20:00:56 | [diff] [blame] | 554 | # Select the Fuchsia test realm in which to run the test. |
| 555 | if (defined(invoker.run_as_chromium_system_test) && |
| 556 | invoker.run_as_chromium_system_test) { |
| 557 | _manifest_fragments += [ |
| 558 | "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml", |
| 559 | "//build/config/fuchsia/test/system_test_minimum.shard.test-cml", |
| 560 | ] |
| 561 | } else { |
| 562 | _manifest_fragments += [ |
| 563 | "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml", |
| 564 | "//build/config/fuchsia/test/minimum.shard.test-cml", |
| 565 | ] |
| 566 | } |
| 567 | |
Greg Thompson | 2f1e376 | 2022-10-17 19:53:44 | [diff] [blame] | 568 | _test_component_manifest = "${target_out_dir}/${target_name}.cml" |
| 569 | _merged_manifest_name = "${_output_name}.cml" |
| 570 | |
| 571 | if (defined(invoker.additional_manifest_fragments)) { |
| 572 | _manifest_fragments += invoker.additional_manifest_fragments |
| 573 | } |
| 574 | |
| 575 | # Generate the test component manifest from the specified elements. |
| 576 | _test_component_manifest_target = "${target_name}_component-manifest" |
| 577 | cmc_merge(_test_component_manifest_target) { |
| 578 | sources = _manifest_fragments |
| 579 | output_name = "${_merged_manifest_name}" |
| 580 | deps = [ ":${_test_program_fragment_target}" ] |
| 581 | } |
| 582 | |
| 583 | # Define the test component, dependent on the generated manifest, and the |
| 584 | # test executable target. |
| 585 | _test_component_target = "${target_name}_component" |
| 586 | fuchsia_component(_test_component_target) { |
| 587 | deps = [ ":$_test_component_manifest_target" ] |
| 588 | data_deps = [ ":$_exec_target" ] |
| 589 | manifest = _test_component_manifest |
| 590 | visibility = [ ":*" ] |
| 591 | } |
| 592 | |
| 593 | _test_component_targets = [ ":${_test_component_target}" ] |
| 594 | |
Wez | 6879f8a | 2021-09-07 20:27:02 | [diff] [blame] | 595 | # Define components for each entry in |additional_manifests|, if any. Since |
| 596 | # manifests may themselves depend-on the outputs of |deps|, these components |
| 597 | # must each individually depend on |invoker.deps|. |
Wez | 6879f8a | 2021-09-07 20:27:02 | [diff] [blame] | 598 | if (defined(invoker.additional_manifests)) { |
| 599 | foreach(filename, invoker.additional_manifests) { |
| 600 | _additional_component_target = |
| 601 | target_name + "_" + get_path_info(filename, "name") |
| 602 | _test_component_targets += [ ":${_additional_component_target}" ] |
| 603 | fuchsia_component(_additional_component_target) { |
| 604 | forward_variables_from(invoker, [ "testonly" ]) |
| 605 | data_deps = [ ":$_exec_target" ] |
| 606 | visibility = [ ":*" ] |
| 607 | manifest = filename |
| 608 | |
| 609 | # Depend on |invoker.deps|, in case it includes a dependency that |
| 610 | # creates this additional component's manifest. |
| 611 | if (defined(invoker.deps)) { |
| 612 | deps = invoker.deps |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | # Define the package target that will bundle the test and additional |
| 619 | # components and their data. |
| 620 | fuchsia_package(_pkg_target) { |
Kevin Marshall | 36c602c | 2021-11-04 16:16:21 | [diff] [blame] | 621 | forward_variables_from(invoker, |
| 622 | [ |
| 623 | "excluded_files", |
| 624 | "excluded_dirs", |
Bryant Chandler | c40f267 | 2023-01-27 23:33:30 | [diff] [blame] | 625 | "excluded_paths", |
Kevin Marshall | 36c602c | 2021-11-04 16:16:21 | [diff] [blame] | 626 | ]) |
Wez | 6879f8a | 2021-09-07 20:27:02 | [diff] [blame] | 627 | package_name = _output_name |
| 628 | deps = _test_component_targets |
Kevin Marshall | 36c602c | 2021-11-04 16:16:21 | [diff] [blame] | 629 | |
Greg Thompson | fd26965 | 2022-10-28 12:06:55 | [diff] [blame] | 630 | if (defined(invoker.fuchsia_package_deps)) { |
| 631 | deps += invoker.fuchsia_package_deps |
| 632 | } |
Bryant Chandler | c40f267 | 2023-01-27 23:33:30 | [diff] [blame] | 633 | if (!defined(excluded_paths)) { |
| 634 | excluded_paths = [] |
Kevin Marshall | 36c602c | 2021-11-04 16:16:21 | [diff] [blame] | 635 | } |
Bryant Chandler | c40f267 | 2023-01-27 23:33:30 | [diff] [blame] | 636 | excluded_paths += [ |
| 637 | "${devtools_root_location}/*", |
| 638 | "*.git/*", |
| 639 | "*.svn/*", |
| 640 | "*.hg/*", |
| 641 | ] |
Sarah Pham | 80972efc | 2022-05-31 17:40:15 | [diff] [blame] | 642 | if (devtools_root_location != "") { |
Bryant Chandler | c40f267 | 2023-01-27 23:33:30 | [diff] [blame] | 643 | excluded_paths += [ "${devtools_root_location}/*" ] |
Sarah Pham | 80972efc | 2022-05-31 17:40:15 | [diff] [blame] | 644 | } |
Wez | 6879f8a | 2021-09-07 20:27:02 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | # |target_name| refers to the package-runner rule, so that building |
| 648 | # "base_unittests" will build not only the executable, component, and |
| 649 | # package, but also the script required to run them. |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 650 | fuchsia_test_runner(target_name) { |
Fabrice de Gans-Riberi | 041a652 | 2018-12-11 00:20:53 | [diff] [blame] | 651 | forward_variables_from(invoker, |
| 652 | [ |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 653 | "data", |
| 654 | "data_deps", |
Fabrice de Gans-Riberi | 041a652 | 2018-12-11 00:20:53 | [diff] [blame] | 655 | "package_deps", |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 656 | "use_test_server", |
Fabrice de Gans-Riberi | 041a652 | 2018-12-11 00:20:53 | [diff] [blame] | 657 | ]) |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 658 | |
Chong Gu | c6bfdf6 | 2021-10-20 23:37:00 | [diff] [blame] | 659 | is_test_exe = true |
Kevin Marshall | 39b4aa8 | 2018-06-23 00:12:15 | [diff] [blame] | 660 | package = ":$_pkg_target" |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 661 | package_name = _output_name |
Dimitri Glazkov | c95e6dd | 2018-08-24 23:39:42 | [diff] [blame] | 662 | |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 663 | if (!defined(deps)) { |
| 664 | deps = [] |
Jamie Madill | dd60ee6 | 2021-04-13 19:25:52 | [diff] [blame] | 665 | } |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 666 | if (defined(invoker.deps)) { |
| 667 | deps += invoker.deps |
| 668 | } |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 669 | |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 670 | if (!defined(data)) { |
| 671 | data = [] |
| 672 | } |
| 673 | if (tests_have_location_tags) { |
| 674 | data += [ "//testing/location_tags.json" ] |
| 675 | } |
| 676 | |
| 677 | if (!defined(data_deps)) { |
| 678 | data_deps = [] |
| 679 | } |
Benjamin Lerman | 5e3cb336 | 2022-01-25 16:46:28 | [diff] [blame] | 680 | |
Kevin Marshall | 2352936 | 2022-02-23 16:50:36 | [diff] [blame] | 681 | data_deps += [ "//testing:test_scripts_shared" ] |
| 682 | |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 683 | if (use_rts) { |
Kevin Marshall | 5fadadd | 2021-10-16 00:08:25 | [diff] [blame] | 684 | data_deps += [ ":${target_name}__rts_filters" ] |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 685 | } |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 686 | } |
| 687 | |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 688 | mixed_test(_exec_target) { |
| 689 | target_type = "executable" |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 690 | forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame] | 691 | output_name = _exec_target |
Scott Graham | 4c4cdc5 | 2017-05-29 20:45:03 | [diff] [blame] | 692 | } |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 693 | } else if (is_ios) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 694 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
Mirko Bonadei | 50e251d | 2020-09-14 18:05:46 | [diff] [blame] | 695 | _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps" |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 696 | |
Rohit Rao | f9b096d | 2019-09-09 22:26:23 | [diff] [blame] | 697 | declare_args() { |
| 698 | # Keep the unittest-as-xctest functionality defaulted to off until the |
| 699 | # bots are updated to handle it properly. |
| 700 | # TODO(crbug.com/1001667): Remove this arg once the iOS test runner |
| 701 | # supports running unittests with xctest. |
| 702 | enable_run_ios_unittests_with_xctest = false |
| 703 | } |
| 704 | |
sdefresne | 01285787 | 2016-03-16 10:55:37 | [diff] [blame] | 705 | _test_target = target_name |
Sylvain Defresne | 3f48aedc | 2021-10-07 10:17:27 | [diff] [blame] | 706 | _output_name = target_name |
| 707 | if (defined(invoker.output_name)) { |
| 708 | _output_name = invoker.output_name |
| 709 | } |
| 710 | |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 711 | _wrapper_output_name = "run_${target_name}" |
| 712 | ios_test_runner_wrapper(_wrapper_output_name) { |
| 713 | forward_variables_from(invoker, |
| 714 | [ |
| 715 | "data", |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 716 | "deps", |
| 717 | "executable_args", |
Sylvain Defresne | 3f48aedc | 2021-10-07 10:17:27 | [diff] [blame] | 718 | "output_name", |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 719 | "retries", |
| 720 | "shards", |
| 721 | ]) |
| 722 | |
| 723 | _root_build_dir = rebase_path("${root_build_dir}", root_build_dir) |
| 724 | |
| 725 | if (!defined(executable_args)) { |
| 726 | executable_args = [] |
| 727 | } |
| 728 | executable_args += [ |
| 729 | "--app", |
| 730 | "@WrappedPath(${_root_build_dir}/${_test_target}.app)", |
| 731 | ] |
| 732 | |
| 733 | wrapper_output_name = "${_wrapper_output_name}" |
Dirk Pranke | 19a5873 | 2021-03-24 22:26:22 | [diff] [blame] | 734 | |
| 735 | if (!defined(data)) { |
| 736 | data = [] |
| 737 | } |
Jamie Madill | dd60ee6 | 2021-04-13 19:25:52 | [diff] [blame] | 738 | if (tests_have_location_tags) { |
| 739 | data += [ "//testing/location_tags.json" ] |
| 740 | } |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 741 | } |
| 742 | |
sdefresne | 01285787 | 2016-03-16 10:55:37 | [diff] [blame] | 743 | _resources_bundle_data = target_name + "_resources_bundle_data" |
| 744 | |
| 745 | bundle_data(_resources_bundle_data) { |
sdefresne | 047490e | 2016-07-22 08:49:34 | [diff] [blame] | 746 | visibility = [ ":$_test_target" ] |
Nico Weber | 852532f | 2020-01-28 18:17:22 | [diff] [blame] | 747 | sources = [ "//testing/gtest_ios/Default.png" ] |
| 748 | outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 749 | } |
| 750 | |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 751 | force_xctest = enable_run_ios_unittests_with_xctest || |
| 752 | (defined(invoker.is_xctest) && invoker.is_xctest) |
| 753 | |
danakj | fae603fc60 | 2022-11-18 18:40:22 | [diff] [blame] | 754 | mixed_test(_test_target) { |
| 755 | if (force_xctest) { |
| 756 | target_type = "ios_xctest_test" |
| 757 | } else { |
| 758 | target_type = "ios_app_bundle" |
| 759 | } |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 760 | testonly = true |
sdefresne | a828c28 | 2016-05-30 18:04:20 | [diff] [blame] | 761 | |
Mirko Bonadei | 15522bc | 2020-09-16 20:38:39 | [diff] [blame] | 762 | if (force_xctest && build_with_chromium) { |
Rohit Rao | f9b096d | 2019-09-09 22:26:23 | [diff] [blame] | 763 | xctest_module_target = "//base/test:google_test_runner" |
| 764 | } |
| 765 | |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 766 | forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) |
sdefresne | 9e147e0 | 2016-06-07 00:10:13 | [diff] [blame] | 767 | |
| 768 | # Provide sensible defaults in case invoker did not define any of those |
| 769 | # required variables. |
sdefresne | 05b97ca | 2016-06-08 07:19:46 | [diff] [blame] | 770 | if (!defined(info_plist) && !defined(info_plist_target)) { |
sdefresne | 9e147e0 | 2016-06-07 00:10:13 | [diff] [blame] | 771 | info_plist = "//testing/gtest_ios/unittest-Info.plist" |
| 772 | } |
sdefresne | 9e147e0 | 2016-06-07 00:10:13 | [diff] [blame] | 773 | |
Sylvain Defresne | 3c5a131 | 2021-09-23 17:08:09 | [diff] [blame] | 774 | if (ios_use_shared_bundle_id_for_test_apps) { |
Ali Juma | c9da024 | 2022-02-18 20:43:13 | [diff] [blame] | 775 | bundle_identifier = shared_bundle_id_for_test_apps |
Ali Juma | ff45dd8 | 2021-11-08 21:53:50 | [diff] [blame] | 776 | not_needed([ "_output_name" ]) |
Sylvain Defresne | 3c5a131 | 2021-09-23 17:08:09 | [diff] [blame] | 777 | } else { |
Ali Juma | 75be0fe | 2022-01-24 19:39:29 | [diff] [blame] | 778 | bundle_identifier = "$ios_app_bundle_id_prefix.chrome." + |
Sylvain Defresne | 3f48aedc | 2021-10-07 10:17:27 | [diff] [blame] | 779 | string_replace(_output_name, "_", "-") |
Sylvain Defresne | 3c5a131 | 2021-09-23 17:08:09 | [diff] [blame] | 780 | } |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 781 | |
sdefresne | 047490e | 2016-07-22 08:49:34 | [diff] [blame] | 782 | if (!defined(bundle_deps)) { |
| 783 | bundle_deps = [] |
| 784 | } |
| 785 | bundle_deps += [ ":$_resources_bundle_data" ] |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 786 | |
| 787 | if (!defined(data_deps)) { |
| 788 | data_deps = [] |
| 789 | } |
| 790 | |
Kevin Marshall | 2352936 | 2022-02-23 16:50:36 | [diff] [blame] | 791 | data_deps += [ "//testing:test_scripts_shared" ] |
| 792 | |
Jeff Yoon | f7f4eb4 | 2020-03-06 18:55:36 | [diff] [blame] | 793 | # Include the generate_wrapper as part of data_deps |
| 794 | data_deps += [ ":${_wrapper_output_name}" ] |
Mirko Bonadei | 50e251d | 2020-09-14 18:05:46 | [diff] [blame] | 795 | write_runtime_deps = _runtime_deps_file |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 796 | |
| 797 | if (use_rts) { |
| 798 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 799 | } |
dpranke | 2a29462 | 2015-08-07 05:23:01 | [diff] [blame] | 800 | } |
Yuke Liao | 2a9b2f0e | 2021-04-16 00:40:11 | [diff] [blame] | 801 | } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) && |
| 802 | cros_board != "") { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 803 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 804 | |
Yuke Liao | 2a9b2f0e | 2021-04-16 00:40:11 | [diff] [blame] | 805 | # Building for a cros board (ie: not linux-chromeos or linux-lacros). |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 806 | |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 807 | _gen_runner_target = "${target_name}__runner" |
| 808 | _runtime_deps_file = |
| 809 | "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") + |
| 810 | "/" + get_label_info(target_name, "name") + ".runtime_deps" |
| 811 | |
Xinan Lin | 6be0125 | 2021-06-25 23:07:36 | [diff] [blame] | 812 | _generated_script = "$root_build_dir/bin/run_" + invoker.target_name |
| 813 | if (is_skylab) { |
Struan Shrimpton | f61293f6 | 2022-04-11 19:33:40 | [diff] [blame] | 814 | generate_skylab_deps(_gen_runner_target) { |
Xinan Lin | 6be0125 | 2021-06-25 23:07:36 | [diff] [blame] | 815 | generated_script = _generated_script |
| 816 | test_exe = invoker.target_name |
Yuke Liao | acb74b1 | 2021-04-23 23:37:34 | [diff] [blame] | 817 | } |
Xinan Lin | 6be0125 | 2021-06-25 23:07:36 | [diff] [blame] | 818 | } else { |
| 819 | generate_runner_script(_gen_runner_target) { |
| 820 | generated_script = _generated_script |
| 821 | test_exe = invoker.target_name |
| 822 | runtime_deps_file = _runtime_deps_file |
Yuke Liao | acb74b1 | 2021-04-23 23:37:34 | [diff] [blame] | 823 | |
Xinan Lin | 6be0125 | 2021-06-25 23:07:36 | [diff] [blame] | 824 | if (is_chromeos_lacros) { |
| 825 | # At build time, Lacros tests don't know whether they'll run on VM or |
| 826 | # HW, and instead, these flags are specified at runtime when invoking |
| 827 | # the generated runner script. |
| 828 | skip_generating_board_args = true |
| 829 | } |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 830 | |
Xinan Lin | 6be0125 | 2021-06-25 23:07:36 | [diff] [blame] | 831 | if (tests_have_location_tags) { |
| 832 | data = [ "//testing/location_tags.json" ] |
| 833 | } |
| 834 | |
| 835 | if (use_rts) { |
| 836 | data_deps = [ ":${invoker.target_name}__rts_filters" ] |
| 837 | } |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 838 | } |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 839 | } |
| 840 | |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 841 | mixed_test(target_name) { |
| 842 | target_type = "executable" |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 843 | forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) |
| 844 | forward_variables_from(invoker, [ "visibility" ]) |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 845 | if (!defined(deps)) { |
| 846 | deps = [] |
| 847 | } |
| 848 | if (!defined(data)) { |
| 849 | data = [] |
| 850 | } |
| 851 | |
Ben Pastene | 4104178 | 2019-02-16 04:21:58 | [diff] [blame] | 852 | # We use a special trigger script for CrOS hardware tests. |
| 853 | data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ] |
| 854 | |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 855 | write_runtime_deps = _runtime_deps_file |
| 856 | data += [ _runtime_deps_file ] |
Tom Anderson | ce772fa | 2018-05-30 22:20:37 | [diff] [blame] | 857 | deps += [ ":$_gen_runner_target" ] |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 858 | |
Kevin Marshall | 2352936 | 2022-02-23 16:50:36 | [diff] [blame] | 859 | if (!defined(data_deps)) { |
| 860 | data_deps = [] |
| 861 | } |
| 862 | |
| 863 | data_deps += [ "//testing:test_scripts_shared" ] |
| 864 | |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 865 | if (use_rts) { |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 866 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 867 | } |
Benjamin Pastene | 3bce864e | 2018-04-14 01:16:32 | [diff] [blame] | 868 | } |
Yuke Liao | 2a9b2f0e | 2021-04-16 00:40:11 | [diff] [blame] | 869 | } else if (is_chromeos_lacros && !is_chromeos_device) { |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 870 | _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps" |
| 871 | _executable = target_name |
| 872 | _gen_runner_target = "${target_name}__runner" |
| 873 | |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 874 | if (defined(invoker.use_xvfb)) { |
| 875 | _use_xvfb = invoker.use_xvfb |
| 876 | } else { |
| 877 | _use_xvfb = false |
| 878 | } |
| 879 | |
Yuke Liao | d037abc | 2020-10-06 22:48:22 | [diff] [blame] | 880 | # When use_xvfb is set by the invoker, it indicates that running this test |
| 881 | # target requires a window, and in lacros build, ash-chrome serves as the |
| 882 | # display server. Note that even though the tests themselves do not require |
| 883 | # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner |
| 884 | # because ash-chrome is based on x11. |
| 885 | _use_ash_chrome = _use_xvfb |
| 886 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 887 | generate_wrapper(_gen_runner_target) { |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 888 | wrapper_script = "$root_build_dir/bin/run_" + _executable |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 889 | |
Yuke Liao | 2e4953cf | 2020-07-26 19:20:19 | [diff] [blame] | 890 | data = [] |
Will Harris | d35e2c9 | 2021-04-07 01:42:02 | [diff] [blame] | 891 | data_deps = [ "//testing:test_scripts_shared" ] |
| 892 | |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 893 | if (_use_xvfb) { |
| 894 | executable = "//testing/xvfb.py" |
Takuto Ikuta | 38ebd0e | 2022-01-19 17:56:22 | [diff] [blame] | 895 | data += [ "//.vpython3" ] |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 896 | } else { |
| 897 | executable = "//testing/test_env.py" |
| 898 | } |
Jamie Madill | dd60ee6 | 2021-04-13 19:25:52 | [diff] [blame] | 899 | if (tests_have_location_tags) { |
| 900 | data += [ "//testing/location_tags.json" ] |
| 901 | } |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 902 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 903 | executable_args = [ |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 904 | "@WrappedPath(../../build/lacros/test_runner.py)", |
Yuke Liao | 240816d | 2020-07-22 00:10:39 | [diff] [blame] | 905 | "test", |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 906 | "@WrappedPath(./${_executable})", |
| 907 | "--test-launcher-bot-mode", |
| 908 | ] |
Yuke Liao | 32af424 | 2020-07-16 21:48:02 | [diff] [blame] | 909 | |
Yuke Liao | f540c74 | 2020-07-29 16:28:34 | [diff] [blame] | 910 | if (_use_ash_chrome) { |
Sven Zheng | 6d089f0 | 2021-09-13 17:59:37 | [diff] [blame] | 911 | executable_args += [ "--ash-chrome-path" ] |
| 912 | |
| 913 | # Can't use --ash-chrome-path=path because WrappedPath |
| 914 | # won't be expanded for that usage. |
| 915 | executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ] |
Yuke Liao | 240816d | 2020-07-22 00:10:39 | [diff] [blame] | 916 | } |
| 917 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 918 | if (is_asan) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 919 | executable_args += [ "--asan=1" ] |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 920 | } |
| 921 | if (is_msan) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 922 | executable_args += [ "--msan=1" ] |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 923 | } |
| 924 | if (is_tsan) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 925 | executable_args += [ "--tsan=1" ] |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 926 | } |
| 927 | if (use_cfi_diag) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 928 | executable_args += [ "--cfi-diag=1" ] |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 929 | } |
| 930 | |
Takuto Ikuta | 38ebd0e | 2022-01-19 17:56:22 | [diff] [blame] | 931 | data += [ "//build/lacros/test_runner.py" ] |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 932 | |
| 933 | if (use_rts) { |
| 934 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 935 | } |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 936 | } |
| 937 | |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 938 | mixed_test(target_name) { |
| 939 | target_type = "executable" |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 940 | forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) |
| 941 | forward_variables_from(invoker, [ "visibility" ]) |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 942 | if (!defined(deps)) { |
| 943 | deps = [] |
| 944 | } |
| 945 | |
Yuke Liao | d037abc | 2020-10-06 22:48:22 | [diff] [blame] | 946 | if (!defined(data_deps)) { |
| 947 | data_deps = [] |
| 948 | } |
| 949 | |
Kevin Marshall | 2352936 | 2022-02-23 16:50:36 | [diff] [blame] | 950 | data_deps += [ "//testing:test_scripts_shared" ] |
| 951 | |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 952 | write_runtime_deps = _runtime_deps_file |
| 953 | deps += [ ":$_gen_runner_target" ] |
Yuke Liao | d037abc | 2020-10-06 22:48:22 | [diff] [blame] | 954 | if (_use_ash_chrome && also_build_ash_chrome) { |
Sven Zheng | 74d4bd4 | 2021-06-02 02:48:56 | [diff] [blame] | 955 | data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ] |
Yuke Liao | d037abc | 2020-10-06 22:48:22 | [diff] [blame] | 956 | } |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 957 | |
| 958 | if (use_rts) { |
| 959 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 960 | } |
Yuke Liao | e703384b | 2020-07-16 01:05:24 | [diff] [blame] | 961 | } |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 962 | } else if (!is_nacl) { |
Dirk Pranke | 79d065d | 2020-08-29 03:28:30 | [diff] [blame] | 963 | if (is_mac || is_win) { |
| 964 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb) |
| 965 | } |
| 966 | |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 967 | _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps" |
| 968 | _executable = target_name |
| 969 | _gen_runner_target = "${target_name}__runner" |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 970 | |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 971 | if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) { |
| 972 | _use_xvfb = invoker.use_xvfb |
| 973 | } else { |
| 974 | _use_xvfb = false |
| 975 | } |
| 976 | |
| 977 | generate_wrapper(_gen_runner_target) { |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 978 | wrapper_script = "$root_build_dir/bin/run_" + _executable |
| 979 | |
| 980 | data = [] |
Will Harris | d35e2c9 | 2021-04-07 01:42:02 | [diff] [blame] | 981 | data_deps = [ "//testing:test_scripts_shared" ] |
| 982 | |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 983 | if (_use_xvfb) { |
| 984 | executable = "//testing/xvfb.py" |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 985 | } else { |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 986 | executable = "//testing/test_env.py" |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 987 | } |
Jamie Madill | dd60ee6 | 2021-04-13 19:25:52 | [diff] [blame] | 988 | if (tests_have_location_tags) { |
| 989 | data += [ "//testing/location_tags.json" ] |
| 990 | } |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 991 | |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 992 | executable_args = [ |
| 993 | "@WrappedPath(./${_executable})", |
| 994 | "--test-launcher-bot-mode", |
| 995 | ] |
| 996 | if (is_asan) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 997 | executable_args += [ "--asan=1" ] |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 998 | } |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 999 | if (is_msan) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 1000 | executable_args += [ "--msan=1" ] |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 1001 | } |
| 1002 | if (is_tsan) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 1003 | executable_args += [ "--tsan=1" ] |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 1004 | } |
| 1005 | if (use_cfi_diag) { |
Sven Zheng | a006f4f | 2022-10-26 18:38:00 | [diff] [blame] | 1006 | executable_args += [ "--cfi-diag=1" ] |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 1007 | } |
| 1008 | |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 1009 | if (use_rts) { |
| 1010 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 1011 | } |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 1012 | } |
| 1013 | |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 1014 | mixed_test(target_name) { |
| 1015 | target_type = "executable" |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 1016 | forward_variables_from(invoker, |
| 1017 | "*", |
| 1018 | TESTONLY_AND_VISIBILITY + [ "use_xvfb" ]) |
| 1019 | forward_variables_from(invoker, [ "visibility" ]) |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 1020 | if (!defined(deps)) { |
| 1021 | deps = [] |
| 1022 | } |
| 1023 | |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 1024 | deps += [ |
| 1025 | # Give tests the default manifest on Windows (a no-op elsewhere). |
| 1026 | "//build/win:default_exe_manifest", |
| 1027 | ] |
| 1028 | |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 1029 | write_runtime_deps = _runtime_deps_file |
| 1030 | deps += [ ":$_gen_runner_target" ] |
Greg Guterman | 50ed4b4 | 2021-04-08 01:15:11 | [diff] [blame] | 1031 | |
Kevin Marshall | 2352936 | 2022-02-23 16:50:36 | [diff] [blame] | 1032 | if (!defined(data_deps)) { |
| 1033 | data_deps = [] |
| 1034 | } |
| 1035 | |
| 1036 | data_deps += [ "//testing:test_scripts_shared" ] |
| 1037 | |
Greg Guterman | 50ed4b4 | 2021-04-08 01:15:11 | [diff] [blame] | 1038 | if (use_rts) { |
Greg Guterman | 50ed4b4 | 2021-04-08 01:15:11 | [diff] [blame] | 1039 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 1040 | } |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 1041 | } |
| 1042 | } else { |
| 1043 | # This is a catch-all clause for NaCl toolchains and other random |
| 1044 | # configurations that might define tests; test() in these configs |
| 1045 | # will just define the underlying executables. |
| 1046 | assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb, |
| 1047 | "use_xvfb should not be defined for a non-linux configuration") |
danakj | ebb9cc4d | 2022-03-04 21:30:11 | [diff] [blame] | 1048 | mixed_test(target_name) { |
| 1049 | target_type = "executable" |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 1050 | forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) |
| 1051 | forward_variables_from(invoker, [ "visibility" ]) |
Dirk Pranke | dd4ff74 | 2020-11-18 19:57:32 | [diff] [blame] | 1052 | if (!defined(deps)) { |
| 1053 | deps = [] |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 1054 | } |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 1055 | |
Kevin Marshall | 2352936 | 2022-02-23 16:50:36 | [diff] [blame] | 1056 | if (!defined(data_deps)) { |
| 1057 | data_deps = [] |
| 1058 | } |
| 1059 | |
| 1060 | data_deps += [ "//testing:test_scripts_shared" ] |
| 1061 | |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 1062 | if (use_rts) { |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 1063 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 1064 | } |
Dirk Pranke | 31e346e | 2020-07-15 00:54:06 | [diff] [blame] | 1065 | } |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 1066 | } |
| 1067 | } |
brettw | edb6ecc | 2016-07-14 23:37:03 | [diff] [blame] | 1068 | |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 1069 | # Defines a type of test that invokes a script to run, rather than |
| 1070 | # invoking an executable. |
| 1071 | # |
| 1072 | # The script must implement the |
| 1073 | # [test executable API](//docs/testing/test_executable_api.md). |
| 1074 | # |
Andrew Grieve | a16222d4 | 2023-02-10 15:31:10 | [diff] [blame] | 1075 | # The template must be passed the `script` parameter, which specifies the path |
| 1076 | # to the script to run. It may optionally be passed a `args` parameter, which |
| 1077 | # can be used to include a list of args to be specified by default. The |
| 1078 | # template will produce a `$root_build_dir/run_$target_name` wrapper and write |
| 1079 | # the runtime_deps for the target to |
| 1080 | # $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in |
| 1081 | # the [test wrapper API](//docs/testing/test_wrapper_api.md). |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 1082 | template("script_test") { |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 1083 | if (use_rts) { |
| 1084 | action("${target_name}__rts_filters") { |
| 1085 | script = "//build/add_rts_filters.py" |
Greg Guterman | 49a4217 | 2021-04-08 22:04:53 | [diff] [blame] | 1086 | rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter" |
Struan Shrimpton | 570c8784 | 2022-08-16 22:30:05 | [diff] [blame] | 1087 | inverted_rts_file = |
| 1088 | "${root_build_dir}/gen/rts/${invoker.target_name}_inverted.filter" |
| 1089 | args = [ |
| 1090 | rebase_path(rts_file, root_build_dir), |
| 1091 | rebase_path(inverted_rts_file, root_build_dir), |
| 1092 | ] |
| 1093 | outputs = [ |
| 1094 | rts_file, |
| 1095 | inverted_rts_file, |
| 1096 | ] |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 1100 | generate_wrapper(target_name) { |
| 1101 | testonly = true |
| 1102 | wrapper_script = "${root_build_dir}/bin/run_${target_name}" |
| 1103 | |
| 1104 | executable = "//testing/test_env.py" |
| 1105 | |
| 1106 | executable_args = |
| 1107 | [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ] |
| 1108 | if (defined(invoker.args)) { |
| 1109 | executable_args += invoker.args |
| 1110 | } |
| 1111 | |
Will Harris | d35e2c9 | 2021-04-07 01:42:02 | [diff] [blame] | 1112 | data = [ invoker.script ] |
Dirk Pranke | 2dd666cd | 2021-03-03 16:57:47 | [diff] [blame] | 1113 | |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 1114 | if (defined(invoker.data)) { |
| 1115 | data += invoker.data |
| 1116 | } |
Jamie Madill | dd60ee6 | 2021-04-13 19:25:52 | [diff] [blame] | 1117 | if (tests_have_location_tags) { |
| 1118 | data += [ "//testing/location_tags.json" ] |
| 1119 | } |
Dirk Pranke | 19a5873 | 2021-03-24 22:26:22 | [diff] [blame] | 1120 | |
Will Harris | d35e2c9 | 2021-04-07 01:42:02 | [diff] [blame] | 1121 | data_deps = [ "//testing:test_scripts_shared" ] |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 1122 | if (defined(invoker.data_deps)) { |
| 1123 | data_deps += invoker.data_deps |
| 1124 | } |
| 1125 | |
| 1126 | forward_variables_from(invoker, |
Andrew Grieve | a16222d4 | 2023-02-10 15:31:10 | [diff] [blame] | 1127 | "*", |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 1128 | TESTONLY_AND_VISIBILITY + [ |
Andrew Grieve | a16222d4 | 2023-02-10 15:31:10 | [diff] [blame] | 1129 | "args", |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 1130 | "data", |
| 1131 | "data_deps", |
| 1132 | "script", |
Andrew Grieve | 1b290e4a2 | 2020-11-24 20:07:01 | [diff] [blame] | 1133 | ]) |
| 1134 | forward_variables_from(invoker, [ "visibility" ]) |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 1135 | |
| 1136 | write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps" |
Greg Guterman | 6963dc08 | 2021-04-07 05:20:59 | [diff] [blame] | 1137 | |
| 1138 | if (use_rts) { |
| 1139 | data_deps += [ ":${invoker.target_name}__rts_filters" ] |
| 1140 | } |
Dirk Pranke | 6188075b | 2020-10-01 19:31:28 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | |
Andrew Grieve | a16222d4 | 2023-02-10 15:31:10 | [diff] [blame] | 1144 | # Defines a test target that uses exit code for pass/fail. |
| 1145 | template("isolated_script_test") { |
| 1146 | script_test(target_name) { |
| 1147 | forward_variables_from(invoker, |
| 1148 | "*", |
| 1149 | TESTONLY_AND_VISIBILITY + [ |
| 1150 | "args", |
| 1151 | "deps", |
| 1152 | "script", |
| 1153 | ]) |
| 1154 | forward_variables_from(invoker, [ "visibility" ]) |
| 1155 | deps = [ "//testing:run_isolated_script_test" ] |
| 1156 | if (defined(invoker.deps)) { |
| 1157 | deps += invoker.deps |
| 1158 | } |
| 1159 | script = "//testing/scripts/run_isolated_script_test.py" |
| 1160 | data = [ invoker.script ] |
| 1161 | args = [ |
| 1162 | rebase_path(invoker.script, root_build_dir), |
| 1163 | "--script-type=bare", |
| 1164 | ] |
| 1165 | if (defined(invoker.args)) { |
| 1166 | args += invoker.args |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | |
brettw | edb6ecc | 2016-07-14 23:37:03 | [diff] [blame] | 1171 | # Test defaults. |
| 1172 | set_defaults("test") { |
| 1173 | if (is_android) { |
| 1174 | configs = default_shared_library_configs |
Yipeng Wang | 158dbc5c | 2017-06-30 18:16:41 | [diff] [blame] | 1175 | configs -= [ "//build/config/android:hide_all_but_jni_onload" ] |
Thomas Anderson | 11c1d982 | 2019-01-15 06:32:59 | [diff] [blame] | 1176 | configs += [ "//build/config/android:hide_all_but_jni" ] |
Andrew Grieve | d5fdf2af | 2022-08-23 07:47:55 | [diff] [blame] | 1177 | |
| 1178 | # Compress sections to stay under 4gb hard limit on 32-bit current_cpu. |
| 1179 | # https://crbug.com/1354616 |
| 1180 | if (symbol_level == 2 && !use_debug_fission && |
| 1181 | (current_cpu == "arm" || current_cpu == "x86")) { |
| 1182 | configs += [ "//build/config:compress_debug_sections" ] |
| 1183 | } |
brettw | edb6ecc | 2016-07-14 23:37:03 | [diff] [blame] | 1184 | } else { |
| 1185 | configs = default_executable_configs |
| 1186 | } |
| 1187 | } |