blob: 9f82d005da39867047db2491969948e35b4faa02 [file] [log] [blame]
Avi Drissmandfd880852022-09-15 20:11:091# Copyright 2015 The Chromium Authors
qsrc6c612c2015-01-13 22:07:482# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
qsrfb5251d12015-01-21 15:57:224
5# ==============================================================================
6# TEST SETUP
7# ==============================================================================
8
Yuke Liao2a9b2f0e2021-04-16 00:40:119import("//build/config/chromeos/args.gni")
Yuke Liaoe703384b2020-07-16 01:05:2410import("//build/config/chromeos/ui_mode.gni")
Kevin Marshall36c602c2021-11-04 16:16:2111import("//build/config/devtools.gni")
Dirk Prankeb404c3b2021-06-14 19:57:5012import("//build/config/gclient_args.gni")
danakj482580a2022-11-18 18:00:5913import("//build/rust/rust_static_library.gni")
Mirko Bonadei4a0df432020-09-08 19:06:0214import("//build_overrides/build.gni")
Yuke Liaoe703384b2020-07-16 01:05:2415
Greg Guterman6963dc082021-04-07 05:20:5916declare_args() {
Dirk Prankeb404c3b2021-06-14 19:57:5017 # Some component repos (e.g. ANGLE) import //testing but do not have
18 # "location_tags.json", and so we don't want to try and upload the tags
19 # for their tests.
20 # And, some build configs may simply turn off generation altogether.
21 tests_have_location_tags = generate_location_tags
Greg Guterman6963dc082021-04-07 05:20:5922}
23
David Dorwin621c5072022-03-30 00:32:5324# On Fuchsia, the test executable has a suffix and is a dependency of the
25# common |target_name| target. For `visibility`, the executable must be
26# specified. Cross-platform targets that include `test` targets in their
27# visibility lists, add `${exec_target_suffix}` immediately after the test
28# target name. This is not necessary when the target is a `source_set`.
29if (is_fuchsia) {
30 exec_target_suffix = "__exec"
31} else {
32 exec_target_suffix = ""
33}
34
jcivellif4462a352017-01-10 04:45:5935if (is_android) {
Ben Pastene1e985542024-09-25 00:41:4236 import("//build/android/test_wrapper/logdog_wrapper.gni")
jcivellif4462a352017-01-10 04:45:5937 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0238 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5039 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5940 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4441 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3242} else if (is_fuchsia) {
Kevin Marshall55fd8522019-10-04 22:47:0143 import("//build/config/fuchsia/generate_runner_scripts.gni")
Wez691dde42023-10-19 17:47:2944 import("//third_party/fuchsia-gn-sdk/src/cmc.gni")
45 import("//third_party/fuchsia-gn-sdk/src/component.gni")
46 import("//third_party/fuchsia-gn-sdk/src/package.gni")
Nico Weberd73c90382022-03-30 20:37:5047} else if (is_chromeos && is_chromeos_device) {
Ben Pastene4c35c572018-04-30 23:21:4848 import("//build/config/chromeos/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3249 import("//build/config/sanitizers/sanitizers.gni")
Dirk Pranke6188075b2020-10-01 19:31:2850 import("//build/util/generate_wrapper.gni")
Dirk Prankedd4ff742020-11-18 19:57:3251} else if (is_ios) {
Jeff Yoonf7f4eb42020-03-06 18:55:3652 import("//build/config/ios/ios_sdk.gni")
53 import("//build/config/ios/ios_test_runner_wrapper.gni")
54 import("//build/config/ios/rules.gni")
Dirk Prankedd4ff742020-11-18 19:57:3255} else {
Dirk Pranke31e346e2020-07-15 00:54:0656 import("//build/config/sanitizers/sanitizers.gni")
57 import("//build/util/generate_wrapper.gni")
58}
59
Paul Semel2c1673cc02024-01-31 15:30:4960# This template represents the core common functionality of a test target
61# on each platform. It includes:
62# * the ability to generate a rust library that includes all .rs files found
63# in sources and depends on that from the test target.
64# * the ability to recognize any declare fuzztests and build runners for them.
danakjebb9cc4d2022-03-04 21:30:1165template("mixed_test") {
66 assert(defined(invoker.target_type) && invoker.target_type != "")
danakjebb9cc4d2022-03-04 21:30:1167
danakjca3cae62023-04-12 15:20:5768 # 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
danakj482580a2022-11-18 18:00:5975 _rs_vars = [
76 "sources", # We split this list into two.
77 "crate_name", # Android test template overrides the crate name.
78 ]
danakjaa85aad2022-03-10 18:45:1079
danakj482580a2022-11-18 18:00:5980 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 != []) {
Daniel Cheng8629dd7e2023-11-22 10:56:4589 # Note: as a weak convention, __ is usually used before a suffix for
90 # internally-generated targets. However, rust_target requires a strict
91 # snake_case name.
danakjc858ce72022-12-20 21:39:5192 if (defined(invoker.crate_name)) {
93 _rust_target_name = "${invoker.crate_name}_rust_objects"
94 } else {
95 _rust_target_name = "${target_name}_rust_objects"
96 }
danakj482580a2022-11-18 18:00:5997
98 # We could automatically add `deps += [ "//testing/rust_gtest_interop" ]`
danakjebb9cc4d2022-03-04 21:30:1199 # if `rs_sources` is non-empty. But we don't automatically provide
100 # //testing/gtest either so it would be asymmetric and could break in that
danakj482580a2022-11-18 18:00:59101 # case. So, we act instead as if //testing/rust_gtest_interop is part of
102 # the //testing/gtest dependency. If you add one, and have `rs_sources`
103 # listed, you get both.
danakjebb9cc4d2022-03-04 21:30:11104 _gtest_is_in_deps = false
danakj482580a2022-11-18 18:00:59105 if (defined(invoker.deps) && invoker.deps != []) {
106 foreach(dep, invoker.deps) {
danakjc1f000c2022-11-18 19:31:06107 if (get_label_info(dep, "label_no_toolchain") ==
108 "//testing/gtest:gtest") {
danakjebb9cc4d2022-03-04 21:30:11109 _gtest_is_in_deps = true
110 }
111 }
112 }
danakj482580a2022-11-18 18:00:59113
114 # TODO(danakj): This could be a rust_source_set perhaps, the point being
115 # that we need to link in all the .o object files inside the library,
116 # instead of dropping unreachable ones during linking (which would drop the
117 # tests). Alternatively we could use a special name suffix or other similar
118 # trick perhaps to ensure that all object files are linked in here.
119 rust_static_library(_rust_target_name) {
120 forward_variables_from(invoker,
121 TESTONLY_AND_VISIBILITY + [
danakjca3cae62023-04-12 15:20:57122 "allow_unsafe",
danakj482580a2022-11-18 18:00:59123 "deps",
danakjca3cae62023-04-12 15:20:57124 "generate_crate_root",
danakj482580a2022-11-18 18:00:59125 "public_deps",
126 ])
127 configs += [ "//build/rust:test" ]
danakjca3cae62023-04-12 15:20:57128 if (defined(invoker.test_crate_root)) {
129 crate_root = invoker.test_crate_root
130 } else {
131 generate_crate_root = true
132 }
danakj482580a2022-11-18 18:00:59133 sources = _rs_sources
Daniel Cheng8629dd7e2023-11-22 10:56:45134 is_gtest_unittests = true
danakjca3cae62023-04-12 15:20:57135
danakj482580a2022-11-18 18:00:59136 if (_gtest_is_in_deps) {
137 deps += [ "//testing/rust_gtest_interop" ]
danakjebb9cc4d2022-03-04 21:30:11138 }
danakj482580a2022-11-18 18:00:59139 }
140 } else {
141 not_needed(invoker, _rs_vars)
142 }
143
Sam Maierb63502c2023-09-15 16:24:41144 if (invoker.target_type == "shared_library_with_jni") {
145 # Needed for shared_library_with_jni. Keeping this import guarded so
146 # that projects who import //testing but not //third_party/jni_zero
147 # don't have issues.
148 import("//third_party/jni_zero/jni_zero.gni")
149 }
danakjca3cae62023-04-12 15:20:57150
Paul Semelffe54d42024-04-16 10:01:30151 _building_fuzztest_fuzzer =
152 defined(invoker.fuzztests) && use_fuzzing_engine && is_linux
153
154 # Fuzz tests are small fuzzers that do not require particularly-powerful
155 # machines to run, so we do not build them when `high_end_fuzzer_targets`
156 # is true and we are building fuzztests in fuzzing mode.
157 if (_building_fuzztest_fuzzer && high_end_fuzzer_targets) {
158 not_needed(invoker, "*")
159 not_needed("*")
160
161 # We still want a reachable target, so make it a no-op empty group. This
162 # will let the fuzzer builders crawl the build graph and invoke ninja in
163 # the same way regardless of GN args.
164 group(target_name) {
danakjebb9cc4d2022-03-04 21:30:11165 }
Paul Semelffe54d42024-04-16 10:01:30166 } else {
167 target(invoker.target_type, target_name) {
168 forward_variables_from(
169 invoker,
170 "*",
171 TESTONLY_AND_VISIBILITY + _rs_vars + [ "fuzztests" ])
172 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
173 sources = _cc_sources
174 if (!defined(deps)) {
175 deps = []
176 }
177 if (!defined(ldflags)) {
178 ldflags = []
179 }
180
181 if (_rs_sources != []) {
182 deps += [ ":${_rust_target_name}" ]
183 }
184 if (defined(invoker.fuzztests)) {
Adrian Taylor6337f562024-06-06 06:18:23185 deps += [
186 "//third_party/fuzztest",
187
188 # The following target contains a static initializer which
189 # will ensure that the code in base/test:test_support
190 # ends up calling through to fuzztest::InitFuzzTest.
Adrian Taylor7f7a7552024-07-01 11:15:33191 "//base/test:confirm_fuzztest_init",
Adrian Taylor6337f562024-06-06 06:18:23192 ]
Paul Semelffe54d42024-04-16 10:01:30193 }
Paul Semel2c1673cc02024-01-31 15:30:49194 }
195 }
196
Paul Semelffe54d42024-04-16 10:01:30197 if (_building_fuzztest_fuzzer && !high_end_fuzzer_targets) {
Paul Semel2c1673cc02024-01-31 15:30:49198 # This test contains fuzztests. We want to package them up in a way
199 # which ClusterFuzz knows how to extract. We need to:
200 # 1) make an executable for each individual fuzz test;
Paul Semelffe54d42024-04-16 10:01:30201 # 2) check that the fuzztests variable is correct.
Paul Semel2c1673cc02024-01-31 15:30:49202 # At present, all this is likely to work only if invoker.target_type
203 # is 'executable', since we generate a wrapper script that assumes so.
204 # At the moment, we aim to fuzz these fuzztests only on Linux so that's
205 # fine. In future we may need to broaden this.
206 if (defined(invoker.output_name)) {
207 _output_name = invoker.output_name
208 } else {
209 _output_name = target_name
210 }
211
Paul Semel2c1673cc02024-01-31 15:30:49212 _fuzzer_binary_extension = ""
213 if (is_win) {
214 _fuzzer_binary_extension = ".exe"
215 }
Paul Semel57d8b1392024-03-28 16:53:02216
217 # This will be the actual name of the fuzzer binary generated by
218 # `target_name`.
219 _fuzzer_binary_name = _output_name + _fuzzer_binary_extension
220 _fuzztest_target_name = target_name
Paul Semel2c1673cc02024-01-31 15:30:49221
222 # Confirming that the "fuzztests =" directive is correct can only
223 # be done on builds where we can confidently run the fuzzing binary.
224 # Let's be conservative about that -- so long as any failures are
225 # spotted by at least one CI bot we should be good.
226 confirm_fuzztest_contents = is_asan || !using_sanitizer
227
228 if (confirm_fuzztest_contents) {
229 # Confirm that the fuzztests GN variable matches with the
230 # actual fuzztests in the binary. The output of this action is unused.
231 # It just exists to fail the build if there's an error.
232 # We only do this on Linux, and not for any sanitizers other than
233 # ASAN, because that's specific for CI to show problems and there
234 # may be unknown problems running the fuzztest binary on other
235 # platforms.
236 _fuzztest_check_action = target_name + "__fuzztest_check"
237 action(_fuzztest_check_action) {
238 deps = [ ":" + _fuzztest_target_name ]
239 testonly = true
240 script = "//testing/libfuzzer/confirm_fuzztests.py"
241 _output_name = "$target_gen_dir/${target_name}__checked.txt"
242 outputs = [ _output_name ]
243
244 args = [
245 "--executable",
246 rebase_path(
247 get_label_info(_fuzztest_target_name, "root_out_dir") +
248 "/" + _fuzzer_binary_name),
249 "--output",
250 rebase_path(_output_name),
251 "--fuzztests",
252 ] + invoker.fuzztests
253 }
254 }
255
256 # Make a wrapper executable for each individual fuzz test
257 foreach(fuzztest_unit, invoker.fuzztests) {
258 _fuzzer_name = target_name + "_" +
259 string_replace(fuzztest_unit, ".", "_") + "_fuzzer"
260
261 # We generate an actual executable because currently our fuzz
262 # builder recipes use `gn refs --type=executable` to find things
263 # to build. Otherwise we could use generate_wrapper or equivalent
264 # to make a python script. We could alter the recipe, or rearrange
265 # deps arragenements so that some other executable depends on these
266 # scripts, but that seems worse. The executable might be more cross-
267 # platform too.
268 _fuzztest_generate_fuzzer = _fuzzer_name + "__generate"
269
270 generated_file(_fuzztest_generate_fuzzer + "_constants") {
271 outputs = [ "$target_gen_dir/$target_name/constants.cpp" ]
Adrian Taylor8c585712024-02-06 18:46:30272
273 # If we're building for libfuzzer, we have to pass -undefok=max_len
274 # etc. for every conceivable libfuzzer argument, so that gtest doesn't
275 # get discombobulated by them. List is from https://llvm.org/docs/LibFuzzer.html
276 if (use_libfuzzer) {
277 known_libfuzzer_args = [
278 "help",
279 "seed",
280 "runs",
281 "max_len",
282 "len_control",
283 "timeout",
284 "rss_limit_mb",
285 "malloc_limit_mb",
286 "timeout_exitcode",
287 "error_exitcode",
288 "max_total_time",
289 "merge",
290 "merge_control_file",
291 "minimize_crash",
292 "reload",
293 "jobs",
294 "workers",
295 "dict",
296 "use_counters",
297 "reduce_inputs",
298 "use_value_profile",
299 "only_ascii",
300 "artifact_prefix",
301 "exact_artifact_path",
302 "print_pcs",
303 "print_final_stats",
304 "detect_leaks",
305 "close_fd_mask",
Adrian Taylor2d40ce022024-02-09 17:40:24306 "fork",
Adrian Taylor8c585712024-02-06 18:46:30307 ]
308 fuzzer_args =
309 "-undefok=" + string_join(",", known_libfuzzer_args) + " "
310 } else {
311 fuzzer_args = ""
312 }
Paul Semelddefa5d2024-05-31 17:24:01313 fuzzer_args += "--fuzz=$fuzztest_unit --corpus_database=\"\""
Adrian Taylor8c585712024-02-06 18:46:30314 contents = [ "const char* kFuzzerArgs = \"${fuzzer_args}\"; const char* kFuzzerBinary = \"${_fuzzer_binary_name}\";" ]
Paul Semel2c1673cc02024-01-31 15:30:49315 }
316
Paul Semel1e37ba62024-03-27 20:48:12317 _fuzzer_target_name = target_name
Paul Semel2c1673cc02024-01-31 15:30:49318 executable(_fuzztest_generate_fuzzer) {
319 testonly = true
Paul Semel1e37ba62024-03-27 20:48:12320 data_deps = [
321 ":" + _fuzztest_target_name,
322 ":" + _fuzzer_target_name,
323 ]
Paul Semel2c1673cc02024-01-31 15:30:49324 deps = [
Paul Semel2c1673cc02024-01-31 15:30:49325 "//testing/libfuzzer:individual_fuzztest_wrapper",
326 ":" + _fuzztest_generate_fuzzer + "_constants",
327 ]
328 if (confirm_fuzztest_contents) {
329 deps += [ ":" + _fuzztest_check_action ]
330 }
331 output_name = _fuzzer_name
332 sources =
333 get_target_outputs(":" + _fuzztest_generate_fuzzer + "_constants")
334 write_runtime_deps = "$root_build_dir/${_fuzzer_name}.runtime_deps"
335 }
336 }
danakjebb9cc4d2022-03-04 21:30:11337 }
338}
339
qsrfb5251d12015-01-21 15:57:22340# Define a test as an executable (or apk on Android) with the "testonly" flag
341# set.
agrieve62ab00282016-04-05 02:03:45342# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30343# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj482580a2022-11-18 18:00:59344# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:56345# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson318cd692022-03-28 08:12:06346# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
Greg Thompsonfd269652022-10-28 12:06:55347# runner shard rather than the default shard for the ELF runner when
348# assembling the test component. This is useful, for example, to use the
349# elf_test_ambient_exec_runner for tests that require
350# job_policy_ambient_mark_vmo_exec.
351# fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component()
352# targets that this test package contains.
Mirko Bonadei15522bc2020-09-16 20:38:39353# is_xctest: (iOS, optional) whether to build the executable as XCTest.
354# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
355# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43356# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
357# network requests during the test.
Adrian Taylora20bc5a2024-01-29 23:22:26358# fuzztests: a list of instances of the FUZZ_TEST macro to
Adrian Taylor62dbea52023-10-25 20:29:16359# include fuzzing tests alongside unit tests. This introduces an
360# extra dependency and also creates additional metadata so that our
361# fuzzing infrastructure can find and run such tests.
Adrian Taylora20bc5a2024-01-29 23:22:26362# This should be a list of the test names, for example
363# fuzztests = [ "MyTestClass.MyTestName" ]
qsrfb5251d12015-01-21 15:57:22364template("test") {
Andrew Grieve1b290e4a22020-11-24 20:07:01365 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39366 if (!is_ios) {
367 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
368 "is_xctest can be set only for iOS builds")
369 }
Stefano Duo4128b6b2021-08-02 21:24:43370 if (!is_android) {
371 assert(!defined(invoker.allow_cleartext_traffic),
372 "allow_cleartext_traffic can be set only for Android tests")
373 }
374
qsrfb5251d12015-01-21 15:57:22375 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30376 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
377
Peter Kotwicz10742f82021-04-15 22:32:50378 _use_default_launcher =
379 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
380 if (!defined(invoker.use_raw_android_executable)) {
381 # Checkouts where build_with_chromium == false often have a custom GN
382 # template wrapper around test() which sets use_default_launcher == false.
383 # Set the _use_raw_android_executable default so that test() targets which
384 # do not use the custom wrapper
385 # (1) Do not cause "gn gen" to fail
386 # (2) Do not need to be moved into if(build_with_chromium) block.
387 _use_raw_android_executable =
388 !build_with_chromium && _use_default_launcher
389 } else {
390 not_needed([ "_use_default_launcher" ])
391 _use_raw_android_executable = invoker.use_raw_android_executable
392 }
qsrfb5251d12015-01-21 15:57:22393
agrieve67855de2016-03-30 14:46:01394 # output_name is used to allow targets with the same name but in different
395 # packages to still produce unique runner scripts.
396 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26397 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01398 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26399 }
agrieve62ab00282016-04-05 02:03:45400
agrieveb355ad152016-04-19 03:45:23401 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42402 _wrapper_script_vars = [
Jamie Madill73b9af332022-08-03 19:27:47403 "android_test_runner_script",
Haiyang Pan88eaf7502024-03-21 22:08:11404 "extra_args",
agrievee41ae190d2016-04-25 14:12:51405 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42406 "shard_timeout",
agrievee41ae190d2016-04-25 14:12:51407 ]
agrieve3ac557f02016-04-12 15:52:00408
jbudorickced2a252016-06-09 16:38:54409 assert(_use_raw_android_executable || enable_java_templates)
410
agrieve62ab00282016-04-05 02:03:45411 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49412 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
413
agrieve62ab00282016-04-05 02:03:45414 _exec_target = "${target_name}__exec"
415 _dist_target = "${target_name}__dist"
416 _exec_output =
417 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
danakj505b7f062023-07-05 19:02:02418 _crate_name = "${target_name}"
agrieve62ab00282016-04-05 02:03:45419
danakjebb9cc4d2022-03-04 21:30:11420 mixed_test(_exec_target) {
421 target_type = "executable"
422
danakj505b7f062023-07-05 19:02:02423 # Use a crate name that avoids creating a warning due to double
424 # underscore (ie. `__`).
425 crate_name = _crate_name
426
danakje94f40d2022-02-16 18:13:53427 # Configs will always be defined since we set_defaults in
428 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45429 configs = []
Dirk Pranke19a58732021-03-24 22:26:22430 forward_variables_from(
431 invoker,
432 "*",
433 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
434 "data_deps",
435 "extra_dist_files",
436 ])
agrieve62ab00282016-04-05 02:03:45437
438 # Thanks to the set_defaults() for test(), configs are initialized with
439 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59440 configs -= [
441 "//build/config:shared_library_config",
442 "//build/config/android:hide_all_but_jni",
443 ]
agrieve62ab00282016-04-05 02:03:45444 configs += [ "//build/config:executable_config" ]
445
Dirk Pranke19a58732021-03-24 22:26:22446 if (defined(invoker.data_deps)) {
447 data_deps = invoker.data_deps
448 } else {
449 data_deps = []
450 }
451 if (!defined(data)) {
452 data = []
453 }
Jamie Madilldd60ee62021-04-13 19:25:52454 if (tests_have_location_tags) {
455 data += [ "//testing/location_tags.json" ]
456 }
Adrian Taylor62dbea52023-10-25 20:29:16457 if (!defined(deps)) {
458 deps = []
459 }
Dirk Pranke19a58732021-03-24 22:26:22460
agrieve62ab00282016-04-05 02:03:45461 # Don't output to the root or else conflict with the group() below.
462 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:45463 }
464
465 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45466 dist_dir = "$root_out_dir/$target_name"
467 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22468 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45469 if (defined(invoker.extra_dist_files)) {
470 extra_files = invoker.extra_dist_files
471 }
472 }
473 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38474 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49475 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38476 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45477 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43478 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45479 "android_manifest",
agrievec6811b422016-06-23 02:25:09480 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27481 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55482 "app_as_shared_lib",
Haiyang Pan5c01df52024-03-11 16:47:23483 "keystore_name",
484 "keystore_password",
485 "keystore_path",
Andrew Grieve43f24fd02022-04-06 23:04:04486 "loadable_module_deps",
Haiyang Pan5c01df52024-03-11 16:47:23487 "loadable_modules",
Tibor Goldschwendt95db95d2019-06-17 20:32:02488 "min_sdk_version",
Haiyang Pan5c01df52024-03-11 16:47:23489 "product_config_java_packages",
huapenglc35ba6e2016-05-25 23:08:07490 "proguard_configs",
491 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45492 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02493 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45494 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56495 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45496 ]
Siddhartha764226b2018-03-13 02:32:55497
Andrew Grieveee8aa44d2022-09-23 17:14:38498 _add_unwind_tables_in_apk =
499 defined(invoker.add_unwind_tables_in_apk) &&
500 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55501
Siddhartha764226b2018-03-13 02:32:55502 # Adds the unwind tables from unstripped binary as an asset file in the
503 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55504 if (_add_unwind_tables_in_apk) {
Alison Gale47d1537d2024-04-19 21:31:46505 # TODO(crbug.com/40833600): Remove generation of v1 unwind asset when
Tushar Agarwaldcafb622022-11-30 17:32:27506 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`.
Andrew Grieveee8aa44d2022-09-23 17:14:38507 _unwind_table_name = "${_library_target_name}_unwind_v1"
508 unwind_table_v1(_unwind_table_name) {
509 library_target = ":$_library_target_name"
510 }
511
Arthur Sonzogni54424e92022-09-23 13:30:45512 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38513 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
514 unwind_table_v2(_unwind_table_v2_name) {
515 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45516 }
517 }
518
Andrew Grieveee8aa44d2022-09-23 17:14:38519 _unwind_table_asset_name = "${target_name}__unwind_assets"
520 android_assets(_unwind_table_asset_name) {
521 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
522 disable_compression = true
523 deps = [ ":$_unwind_table_name" ]
524 if (use_android_unwinder_v2) {
525 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
526 deps += [ ":$_unwind_table_v2_name" ]
527 }
Siddhartha764226b2018-03-13 02:32:55528 }
529 }
530
Sam Maierbc320a9482023-05-17 19:44:16531 _generate_final_jni =
532 !defined(invoker.generate_final_jni) || invoker.generate_final_jni
Andrew Grieveee8aa44d2022-09-23 17:14:38533 mixed_test(_library_target_name) {
Sam Maierbc320a9482023-05-17 19:44:16534 if (_generate_final_jni) {
535 target_type = "shared_library_with_jni"
536 java_targets = [ ":$_apk_target_name" ]
537 } else {
538 target_type = "shared_library"
539 }
danakjebb9cc4d2022-03-04 21:30:11540
danakj98e073722022-02-24 21:01:49541 # Configs will always be defined since we set_defaults in
542 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45543 configs = [] # Prevent list overwriting warning.
544 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45545
jbudorickd29ecfa72016-11-18 22:45:42546 forward_variables_from(
547 invoker,
548 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55549 [
550 "configs",
551 "deps",
552 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07553 TESTONLY_AND_VISIBILITY)
554
danakj482580a2022-11-18 18:00:59555 # Use a crate name that avoids creating a warning due to double
556 # underscore (ie. `__`).
557 crate_name = _library_crate_name
558
Peter Wen2052bd12020-12-03 20:15:07559 # Native targets do not need to depend on java targets. Filter them out
560 # so that the shared library can be built without needing to wait for
561 # dependent java targets.
Paul Semel2c1673cc02024-01-31 15:30:49562 if (!defined(deps)) {
563 deps = []
564 }
Peter Wen2052bd12020-12-03 20:15:07565 if (defined(invoker.deps)) {
Adrian Taylor62dbea52023-10-25 20:29:16566 deps += filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07567 }
agrieve62ab00282016-04-05 02:03:45568
Peter Kotwiczb9957d62021-04-12 21:09:43569 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37570 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45571 }
572 }
Andrew Grieveee8aa44d2022-09-23 17:14:38573 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54574 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38575 shared_library = ":$_library_target_name"
Sam Maierbc320a9482023-05-17 19:44:16576 if (_generate_final_jni) {
577 srcjar_deps = [ "${shared_library}__jni_registration" ]
Sam Maierbc320a9482023-05-17 19:44:16578 }
agrieve62ab00282016-04-05 02:03:45579 apk_name = invoker.target_name
580 if (defined(invoker.output_name)) {
581 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45582 }
agrieveb355ad152016-04-19 03:45:23583
Daniel Bratellfdda4652019-01-31 15:45:54584 if (defined(invoker.deps)) {
585 deps = invoker.deps
586 } else {
587 deps = []
588 }
Andrew Grieve43f24fd02022-04-06 23:04:04589 if (defined(loadable_module_deps)) {
590 deps += loadable_module_deps
591 }
Daniel Bratellfdda4652019-01-31 15:45:54592
jcivellif4462a352017-01-10 04:45:59593 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43594 if (_use_default_launcher) {
595 deps += [ "//base/test:test_support_java" ]
596 }
jcivellif4462a352017-01-10 04:45:59597
Siddhartha764226b2018-03-13 02:32:55598 if (defined(_unwind_table_asset_name)) {
599 deps += [ ":${_unwind_table_asset_name}" ]
600 }
agrieve62ab00282016-04-05 02:03:45601 }
Andrew Grievee1dc23f2019-10-22 16:26:36602 }
agrieve62ab00282016-04-05 02:03:45603
Andrew Grievee1dc23f2019-10-22 16:26:36604 test_runner_script(_test_runner_target) {
605 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce8443922016-12-15 19:57:57606
Andrew Grievee1dc23f2019-10-22 16:26:36607 if (_use_raw_android_executable) {
608 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34609 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36610 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38611 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36612 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47613
614 # Dep needed for the test runner .runtime_deps file to pick up data
615 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38616 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45617 }
Andrew Grievee1dc23f2019-10-22 16:26:36618 test_name = _output_name
619 test_suite = _output_name
620 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26621 }
622
Andrew Grieve7ca6de32019-10-18 03:57:47623 # Create a wrapper script rather than using a group() in order to ensure
624 # "ninja $target_name" always works. If this was a group(), then GN would
625 # not create a top-level alias for it if a target exists in another
626 # directory with the same $target_name.
627 # Also - bots run this script directly for "components_perftests".
628 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01629 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47630 executable = "$root_build_dir/bin/run_$_output_name"
631 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22632 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40633 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47634 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40635 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47636 # Dep needed for the swarming .isolate file to pick up data
637 # deps from the forward_variables_from(invoker, "*") on the library.
638 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38639 ":$_apk_target_name",
640 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47641 ]
agrieve62ab00282016-04-05 02:03:45642 }
Dirk Pranke19a58732021-03-24 22:26:22643
644 if (defined(invoker.data_deps)) {
645 data_deps = invoker.data_deps
646 } else {
647 data_deps = []
648 }
Kevin Marshall23529362022-02-23 16:50:36649
650 data_deps += [ "//testing:test_scripts_shared" ]
651
Jamie Madilldd60ee62021-04-13 19:25:52652 if (tests_have_location_tags) {
653 data = [ "//testing/location_tags.json" ]
654 }
agrieve1a02e582015-10-15 21:35:39655 }
Scott Graham4c4cdc52017-05-29 20:45:03656 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30657 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
658
Scott Graham4c4cdc52017-05-29 20:45:03659 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42660 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42661 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb42022-04-05 12:30:35662 _program_name = get_label_info(":${_exec_target}", "name")
danakj505b7f062023-07-05 19:02:02663 _crate_name = _output_name
Scott Graham4c4cdc52017-05-29 20:45:03664
Greg Thompson2f1e3762022-10-17 19:53:44665 # Generate a CML fragment that provides the program name.
666 _test_program_fragment_target = "${target_name}_program-fragment"
667 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
668 generated_file(_test_program_fragment_target) {
669 contents = {
670 program = {
671 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28672 }
Greg Thompson26516592021-12-16 08:34:45673 }
Greg Thompson2f1e3762022-10-17 19:53:44674 outputs = [ _test_program_fragment ]
675 output_conversion = "json"
Greg Thompson9765eeb42022-04-05 12:30:35676 }
677
Greg Thompson2f1e3762022-10-17 19:53:44678 _test_runner_shard =
679 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
680 if (defined(invoker.test_runner_shard)) {
681 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02682 }
683
Greg Thompson2f1e3762022-10-17 19:53:44684 # Collate the complete set of elements to include in the test component's
685 # manifest.
David Dorwin2c4872c2023-02-22 20:00:56686
Greg Thompson2f1e3762022-10-17 19:53:44687 _manifest_fragments = [
Greg Thompson2f1e3762022-10-17 19:53:44688 _test_program_fragment,
689 _test_runner_shard,
690 ]
691
David Dorwin2c4872c2023-02-22 20:00:56692 # Select the Fuchsia test realm in which to run the test.
693 if (defined(invoker.run_as_chromium_system_test) &&
694 invoker.run_as_chromium_system_test) {
695 _manifest_fragments += [
696 "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
697 "//build/config/fuchsia/test/system_test_minimum.shard.test-cml",
698 ]
699 } else {
700 _manifest_fragments += [
701 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
702 "//build/config/fuchsia/test/minimum.shard.test-cml",
703 ]
704 }
705
Zijie He78d978e2023-07-19 21:46:42706 if (is_asan) {
Alison Gale59c007a2024-04-20 03:05:40707 # TODO(crbug.com/40276216): Remove the extra cml segment for asan.
Zijie He78d978e2023-07-19 21:46:42708 _manifest_fragments +=
709 [ "//build/config/fuchsia/test/asan_options.shard.test-cml" ]
710 }
711
Greg Thompson2f1e3762022-10-17 19:53:44712 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
713 _merged_manifest_name = "${_output_name}.cml"
714
715 if (defined(invoker.additional_manifest_fragments)) {
716 _manifest_fragments += invoker.additional_manifest_fragments
717 }
718
719 # Generate the test component manifest from the specified elements.
720 _test_component_manifest_target = "${target_name}_component-manifest"
721 cmc_merge(_test_component_manifest_target) {
722 sources = _manifest_fragments
723 output_name = "${_merged_manifest_name}"
724 deps = [ ":${_test_program_fragment_target}" ]
725 }
726
727 # Define the test component, dependent on the generated manifest, and the
728 # test executable target.
729 _test_component_target = "${target_name}_component"
730 fuchsia_component(_test_component_target) {
731 deps = [ ":$_test_component_manifest_target" ]
732 data_deps = [ ":$_exec_target" ]
733 manifest = _test_component_manifest
734 visibility = [ ":*" ]
735 }
736
737 _test_component_targets = [ ":${_test_component_target}" ]
738
Wez6879f8a2021-09-07 20:27:02739 # Define components for each entry in |additional_manifests|, if any. Since
740 # manifests may themselves depend-on the outputs of |deps|, these components
741 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02742 if (defined(invoker.additional_manifests)) {
743 foreach(filename, invoker.additional_manifests) {
744 _additional_component_target =
745 target_name + "_" + get_path_info(filename, "name")
746 _test_component_targets += [ ":${_additional_component_target}" ]
747 fuchsia_component(_additional_component_target) {
748 forward_variables_from(invoker, [ "testonly" ])
749 data_deps = [ ":$_exec_target" ]
750 visibility = [ ":*" ]
751 manifest = filename
752
753 # Depend on |invoker.deps|, in case it includes a dependency that
754 # creates this additional component's manifest.
755 if (defined(invoker.deps)) {
756 deps = invoker.deps
757 }
758 }
759 }
760 }
761
762 # Define the package target that will bundle the test and additional
763 # components and their data.
764 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21765 forward_variables_from(invoker,
766 [
767 "excluded_files",
768 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30769 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21770 ])
Wez6879f8a2021-09-07 20:27:02771 package_name = _output_name
772 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21773
Greg Thompsonfd269652022-10-28 12:06:55774 if (defined(invoker.fuchsia_package_deps)) {
775 deps += invoker.fuchsia_package_deps
776 }
Bryant Chandlerc40f2672023-01-27 23:33:30777 if (!defined(excluded_paths)) {
778 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21779 }
Bryant Chandlerc40f2672023-01-27 23:33:30780 excluded_paths += [
781 "${devtools_root_location}/*",
782 "*.git/*",
783 "*.svn/*",
784 "*.hg/*",
785 ]
Sarah Pham80972efc2022-05-31 17:40:15786 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30787 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15788 }
Wez6879f8a2021-09-07 20:27:02789 }
790
791 # |target_name| refers to the package-runner rule, so that building
792 # "base_unittests" will build not only the executable, component, and
793 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25794 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53795 forward_variables_from(invoker,
796 [
Kevin Marshall5fadadd2021-10-16 00:08:25797 "data",
798 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53799 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25800 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53801 ])
Kevin Marshall5fadadd2021-10-16 00:08:25802
Chong Guc6bfdf62021-10-20 23:37:00803 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15804 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25805 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42806
Kevin Marshall5fadadd2021-10-16 00:08:25807 if (!defined(deps)) {
808 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52809 }
Kevin Marshall5fadadd2021-10-16 00:08:25810 if (defined(invoker.deps)) {
811 deps += invoker.deps
812 }
Greg Guterman6963dc082021-04-07 05:20:59813
Kevin Marshall5fadadd2021-10-16 00:08:25814 if (!defined(data)) {
815 data = []
816 }
817 if (tests_have_location_tags) {
818 data += [ "//testing/location_tags.json" ]
819 }
820
821 if (!defined(data_deps)) {
822 data_deps = []
823 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28824
Kevin Marshall23529362022-02-23 16:50:36825 data_deps += [ "//testing:test_scripts_shared" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42826 }
827
danakjebb9cc4d2022-03-04 21:30:11828 mixed_test(_exec_target) {
829 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01830 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42831 output_name = _exec_target
danakj505b7f062023-07-05 19:02:02832
Adrian Taylor62dbea52023-10-25 20:29:16833 if (!defined(deps)) {
834 deps = []
835 }
Adrian Taylor62dbea52023-10-25 20:29:16836
danakj505b7f062023-07-05 19:02:02837 # Use a crate name that avoids creating a warning due to double
838 # underscore (ie. `__`).
839 crate_name = _crate_name
Scott Graham4c4cdc52017-05-29 20:45:03840 }
dpranke2a294622015-08-07 05:23:01841 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30842 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46843 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30844
Rohit Raof9b096d2019-09-09 22:26:23845 declare_args() {
Zhaoyang Li34fb05e2023-07-25 18:02:00846 # Keep the unittest-as-xctest functionality defaulted to off for
847 # local builds and test executions.
Rohit Raof9b096d2019-09-09 22:26:23848 enable_run_ios_unittests_with_xctest = false
849 }
850
sdefresne012857872016-03-16 10:55:37851 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27852
Jeff Yoonf7f4eb42020-03-06 18:55:36853 _wrapper_output_name = "run_${target_name}"
854 ios_test_runner_wrapper(_wrapper_output_name) {
855 forward_variables_from(invoker,
856 [
Cameron Higgins69d21be2023-12-04 17:57:21857 "clones",
Jeff Yoonf7f4eb42020-03-06 18:55:36858 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36859 "deps",
860 "executable_args",
861 "retries",
Jeff Yoonf7f4eb42020-03-06 18:55:36862 ])
863
864 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
865
866 if (!defined(executable_args)) {
867 executable_args = []
868 }
869 executable_args += [
870 "--app",
871 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
872 ]
873
874 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22875
876 if (!defined(data)) {
877 data = []
878 }
Jamie Madilldd60ee62021-04-13 19:25:52879 if (tests_have_location_tags) {
880 data += [ "//testing/location_tags.json" ]
881 }
Jeff Yoonf7f4eb42020-03-06 18:55:36882 }
883
sdefresne012857872016-03-16 10:55:37884 _resources_bundle_data = target_name + "_resources_bundle_data"
885
886 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34887 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22888 sources = [ "//testing/gtest_ios/Default.png" ]
889 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01890 }
891
Mirko Bonadei15522bc2020-09-16 20:38:39892 force_xctest = enable_run_ios_unittests_with_xctest ||
893 (defined(invoker.is_xctest) && invoker.is_xctest)
894
danakjfae603fc602022-11-18 18:40:22895 mixed_test(_test_target) {
896 if (force_xctest) {
897 target_type = "ios_xctest_test"
898 } else {
899 target_type = "ios_app_bundle"
900 }
dpranke2a294622015-08-07 05:23:01901 testonly = true
sdefresnea828c282016-05-30 18:04:20902
Mirko Bonadei15522bc2020-09-16 20:38:39903 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23904 xctest_module_target = "//base/test:google_test_runner"
905 }
906
Andrew Grieve1b290e4a22020-11-24 20:07:01907 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13908
909 # Provide sensible defaults in case invoker did not define any of those
910 # required variables.
sdefresne05b97ca2016-06-08 07:19:46911 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13912 info_plist = "//testing/gtest_ios/unittest-Info.plist"
913 }
sdefresne9e147e02016-06-07 00:10:13914
Sylvain Defresne8c0fc9a2023-10-16 17:26:13915 bundle_identifier = shared_bundle_id_for_test_apps
dpranke2a294622015-08-07 05:23:01916
sdefresne047490e2016-07-22 08:49:34917 if (!defined(bundle_deps)) {
918 bundle_deps = []
919 }
920 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36921
922 if (!defined(data_deps)) {
923 data_deps = []
924 }
925
Kevin Marshall23529362022-02-23 16:50:36926 data_deps += [ "//testing:test_scripts_shared" ]
927
Jeff Yoonf7f4eb42020-03-06 18:55:36928 # Include the generate_wrapper as part of data_deps
929 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46930 write_runtime_deps = _runtime_deps_file
Adrian Taylor62dbea52023-10-25 20:29:16931 if (!defined(deps)) {
932 deps = []
933 }
dpranke2a294622015-08-07 05:23:01934 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11935 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
936 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30937 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
938
Yuke Liao2a9b2f0e2021-04-16 00:40:11939 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32940
Benjamin Pastene3bce864e2018-04-14 01:16:32941 _gen_runner_target = "${target_name}__runner"
942 _runtime_deps_file =
943 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
944 "/" + get_label_info(target_name, "name") + ".runtime_deps"
945
Xinan Linf3f5aa52023-08-24 22:07:28946 if (is_skylab && (defined(tast_attr_expr) || defined(tast_tests) ||
947 defined(tast_disabled_tests))) {
948 generate_skylab_tast_filter(_gen_runner_target) {
Yuke Liaoacb74b12021-04-23 23:37:34949 }
Xinan Lin6be01252021-06-25 23:07:36950 } else {
951 generate_runner_script(_gen_runner_target) {
Xinan Linf3f5aa52023-08-24 22:07:28952 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Xinan Lin6be01252021-06-25 23:07:36953 test_exe = invoker.target_name
954 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34955
Xinan Lin6be01252021-06-25 23:07:36956 if (is_chromeos_lacros) {
957 # At build time, Lacros tests don't know whether they'll run on VM or
958 # HW, and instead, these flags are specified at runtime when invoking
959 # the generated runner script.
960 skip_generating_board_args = true
961 }
Greg Guterman6963dc082021-04-07 05:20:59962
Xinan Lin6be01252021-06-25 23:07:36963 if (tests_have_location_tags) {
964 data = [ "//testing/location_tags.json" ]
965 }
Greg Guterman6963dc082021-04-07 05:20:59966 }
Benjamin Pastene3bce864e2018-04-14 01:16:32967 }
968
danakjebb9cc4d2022-03-04 21:30:11969 mixed_test(target_name) {
970 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01971 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
972 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32973 if (!defined(deps)) {
974 deps = []
975 }
976 if (!defined(data)) {
977 data = []
978 }
979
Ben Pastene41041782019-02-16 04:21:58980 # We use a special trigger script for CrOS hardware tests.
981 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
982
Benjamin Pastene3bce864e2018-04-14 01:16:32983 write_runtime_deps = _runtime_deps_file
984 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37985 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc082021-04-07 05:20:59986
Kevin Marshall23529362022-02-23 16:50:36987 if (!defined(data_deps)) {
988 data_deps = []
989 }
990
991 data_deps += [ "//testing:test_scripts_shared" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32992 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11993 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24994 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
995 _executable = target_name
996 _gen_runner_target = "${target_name}__runner"
997
Yuke Liao32af4242020-07-16 21:48:02998 if (defined(invoker.use_xvfb)) {
999 _use_xvfb = invoker.use_xvfb
1000 } else {
1001 _use_xvfb = false
1002 }
1003
Yuke Liaod037abc2020-10-06 22:48:221004 # When use_xvfb is set by the invoker, it indicates that running this test
1005 # target requires a window, and in lacros build, ash-chrome serves as the
1006 # display server. Note that even though the tests themselves do not require
1007 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
1008 # because ash-chrome is based on x11.
1009 _use_ash_chrome = _use_xvfb
1010
Yuke Liaoe703384b2020-07-16 01:05:241011 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:241012 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:021013
Yuke Liao2e4953cf2020-07-26 19:20:191014 data = []
Will Harrisd35e2c92021-04-07 01:42:021015 data_deps = [ "//testing:test_scripts_shared" ]
1016
Yuke Liao32af4242020-07-16 21:48:021017 if (_use_xvfb) {
1018 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:221019 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:021020 } else {
1021 executable = "//testing/test_env.py"
1022 }
Jamie Madilldd60ee62021-04-13 19:25:521023 if (tests_have_location_tags) {
1024 data += [ "//testing/location_tags.json" ]
1025 }
Yuke Liao32af4242020-07-16 21:48:021026
Yuke Liaoe703384b2020-07-16 01:05:241027 executable_args = [
Yuke Liao32af4242020-07-16 21:48:021028 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:391029 "test",
Yuke Liaoe703384b2020-07-16 01:05:241030 "@WrappedPath(./${_executable})",
1031 "--test-launcher-bot-mode",
1032 ]
Yuke Liao32af4242020-07-16 21:48:021033
Yuke Liaof540c742020-07-29 16:28:341034 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:371035 executable_args += [ "--ash-chrome-path" ]
1036
1037 # Can't use --ash-chrome-path=path because WrappedPath
1038 # won't be expanded for that usage.
1039 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:391040 }
1041
Yuke Liaoe703384b2020-07-16 01:05:241042 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:001043 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241044 }
1045 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001046 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241047 }
1048 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001049 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241050 }
1051 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001052 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241053 }
Ian Struiksma2ebc3222023-05-24 00:28:461054 if (fail_on_san_warnings) {
1055 executable_args += [ "--fail-san=1" ]
1056 }
Yuke Liaoe703384b2020-07-16 01:05:241057
Takuto Ikuta38ebd0e2022-01-19 17:56:221058 data += [ "//build/lacros/test_runner.py" ]
Yuke Liaoe703384b2020-07-16 01:05:241059 }
1060
danakjebb9cc4d2022-03-04 21:30:111061 mixed_test(target_name) {
1062 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011063 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1064 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:241065 if (!defined(deps)) {
1066 deps = []
1067 }
1068
Yuke Liaod037abc2020-10-06 22:48:221069 if (!defined(data_deps)) {
1070 data_deps = []
1071 }
1072
Kevin Marshall23529362022-02-23 16:50:361073 data_deps += [ "//testing:test_scripts_shared" ]
1074
Yuke Liaoe703384b2020-07-16 01:05:241075 write_runtime_deps = _runtime_deps_file
1076 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:221077 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:561078 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:221079 }
Yuke Liaoe703384b2020-07-16 01:05:241080 }
Dirk Prankedd4ff742020-11-18 19:57:321081 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:301082 if (is_mac || is_win) {
1083 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
1084 }
1085
Dirk Prankedd4ff742020-11-18 19:57:321086 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
1087 _executable = target_name
1088 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:061089
Dirk Prankedd4ff742020-11-18 19:57:321090 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
1091 _use_xvfb = invoker.use_xvfb
1092 } else {
1093 _use_xvfb = false
1094 }
1095
1096 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:321097 wrapper_script = "$root_build_dir/bin/run_" + _executable
1098
1099 data = []
Will Harrisd35e2c92021-04-07 01:42:021100 data_deps = [ "//testing:test_scripts_shared" ]
1101
Dirk Prankedd4ff742020-11-18 19:57:321102 if (_use_xvfb) {
1103 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:061104 } else {
Dirk Prankedd4ff742020-11-18 19:57:321105 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:061106 }
Jamie Madilldd60ee62021-04-13 19:25:521107 if (tests_have_location_tags) {
1108 data += [ "//testing/location_tags.json" ]
1109 }
Dirk Pranke31e346e2020-07-15 00:54:061110
Dirk Prankedd4ff742020-11-18 19:57:321111 executable_args = [
1112 "@WrappedPath(./${_executable})",
1113 "--test-launcher-bot-mode",
1114 ]
1115 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:001116 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:061117 }
Dirk Prankedd4ff742020-11-18 19:57:321118 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001119 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321120 }
1121 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001122 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321123 }
1124 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001125 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321126 }
Ian Struiksma2ebc3222023-05-24 00:28:461127 if (fail_on_san_warnings) {
1128 executable_args += [ "--fail-san=1" ]
1129 }
Dirk Pranke31e346e2020-07-15 00:54:061130 }
1131
danakjebb9cc4d2022-03-04 21:30:111132 mixed_test(target_name) {
1133 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011134 forward_variables_from(invoker,
1135 "*",
1136 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
1137 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:061138 if (!defined(deps)) {
1139 deps = []
1140 }
1141
Dirk Pranke31e346e2020-07-15 00:54:061142 deps += [
1143 # Give tests the default manifest on Windows (a no-op elsewhere).
1144 "//build/win:default_exe_manifest",
1145 ]
1146
Dirk Prankedd4ff742020-11-18 19:57:321147 write_runtime_deps = _runtime_deps_file
1148 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111149
Kevin Marshall23529362022-02-23 16:50:361150 if (!defined(data_deps)) {
1151 data_deps = []
1152 }
1153
1154 data_deps += [ "//testing:test_scripts_shared" ]
Dirk Prankedd4ff742020-11-18 19:57:321155 }
1156 } else {
1157 # This is a catch-all clause for NaCl toolchains and other random
1158 # configurations that might define tests; test() in these configs
1159 # will just define the underlying executables.
1160 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1161 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc4d2022-03-04 21:30:111162 mixed_test(target_name) {
1163 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011164 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1165 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321166 if (!defined(deps)) {
1167 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061168 }
Greg Guterman6963dc082021-04-07 05:20:591169
Kevin Marshall23529362022-02-23 16:50:361170 if (!defined(data_deps)) {
1171 data_deps = []
1172 }
1173
1174 data_deps += [ "//testing:test_scripts_shared" ]
Dirk Pranke31e346e2020-07-15 00:54:061175 }
qsrfb5251d12015-01-21 15:57:221176 }
1177}
brettwedb6ecc2016-07-14 23:37:031178
Dirk Pranke6188075b2020-10-01 19:31:281179# Defines a type of test that invokes a script to run, rather than
1180# invoking an executable.
1181#
1182# The script must implement the
1183# [test executable API](//docs/testing/test_executable_api.md).
1184#
Andrew Grievea16222d42023-02-10 15:31:101185# The template must be passed the `script` parameter, which specifies the path
1186# to the script to run. It may optionally be passed a `args` parameter, which
1187# can be used to include a list of args to be specified by default. The
1188# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1189# the runtime_deps for the target to
1190# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1191# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Ben Pastene1e985542024-09-25 00:41:421192#
1193# Variables:
1194# script: Path to underlying test script.
1195# args: Args to the test script.
1196# enable_android_wrapper: (optional) If true, the test will get wrapped in the
1197# logdog_wrapper on Android, which will stream logcats from the device.
1198# enable_cros_wrapper: (optional) If true, the test will get wrapped by the
1199# cros_test_wrapper on ChromeOS, which will prep the device for testing.
Dirk Pranke6188075b2020-10-01 19:31:281200template("script_test") {
Ben Pastene1e985542024-09-25 00:41:421201 _enable_logdog_wrapper = defined(invoker.enable_android_wrapper) &&
1202 invoker.enable_android_wrapper && is_android
1203 _enable_cros_wrapper =
1204 defined(invoker.enable_cros_wrapper) && invoker.enable_cros_wrapper &&
1205 is_chromeos_ash && is_chromeos_device
1206 assert(!(_enable_logdog_wrapper && _enable_cros_wrapper),
1207 "The logdog and cros_test wrappers are mutually exclusive")
Dirk Pranke6188075b2020-10-01 19:31:281208
Ben Pastene1e985542024-09-25 00:41:421209 _shared_data = [ invoker.script ]
1210 if (defined(invoker.data)) {
1211 _shared_data += invoker.data
1212 }
1213 if (tests_have_location_tags) {
1214 _shared_data += [ "//testing/location_tags.json" ]
1215 }
Dirk Pranke6188075b2020-10-01 19:31:281216
Ben Pastene1e985542024-09-25 00:41:421217 _shared_data_deps = [ "//testing:test_scripts_shared" ]
1218 if (defined(invoker.data_deps)) {
1219 _shared_data_deps += invoker.data_deps
1220 }
1221
1222 _wrapped_script =
1223 "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")"
1224 if (_enable_logdog_wrapper) {
1225 logdog_wrapper_script_test(target_name) {
1226 testonly = true
1227 args = [ _wrapped_script ]
1228 if (defined(invoker.args)) {
1229 args += invoker.args
1230 }
1231 data = _shared_data
1232 data_deps = _shared_data_deps
1233
1234 forward_variables_from(invoker,
1235 "*",
1236 TESTONLY_AND_VISIBILITY + [
1237 "args",
1238 "data",
1239 "data_deps",
1240 "script",
1241 ])
Dirk Pranke6188075b2020-10-01 19:31:281242 }
Ben Pastene1e985542024-09-25 00:41:421243 } else if (_enable_cros_wrapper) {
1244 cros_test_wrapper_script_test(target_name) {
1245 args = [ _wrapped_script ]
1246 if (defined(invoker.args)) {
1247 args += invoker.args
1248 }
1249 data = _shared_data
1250 data_deps = _shared_data_deps
Dirk Pranke6188075b2020-10-01 19:31:281251
Ben Pastene1e985542024-09-25 00:41:421252 forward_variables_from(invoker,
1253 "*",
1254 TESTONLY_AND_VISIBILITY + [
1255 "args",
1256 "data",
1257 "data_deps",
1258 "script",
1259 ])
Dirk Pranke6188075b2020-10-01 19:31:281260 }
Ben Pastene1e985542024-09-25 00:41:421261 } else {
1262 generate_wrapper(target_name) {
1263 testonly = true
1264 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1265
1266 executable = "//testing/test_env.py"
1267
1268 executable_args = [ _wrapped_script ]
1269 if (defined(invoker.args)) {
1270 executable_args += invoker.args
1271 }
1272
1273 data = _shared_data
1274 data_deps = _shared_data_deps
1275
1276 forward_variables_from(invoker,
1277 "*",
1278 TESTONLY_AND_VISIBILITY + [
1279 "args",
1280 "data",
1281 "data_deps",
1282 "script",
1283 ])
1284 forward_variables_from(invoker, [ "visibility" ])
1285
1286 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
Jamie Madilldd60ee62021-04-13 19:25:521287 }
Dirk Pranke6188075b2020-10-01 19:31:281288 }
1289}
1290
Andrew Grievea16222d42023-02-10 15:31:101291# Defines a test target that uses exit code for pass/fail.
1292template("isolated_script_test") {
1293 script_test(target_name) {
1294 forward_variables_from(invoker,
1295 "*",
1296 TESTONLY_AND_VISIBILITY + [
1297 "args",
Peter Wena9f19582024-10-08 18:16:161298 "data",
Andrew Grievea16222d42023-02-10 15:31:101299 "deps",
1300 "script",
1301 ])
1302 forward_variables_from(invoker, [ "visibility" ])
1303 deps = [ "//testing:run_isolated_script_test" ]
1304 if (defined(invoker.deps)) {
1305 deps += invoker.deps
1306 }
1307 script = "//testing/scripts/run_isolated_script_test.py"
1308 data = [ invoker.script ]
Peter Wena9f19582024-10-08 18:16:161309 if (defined(invoker.data)) {
1310 data += invoker.data
1311 }
Andrew Grievea16222d42023-02-10 15:31:101312 args = [
1313 rebase_path(invoker.script, root_build_dir),
1314 "--script-type=bare",
1315 ]
1316 if (defined(invoker.args)) {
1317 args += invoker.args
1318 }
1319 }
1320}
1321
brettwedb6ecc2016-07-14 23:37:031322# Test defaults.
1323set_defaults("test") {
1324 if (is_android) {
Mohamed Heikaldd52b452024-09-10 17:10:501325 # Should be kept in sync with set_defaults("cronet_test") in
1326 # //components/cronet/android/cronet_test_templates.gni
1327 # LINT.IfChange
brettwedb6ecc2016-07-14 23:37:031328 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411329 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591330 configs += [ "//build/config/android:hide_all_but_jni" ]
Mohamed Heikaldd52b452024-09-10 17:10:501331
1332 # LINT.ThenChange(/components/cronet/android/cronet_test_templates.gni)
brettwedb6ecc2016-07-14 23:37:031333 } else {
1334 configs = default_executable_configs
1335 }
1336}