[go: nahoru, domu]

blob: e0a233b1fc0ea2ad58a1f7e82fde7863f35a3ada [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 Guterman6963dc02021-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 Guterman6963dc02021-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) {
36 import("//build/config/android/config.gni")
Charlie Hud98dc692021-12-08 01:01:0237 import("//build/config/android/create_unwind_table.gni")
James Cook209256f2018-12-07 18:40:5038 import("//build/config/android/extract_unwind_tables.gni")
jcivellif4462a352017-01-10 04:45:5939 import("//build/config/android/rules.gni")
Abhishek Arya2f5f7342018-06-13 16:59:4440 import("//build/config/sanitizers/sanitizers.gni")
Dirk Prankedd4ff742020-11-18 19:57:3241} else if (is_fuchsia) {
mark a. foltze185ab2fa2023-11-06 21:21:2042 import("//build/config/cast.gni")
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.
danakjebb9cc42022-03-04 21:30:1165template("mixed_test") {
66 assert(defined(invoker.target_type) && invoker.target_type != "")
danakjebb9cc42022-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 Cheng8629dd72023-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" ]`
danakjebb9cc42022-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.
danakjebb9cc42022-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") {
danakjebb9cc42022-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 Cheng8629dd72023-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" ]
danakjebb9cc42022-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 }
danakj482580a2022-11-18 18:00:59150 target(invoker.target_type, target_name) {
Paul Semel2c1673cc02024-01-31 15:30:49151 forward_variables_from(invoker,
152 "*",
153 TESTONLY_AND_VISIBILITY + _rs_vars + [ "fuzztests" ])
danakj482580a2022-11-18 18:00:59154 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
155 sources = _cc_sources
156 if (!defined(deps)) {
157 deps = []
158 }
danakjca3cae62023-04-12 15:20:57159 if (!defined(ldflags)) {
160 ldflags = []
161 }
162
danakj482580a2022-11-18 18:00:59163 if (_rs_sources != []) {
164 deps += [ ":${_rust_target_name}" ]
danakjebb9cc42022-03-04 21:30:11165 }
Paul Semel2c1673cc02024-01-31 15:30:49166 if (defined(invoker.fuzztests)) {
167 deps += [ "//third_party/fuzztest" ]
168 }
169 }
170
171 if (defined(invoker.fuzztests) && use_fuzzing_engine && is_linux) {
172 # This test contains fuzztests. We want to package them up in a way
173 # which ClusterFuzz knows how to extract. We need to:
174 # 1) make an executable for each individual fuzz test;
175 # 2) name the main executable something specific so that ClusterFuzz
176 # knows how to extract it
177 # 3) check that the fuzztests variable is correct.
178 # At present, all this is likely to work only if invoker.target_type
179 # is 'executable', since we generate a wrapper script that assumes so.
180 # At the moment, we aim to fuzz these fuzztests only on Linux so that's
181 # fine. In future we may need to broaden this.
182 if (defined(invoker.output_name)) {
183 _output_name = invoker.output_name
184 } else {
185 _output_name = target_name
186 }
187
188 # Make a second copy of the test target, with a
189 # special binary name so that ClusterFuzz knows to unzip it.
190 # The extension .fuzztest_runner is the magical string;
191 # ClusterFuzz unzips anything with a filename extension which isn't
192 # on its blocklist.
193 # Once ClusterFuzz knows how to understand and unzip runtime_deps,
194 # we can remove this.
195 # (https://github.com/google/clusterfuzz/pull/3515 and follow up work).
196 # An alternative here is using a symlink but this seems less
197 # cross-platform, so for now let's just make a copy.
198 _fuzzer_binary_extension = ""
199 if (is_win) {
200 _fuzzer_binary_extension = ".exe"
201 }
202 _fuzzer_binary_name =
203 _output_name + ".fuzztest_runner" + _fuzzer_binary_extension
204 _fuzztest_target_name = target_name + "__fuzztest_runner"
205 copy(_fuzztest_target_name) {
206 deps = [ ":" + target_name ]
207 sources = [ "$root_out_dir/$_output_name" + _fuzzer_binary_extension ]
208 outputs = [ "$root_out_dir/$_fuzzer_binary_name" ]
209 testonly = true
210 }
211
212 # Confirming that the "fuzztests =" directive is correct can only
213 # be done on builds where we can confidently run the fuzzing binary.
214 # Let's be conservative about that -- so long as any failures are
215 # spotted by at least one CI bot we should be good.
216 confirm_fuzztest_contents = is_asan || !using_sanitizer
217
218 if (confirm_fuzztest_contents) {
219 # Confirm that the fuzztests GN variable matches with the
220 # actual fuzztests in the binary. The output of this action is unused.
221 # It just exists to fail the build if there's an error.
222 # We only do this on Linux, and not for any sanitizers other than
223 # ASAN, because that's specific for CI to show problems and there
224 # may be unknown problems running the fuzztest binary on other
225 # platforms.
226 _fuzztest_check_action = target_name + "__fuzztest_check"
227 action(_fuzztest_check_action) {
228 deps = [ ":" + _fuzztest_target_name ]
229 testonly = true
230 script = "//testing/libfuzzer/confirm_fuzztests.py"
231 _output_name = "$target_gen_dir/${target_name}__checked.txt"
232 outputs = [ _output_name ]
233
234 args = [
235 "--executable",
236 rebase_path(
237 get_label_info(_fuzztest_target_name, "root_out_dir") +
238 "/" + _fuzzer_binary_name),
239 "--output",
240 rebase_path(_output_name),
241 "--fuzztests",
242 ] + invoker.fuzztests
243 }
244 }
245
246 # Make a wrapper executable for each individual fuzz test
247 foreach(fuzztest_unit, invoker.fuzztests) {
248 _fuzzer_name = target_name + "_" +
249 string_replace(fuzztest_unit, ".", "_") + "_fuzzer"
250
251 # We generate an actual executable because currently our fuzz
252 # builder recipes use `gn refs --type=executable` to find things
253 # to build. Otherwise we could use generate_wrapper or equivalent
254 # to make a python script. We could alter the recipe, or rearrange
255 # deps arragenements so that some other executable depends on these
256 # scripts, but that seems worse. The executable might be more cross-
257 # platform too.
258 _fuzztest_generate_fuzzer = _fuzzer_name + "__generate"
259
260 generated_file(_fuzztest_generate_fuzzer + "_constants") {
261 outputs = [ "$target_gen_dir/$target_name/constants.cpp" ]
Adrian Taylor8c585712024-02-06 18:46:30262
263 # If we're building for libfuzzer, we have to pass -undefok=max_len
264 # etc. for every conceivable libfuzzer argument, so that gtest doesn't
265 # get discombobulated by them. List is from https://llvm.org/docs/LibFuzzer.html
266 if (use_libfuzzer) {
267 known_libfuzzer_args = [
268 "help",
269 "seed",
270 "runs",
271 "max_len",
272 "len_control",
273 "timeout",
274 "rss_limit_mb",
275 "malloc_limit_mb",
276 "timeout_exitcode",
277 "error_exitcode",
278 "max_total_time",
279 "merge",
280 "merge_control_file",
281 "minimize_crash",
282 "reload",
283 "jobs",
284 "workers",
285 "dict",
286 "use_counters",
287 "reduce_inputs",
288 "use_value_profile",
289 "only_ascii",
290 "artifact_prefix",
291 "exact_artifact_path",
292 "print_pcs",
293 "print_final_stats",
294 "detect_leaks",
295 "close_fd_mask",
Adrian Taylor2d40ce022024-02-09 17:40:24296 "fork",
Adrian Taylor8c585712024-02-06 18:46:30297 ]
298 fuzzer_args =
299 "-undefok=" + string_join(",", known_libfuzzer_args) + " "
300 } else {
301 fuzzer_args = ""
302 }
303 fuzzer_args += "--fuzz=$fuzztest_unit"
304 contents = [ "const char* kFuzzerArgs = \"${fuzzer_args}\"; const char* kFuzzerBinary = \"${_fuzzer_binary_name}\";" ]
Paul Semel2c1673cc02024-01-31 15:30:49305 }
306
307 executable(_fuzztest_generate_fuzzer) {
308 testonly = true
309 data_deps = [ ":" + _fuzztest_target_name ]
310 deps = [
311 # Depend on fuzzing_engine so that our recipes know to build all
312 # these wrapper script targets.
313 "//testing/libfuzzer:fuzzing_engine",
314 "//testing/libfuzzer:individual_fuzztest_wrapper",
315 ":" + _fuzztest_generate_fuzzer + "_constants",
316 ]
317 if (confirm_fuzztest_contents) {
318 deps += [ ":" + _fuzztest_check_action ]
319 }
320 output_name = _fuzzer_name
321 sources =
322 get_target_outputs(":" + _fuzztest_generate_fuzzer + "_constants")
323 write_runtime_deps = "$root_build_dir/${_fuzzer_name}.runtime_deps"
324 }
325 }
danakjebb9cc42022-03-04 21:30:11326 }
327}
328
qsrfb5251d12015-01-21 15:57:22329# Define a test as an executable (or apk on Android) with the "testonly" flag
330# set.
agrieve62ab00282016-04-05 02:03:45331# Variable:
Dirk Pranke79d065d2020-08-29 03:28:30332# use_xvfb: (optional) whether to run the executable under Xvfb.
danakj482580a2022-11-18 18:00:59333# use_raw_android_executable: Use executable() rather than android_apk().
ynovikov389d9e442016-05-27 02:34:56334# use_native_activity: Test implements ANativeActivity_onCreate().
Greg Thompson318cd692022-03-28 08:12:06335# test_runner_shard: (Fuchsia, optional): for CFv2 tests, use the given test
Greg Thompsonfd269652022-10-28 12:06:55336# runner shard rather than the default shard for the ELF runner when
337# assembling the test component. This is useful, for example, to use the
338# elf_test_ambient_exec_runner for tests that require
339# job_policy_ambient_mark_vmo_exec.
340# fuchsia_package_deps: (Fuchsia, optional) List of fuchsia_component()
341# targets that this test package contains.
Mirko Bonadei15522bc2020-09-16 20:38:39342# is_xctest: (iOS, optional) whether to build the executable as XCTest.
343# Similar to the GN arg 'enable_run_ios_unittests_with_xctest' but
344# for build targets.
Stefano Duo4128b6b2021-08-02 21:24:43345# allow_cleartext_traffic: (Android, optional) whether to allow cleartext
346# network requests during the test.
Adrian Taylora20bc5a2024-01-29 23:22:26347# fuzztests: a list of instances of the FUZZ_TEST macro to
Adrian Taylor62dbea52023-10-25 20:29:16348# include fuzzing tests alongside unit tests. This introduces an
349# extra dependency and also creates additional metadata so that our
350# fuzzing infrastructure can find and run such tests.
Adrian Taylora20bc5a2024-01-29 23:22:26351# This should be a list of the test names, for example
352# fuzztests = [ "MyTestClass.MyTestName" ]
qsrfb5251d12015-01-21 15:57:22353template("test") {
Andrew Grieve1b290e4a22020-11-24 20:07:01354 testonly = true
Mirko Bonadei15522bc2020-09-16 20:38:39355 if (!is_ios) {
356 assert(!defined(invoker.is_xctest) || !invoker.is_xctest,
357 "is_xctest can be set only for iOS builds")
358 }
Stefano Duo4128b6b2021-08-02 21:24:43359 if (!is_android) {
360 assert(!defined(invoker.allow_cleartext_traffic),
361 "allow_cleartext_traffic can be set only for Android tests")
362 }
363
qsrfb5251d12015-01-21 15:57:22364 if (is_android) {
Dirk Pranke79d065d2020-08-29 03:28:30365 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
366
Peter Kotwicz10742f82021-04-15 22:32:50367 _use_default_launcher =
368 !defined(invoker.use_default_launcher) || invoker.use_default_launcher
369 if (!defined(invoker.use_raw_android_executable)) {
370 # Checkouts where build_with_chromium == false often have a custom GN
371 # template wrapper around test() which sets use_default_launcher == false.
372 # Set the _use_raw_android_executable default so that test() targets which
373 # do not use the custom wrapper
374 # (1) Do not cause "gn gen" to fail
375 # (2) Do not need to be moved into if(build_with_chromium) block.
376 _use_raw_android_executable =
377 !build_with_chromium && _use_default_launcher
378 } else {
379 not_needed([ "_use_default_launcher" ])
380 _use_raw_android_executable = invoker.use_raw_android_executable
381 }
qsrfb5251d12015-01-21 15:57:22382
agrieve67855de2016-03-30 14:46:01383 # output_name is used to allow targets with the same name but in different
384 # packages to still produce unique runner scripts.
385 _output_name = invoker.target_name
mikecase56d80d72015-06-03 00:57:26386 if (defined(invoker.output_name)) {
agrieve67855de2016-03-30 14:46:01387 _output_name = invoker.output_name
mikecase56d80d72015-06-03 00:57:26388 }
agrieve62ab00282016-04-05 02:03:45389
agrieveb355ad152016-04-19 03:45:23390 _test_runner_target = "${_output_name}__test_runner_script"
jbudorickd29ecfa72016-11-18 22:45:42391 _wrapper_script_vars = [
Jamie Madill73b9af32022-08-03 19:27:47392 "android_test_runner_script",
agrievee41ae1902016-04-25 14:12:51393 "ignore_all_data_deps",
jbudorickd29ecfa72016-11-18 22:45:42394 "shard_timeout",
agrievee41ae1902016-04-25 14:12:51395 ]
agrieve3ac557f02016-04-12 15:52:00396
jbudorickced2a252016-06-09 16:38:54397 assert(_use_raw_android_executable || enable_java_templates)
398
agrieve62ab00282016-04-05 02:03:45399 if (_use_raw_android_executable) {
Peter Kotwicz13a827a62021-04-22 22:34:49400 not_needed(invoker, [ "add_unwind_tables_in_apk" ])
401
agrieve62ab00282016-04-05 02:03:45402 _exec_target = "${target_name}__exec"
403 _dist_target = "${target_name}__dist"
404 _exec_output =
405 "$target_out_dir/${invoker.target_name}/${invoker.target_name}"
danakj505b7f02023-07-05 19:02:02406 _crate_name = "${target_name}"
agrieve62ab00282016-04-05 02:03:45407
danakjebb9cc42022-03-04 21:30:11408 mixed_test(_exec_target) {
409 target_type = "executable"
410
danakj505b7f02023-07-05 19:02:02411 # Use a crate name that avoids creating a warning due to double
412 # underscore (ie. `__`).
413 crate_name = _crate_name
414
danakje94f40d2022-02-16 18:13:53415 # Configs will always be defined since we set_defaults in
416 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45417 configs = []
Dirk Pranke19a58732021-03-24 22:26:22418 forward_variables_from(
419 invoker,
420 "*",
421 TESTONLY_AND_VISIBILITY + _wrapper_script_vars + [
422 "data_deps",
423 "extra_dist_files",
424 ])
agrieve62ab00282016-04-05 02:03:45425
426 # Thanks to the set_defaults() for test(), configs are initialized with
427 # the default shared_library configs rather than executable configs.
Thomas Anderson11c1d9822019-01-15 06:32:59428 configs -= [
429 "//build/config:shared_library_config",
430 "//build/config/android:hide_all_but_jni",
431 ]
agrieve62ab00282016-04-05 02:03:45432 configs += [ "//build/config:executable_config" ]
433
Dirk Pranke19a58732021-03-24 22:26:22434 if (defined(invoker.data_deps)) {
435 data_deps = invoker.data_deps
436 } else {
437 data_deps = []
438 }
439 if (!defined(data)) {
440 data = []
441 }
Jamie Madilldd60ee62021-04-13 19:25:52442 if (tests_have_location_tags) {
443 data += [ "//testing/location_tags.json" ]
444 }
Adrian Taylor62dbea52023-10-25 20:29:16445 if (!defined(deps)) {
446 deps = []
447 }
Dirk Pranke19a58732021-03-24 22:26:22448
agrieve62ab00282016-04-05 02:03:45449 # Don't output to the root or else conflict with the group() below.
450 output_name = rebase_path(_exec_output, root_out_dir)
agrieve62ab00282016-04-05 02:03:45451 }
452
453 create_native_executable_dist(_dist_target) {
agrieve62ab00282016-04-05 02:03:45454 dist_dir = "$root_out_dir/$target_name"
455 binary = _exec_output
Nico Weber852532f2020-01-28 18:17:22456 deps = [ ":$_exec_target" ]
agrieve62ab00282016-04-05 02:03:45457 if (defined(invoker.extra_dist_files)) {
458 extra_files = invoker.extra_dist_files
459 }
460 }
461 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38462 _library_target_name = "${target_name}__library"
danakj98e073722022-02-24 21:01:49463 _library_crate_name = "${target_name}_library"
Andrew Grieveee8aa44d2022-09-23 17:14:38464 _apk_target_name = "${target_name}__apk"
agrieve62ab00282016-04-05 02:03:45465 _apk_specific_vars = [
Stefano Duo4128b6b2021-08-02 21:24:43466 "allow_cleartext_traffic",
agrieve62ab00282016-04-05 02:03:45467 "android_manifest",
agrievec6811b422016-06-23 02:25:09468 "android_manifest_dep",
Peter Kotwiczab1b5422021-03-30 22:58:27469 "android_manifest_template",
Clark DuVall1bee5322020-06-10 05:51:55470 "app_as_shared_lib",
Benoît Lizéd8b8f742019-11-07 12:50:07471 "product_config_java_packages",
Andrew Grieve43f24fd02022-04-06 23:04:04472 "loadable_modules",
473 "loadable_module_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02474 "min_sdk_version",
huapenglc35ba6e2016-05-25 23:08:07475 "proguard_configs",
476 "proguard_enabled",
Fred Mello0cc91c62019-08-24 01:53:45477 "srcjar_deps",
Tibor Goldschwendt95db95d2019-06-17 20:32:02478 "target_sdk_version",
agrieve62ab00282016-04-05 02:03:45479 "use_default_launcher",
ynovikov389d9e442016-05-27 02:34:56480 "use_native_activity",
agrieve62ab00282016-04-05 02:03:45481 ]
Siddhartha764226b2018-03-13 02:32:55482
Andrew Grieveee8aa44d2022-09-23 17:14:38483 _add_unwind_tables_in_apk =
484 defined(invoker.add_unwind_tables_in_apk) &&
485 invoker.add_unwind_tables_in_apk && target_cpu == "arm"
Andrew Grieved5fdf2af2022-08-23 07:47:55486
Siddhartha764226b2018-03-13 02:32:55487 # Adds the unwind tables from unstripped binary as an asset file in the
488 # apk, if |add_unwind_tables_in_apk| is specified by the test.
Andrew Grieved5fdf2af2022-08-23 07:47:55489 if (_add_unwind_tables_in_apk) {
Andrew Grieveee8aa44d2022-09-23 17:14:38490 # TODO(crbug.com/1315603): Remove generation of v1 unwind asset when
Tushar Agarwaldcafb622022-11-30 17:32:27491 # `CFIBacktraceAndroid` is replaced with `ChromeUnwinderAndroid`.
Andrew Grieveee8aa44d2022-09-23 17:14:38492 _unwind_table_name = "${_library_target_name}_unwind_v1"
493 unwind_table_v1(_unwind_table_name) {
494 library_target = ":$_library_target_name"
495 }
496
Arthur Sonzogni54424e92022-09-23 13:30:45497 if (use_android_unwinder_v2) {
Andrew Grieveee8aa44d2022-09-23 17:14:38498 _unwind_table_v2_name = "${_library_target_name}_unwind_v2"
499 unwind_table_v2(_unwind_table_v2_name) {
500 library_target = ":$_library_target_name"
Arthur Sonzogni54424e92022-09-23 13:30:45501 }
502 }
503
Andrew Grieveee8aa44d2022-09-23 17:14:38504 _unwind_table_asset_name = "${target_name}__unwind_assets"
505 android_assets(_unwind_table_asset_name) {
506 sources = [ "$target_out_dir/$_unwind_table_name/$unwind_table_asset_v1_filename" ]
507 disable_compression = true
508 deps = [ ":$_unwind_table_name" ]
509 if (use_android_unwinder_v2) {
510 sources += [ "$target_out_dir/$_unwind_table_v2_name/$unwind_table_asset_v2_filename" ]
511 deps += [ ":$_unwind_table_v2_name" ]
512 }
Siddhartha764226b2018-03-13 02:32:55513 }
514 }
515
Sam Maierbc320a9482023-05-17 19:44:16516 _generate_final_jni =
517 !defined(invoker.generate_final_jni) || invoker.generate_final_jni
Andrew Grieveee8aa44d2022-09-23 17:14:38518 mixed_test(_library_target_name) {
Sam Maierbc320a9482023-05-17 19:44:16519 if (_generate_final_jni) {
520 target_type = "shared_library_with_jni"
521 java_targets = [ ":$_apk_target_name" ]
522 } else {
523 target_type = "shared_library"
524 }
danakjebb9cc42022-03-04 21:30:11525
danakj98e073722022-02-24 21:01:49526 # Configs will always be defined since we set_defaults in
527 # BUILDCONFIG.gn.
agrieve62ab00282016-04-05 02:03:45528 configs = [] # Prevent list overwriting warning.
529 configs = invoker.configs
agrieve62ab00282016-04-05 02:03:45530
jbudorickd29ecfa72016-11-18 22:45:42531 forward_variables_from(
532 invoker,
533 "*",
Andrew Grieved5fdf2af2022-08-23 07:47:55534 [
535 "configs",
536 "deps",
537 ] + _apk_specific_vars + _wrapper_script_vars +
Peter Wen2052bd12020-12-03 20:15:07538 TESTONLY_AND_VISIBILITY)
539
danakj482580a2022-11-18 18:00:59540 # Use a crate name that avoids creating a warning due to double
541 # underscore (ie. `__`).
542 crate_name = _library_crate_name
543
Peter Wen2052bd12020-12-03 20:15:07544 # Native targets do not need to depend on java targets. Filter them out
545 # so that the shared library can be built without needing to wait for
546 # dependent java targets.
Paul Semel2c1673cc02024-01-31 15:30:49547 if (!defined(deps)) {
548 deps = []
549 }
Peter Wen2052bd12020-12-03 20:15:07550 if (defined(invoker.deps)) {
Adrian Taylor62dbea52023-10-25 20:29:16551 deps += filter_exclude(invoker.deps, java_target_patterns)
Peter Wen2052bd12020-12-03 20:15:07552 }
agrieve62ab00282016-04-05 02:03:45553
Peter Kotwiczb9957d62021-04-12 21:09:43554 if (_use_default_launcher) {
Tom Andersonce772fa2018-05-30 22:20:37555 deps += [ "//testing/android/native_test:native_test_native_code" ]
agrieve62ab00282016-04-05 02:03:45556 }
557 }
Andrew Grieveee8aa44d2022-09-23 17:14:38558 unittest_apk(_apk_target_name) {
Daniel Bratellfdda4652019-01-31 15:45:54559 forward_variables_from(invoker, _apk_specific_vars)
Andrew Grieveee8aa44d2022-09-23 17:14:38560 shared_library = ":$_library_target_name"
Sam Maierbc320a9482023-05-17 19:44:16561 if (_generate_final_jni) {
562 srcjar_deps = [ "${shared_library}__jni_registration" ]
Sam Maierbc320a9482023-05-17 19:44:16563 }
agrieve62ab00282016-04-05 02:03:45564 apk_name = invoker.target_name
565 if (defined(invoker.output_name)) {
566 apk_name = invoker.output_name
agrieve62ab00282016-04-05 02:03:45567 }
agrieveb355ad152016-04-19 03:45:23568
Daniel Bratellfdda4652019-01-31 15:45:54569 if (defined(invoker.deps)) {
570 deps = invoker.deps
571 } else {
572 deps = []
573 }
Andrew Grieve43f24fd02022-04-06 23:04:04574 if (defined(loadable_module_deps)) {
575 deps += loadable_module_deps
576 }
Daniel Bratellfdda4652019-01-31 15:45:54577
jcivellif4462a352017-01-10 04:45:59578 # Add the Java classes so that each target does not have to do it.
Peter Kotwiczb9957d62021-04-12 21:09:43579 if (_use_default_launcher) {
580 deps += [ "//base/test:test_support_java" ]
581 }
jcivellif4462a352017-01-10 04:45:59582
Siddhartha764226b2018-03-13 02:32:55583 if (defined(_unwind_table_asset_name)) {
584 deps += [ ":${_unwind_table_asset_name}" ]
585 }
agrieve62ab00282016-04-05 02:03:45586 }
Andrew Grievee1dc23f2019-10-22 16:26:36587 }
agrieve62ab00282016-04-05 02:03:45588
Andrew Grievee1dc23f2019-10-22 16:26:36589 test_runner_script(_test_runner_target) {
590 forward_variables_from(invoker, _wrapper_script_vars)
estevensonce844392016-12-15 19:57:57591
Andrew Grievee1dc23f2019-10-22 16:26:36592 if (_use_raw_android_executable) {
593 executable_dist_dir = "$root_out_dir/$_dist_target"
John Budorickd5dccb22020-02-01 02:16:34594 data_deps = [ ":$_exec_target" ]
Andrew Grievee1dc23f2019-10-22 16:26:36595 } else {
Andrew Grieveee8aa44d2022-09-23 17:14:38596 apk_target = ":$_apk_target_name"
Andrew Grievee1dc23f2019-10-22 16:26:36597 incremental_apk = incremental_install
Andrew Grieve7ca6de32019-10-18 03:57:47598
599 # Dep needed for the test runner .runtime_deps file to pick up data
600 # deps from the forward_variables_from(invoker, "*") on the library.
Andrew Grieveee8aa44d2022-09-23 17:14:38601 data_deps = [ ":$_library_target_name" ]
agrieve62ab00282016-04-05 02:03:45602 }
Andrew Grievee1dc23f2019-10-22 16:26:36603 test_name = _output_name
604 test_suite = _output_name
605 test_type = "gtest"
mikecase56d80d72015-06-03 00:57:26606 }
607
Andrew Grieve7ca6de32019-10-18 03:57:47608 # Create a wrapper script rather than using a group() in order to ensure
609 # "ninja $target_name" always works. If this was a group(), then GN would
610 # not create a top-level alias for it if a target exists in another
611 # directory with the same $target_name.
612 # Also - bots run this script directly for "components_perftests".
613 generate_wrapper(target_name) {
Andrew Grieve1b290e4a22020-11-24 20:07:01614 forward_variables_from(invoker, [ "visibility" ])
Andrew Grieve7ca6de32019-10-18 03:57:47615 executable = "$root_build_dir/bin/run_$_output_name"
616 wrapper_script = "$root_build_dir/$_output_name"
Nico Weber852532f2020-01-28 18:17:22617 deps = [ ":$_test_runner_target" ]
jbudorick686094f62017-05-04 21:52:40618 if (_use_raw_android_executable) {
Andrew Grieve7ca6de32019-10-18 03:57:47619 deps += [ ":$_dist_target" ]
jbudorick686094f62017-05-04 21:52:40620 } else {
Andrew Grieve7ca6de32019-10-18 03:57:47621 # Dep needed for the swarming .isolate file to pick up data
622 # deps from the forward_variables_from(invoker, "*") on the library.
623 deps += [
Andrew Grieveee8aa44d2022-09-23 17:14:38624 ":$_apk_target_name",
625 ":$_library_target_name",
Andrew Grieve7ca6de32019-10-18 03:57:47626 ]
agrieve62ab00282016-04-05 02:03:45627 }
Dirk Pranke19a58732021-03-24 22:26:22628
629 if (defined(invoker.data_deps)) {
630 data_deps = invoker.data_deps
631 } else {
632 data_deps = []
633 }
Kevin Marshall23529362022-02-23 16:50:36634
635 data_deps += [ "//testing:test_scripts_shared" ]
636
Jamie Madilldd60ee62021-04-13 19:25:52637 if (tests_have_location_tags) {
638 data = [ "//testing/location_tags.json" ]
639 }
agrieve1a02e582015-10-15 21:35:39640 }
Scott Graham4c4cdc52017-05-29 20:45:03641 } else if (is_fuchsia) {
Dirk Pranke79d065d2020-08-29 03:28:30642 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
643
Scott Graham4c4cdc52017-05-29 20:45:03644 _output_name = invoker.target_name
Kevin Marshallf35fa5f2018-01-29 19:24:42645 _pkg_target = "${_output_name}_pkg"
Kevin Marshallf35fa5f2018-01-29 19:24:42646 _exec_target = "${_output_name}__exec"
Greg Thompson9765eeb2022-04-05 12:30:35647 _program_name = get_label_info(":${_exec_target}", "name")
danakj505b7f02023-07-05 19:02:02648 _crate_name = _output_name
Scott Graham4c4cdc52017-05-29 20:45:03649
Greg Thompson2f1e3762022-10-17 19:53:44650 # Generate a CML fragment that provides the program name.
651 _test_program_fragment_target = "${target_name}_program-fragment"
652 _test_program_fragment = "${target_out_dir}/${target_name}_program.test-cml"
653 generated_file(_test_program_fragment_target) {
654 contents = {
655 program = {
656 binary = _program_name
Kevin Marshall2ec60032022-05-09 17:38:28657 }
Greg Thompson26516592021-12-16 08:34:45658 }
Greg Thompson2f1e3762022-10-17 19:53:44659 outputs = [ _test_program_fragment ]
660 output_conversion = "json"
Greg Thompson9765eeb2022-04-05 12:30:35661 }
662
Greg Thompson2f1e3762022-10-17 19:53:44663 _test_runner_shard =
664 "//build/config/fuchsia/test/elf_test_runner.shard.test-cml"
665 if (defined(invoker.test_runner_shard)) {
666 _test_runner_shard = invoker.test_runner_shard
Wez6879f8a2021-09-07 20:27:02667 }
668
Greg Thompson2f1e3762022-10-17 19:53:44669 # Collate the complete set of elements to include in the test component's
670 # manifest.
David Dorwin2c4872c2023-02-22 20:00:56671
Greg Thompson2f1e3762022-10-17 19:53:44672 _manifest_fragments = [
Greg Thompson2f1e3762022-10-17 19:53:44673 _test_program_fragment,
674 _test_runner_shard,
675 ]
676
David Dorwin2c4872c2023-02-22 20:00:56677 # Select the Fuchsia test realm in which to run the test.
678 if (defined(invoker.run_as_chromium_system_test) &&
679 invoker.run_as_chromium_system_test) {
680 _manifest_fragments += [
681 "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
682 "//build/config/fuchsia/test/system_test_minimum.shard.test-cml",
683 ]
684 } else {
685 _manifest_fragments += [
686 "//build/config/fuchsia/test/chromium_test_facet.shard.test-cml",
687 "//build/config/fuchsia/test/minimum.shard.test-cml",
688 ]
689 }
690
Zijie He78d978e2023-07-19 21:46:42691 if (is_asan) {
692 # TODO(crbug.com/1465997): Remove the extra cml segment for asan.
693 _manifest_fragments +=
694 [ "//build/config/fuchsia/test/asan_options.shard.test-cml" ]
695 }
696
Greg Thompson2f1e3762022-10-17 19:53:44697 _test_component_manifest = "${target_out_dir}/${target_name}.cml"
698 _merged_manifest_name = "${_output_name}.cml"
699
700 if (defined(invoker.additional_manifest_fragments)) {
701 _manifest_fragments += invoker.additional_manifest_fragments
702 }
703
704 # Generate the test component manifest from the specified elements.
705 _test_component_manifest_target = "${target_name}_component-manifest"
706 cmc_merge(_test_component_manifest_target) {
707 sources = _manifest_fragments
708 output_name = "${_merged_manifest_name}"
709 deps = [ ":${_test_program_fragment_target}" ]
710 }
711
712 # Define the test component, dependent on the generated manifest, and the
713 # test executable target.
714 _test_component_target = "${target_name}_component"
715 fuchsia_component(_test_component_target) {
716 deps = [ ":$_test_component_manifest_target" ]
717 data_deps = [ ":$_exec_target" ]
718 manifest = _test_component_manifest
719 visibility = [ ":*" ]
720 }
721
722 _test_component_targets = [ ":${_test_component_target}" ]
723
Wez6879f8a2021-09-07 20:27:02724 # Define components for each entry in |additional_manifests|, if any. Since
725 # manifests may themselves depend-on the outputs of |deps|, these components
726 # must each individually depend on |invoker.deps|.
Wez6879f8a2021-09-07 20:27:02727 if (defined(invoker.additional_manifests)) {
728 foreach(filename, invoker.additional_manifests) {
729 _additional_component_target =
730 target_name + "_" + get_path_info(filename, "name")
731 _test_component_targets += [ ":${_additional_component_target}" ]
732 fuchsia_component(_additional_component_target) {
733 forward_variables_from(invoker, [ "testonly" ])
734 data_deps = [ ":$_exec_target" ]
735 visibility = [ ":*" ]
736 manifest = filename
737
738 # Depend on |invoker.deps|, in case it includes a dependency that
739 # creates this additional component's manifest.
740 if (defined(invoker.deps)) {
741 deps = invoker.deps
742 }
743 }
744 }
745 }
746
747 # Define the package target that will bundle the test and additional
748 # components and their data.
749 fuchsia_package(_pkg_target) {
Kevin Marshall36c602c2021-11-04 16:16:21750 forward_variables_from(invoker,
751 [
752 "excluded_files",
753 "excluded_dirs",
Bryant Chandlerc40f2672023-01-27 23:33:30754 "excluded_paths",
Kevin Marshall36c602c2021-11-04 16:16:21755 ])
Wez6879f8a2021-09-07 20:27:02756 package_name = _output_name
757 deps = _test_component_targets
Kevin Marshall36c602c2021-11-04 16:16:21758
Greg Thompsonfd269652022-10-28 12:06:55759 if (defined(invoker.fuchsia_package_deps)) {
760 deps += invoker.fuchsia_package_deps
761 }
Bryant Chandlerc40f2672023-01-27 23:33:30762 if (!defined(excluded_paths)) {
763 excluded_paths = []
Kevin Marshall36c602c2021-11-04 16:16:21764 }
Bryant Chandlerc40f2672023-01-27 23:33:30765 excluded_paths += [
766 "${devtools_root_location}/*",
767 "*.git/*",
768 "*.svn/*",
769 "*.hg/*",
770 ]
Sarah Pham80972efc2022-05-31 17:40:15771 if (devtools_root_location != "") {
Bryant Chandlerc40f2672023-01-27 23:33:30772 excluded_paths += [ "${devtools_root_location}/*" ]
Sarah Pham80972efc2022-05-31 17:40:15773 }
Wez6879f8a2021-09-07 20:27:02774 }
775
776 # |target_name| refers to the package-runner rule, so that building
777 # "base_unittests" will build not only the executable, component, and
778 # package, but also the script required to run them.
Kevin Marshall5fadadd2021-10-16 00:08:25779 fuchsia_test_runner(target_name) {
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53780 forward_variables_from(invoker,
781 [
Kevin Marshall5fadadd2021-10-16 00:08:25782 "data",
783 "data_deps",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53784 "package_deps",
Kevin Marshall5fadadd2021-10-16 00:08:25785 "use_test_server",
Fabrice de Gans-Riberi041a6522018-12-11 00:20:53786 ])
Kevin Marshall5fadadd2021-10-16 00:08:25787
Chong Guc6bfdf62021-10-20 23:37:00788 is_test_exe = true
Kevin Marshall39b4aa82018-06-23 00:12:15789 package = ":$_pkg_target"
Kevin Marshall5fadadd2021-10-16 00:08:25790 package_name = _output_name
Dimitri Glazkovc95e6dd2018-08-24 23:39:42791
Kevin Marshall5fadadd2021-10-16 00:08:25792 if (!defined(deps)) {
793 deps = []
Jamie Madilldd60ee62021-04-13 19:25:52794 }
Kevin Marshall5fadadd2021-10-16 00:08:25795 if (defined(invoker.deps)) {
796 deps += invoker.deps
797 }
Greg Guterman6963dc02021-04-07 05:20:59798
Kevin Marshall5fadadd2021-10-16 00:08:25799 if (!defined(data)) {
800 data = []
801 }
802 if (tests_have_location_tags) {
803 data += [ "//testing/location_tags.json" ]
804 }
805
806 if (!defined(data_deps)) {
807 data_deps = []
808 }
Benjamin Lerman5e3cb3362022-01-25 16:46:28809
Kevin Marshall23529362022-02-23 16:50:36810 data_deps += [ "//testing:test_scripts_shared" ]
Kevin Marshallf35fa5f2018-01-29 19:24:42811 }
812
danakjebb9cc42022-03-04 21:30:11813 mixed_test(_exec_target) {
814 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01815 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
Kevin Marshallf35fa5f2018-01-29 19:24:42816 output_name = _exec_target
danakj505b7f02023-07-05 19:02:02817
Adrian Taylor62dbea52023-10-25 20:29:16818 if (!defined(deps)) {
819 deps = []
820 }
Adrian Taylor62dbea52023-10-25 20:29:16821
danakj505b7f02023-07-05 19:02:02822 # Use a crate name that avoids creating a warning due to double
823 # underscore (ie. `__`).
824 crate_name = _crate_name
Scott Graham4c4cdc52017-05-29 20:45:03825 }
dpranke2a294622015-08-07 05:23:01826 } else if (is_ios) {
Dirk Pranke79d065d2020-08-29 03:28:30827 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Mirko Bonadei50e251d2020-09-14 18:05:46828 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
Dirk Pranke79d065d2020-08-29 03:28:30829
Rohit Raof9b096d2019-09-09 22:26:23830 declare_args() {
Zhaoyang Li34fb05e2023-07-25 18:02:00831 # Keep the unittest-as-xctest functionality defaulted to off for
832 # local builds and test executions.
Rohit Raof9b096d2019-09-09 22:26:23833 enable_run_ios_unittests_with_xctest = false
834 }
835
sdefresne012857872016-03-16 10:55:37836 _test_target = target_name
Sylvain Defresne3f48aedc2021-10-07 10:17:27837
Jeff Yoonf7f4eb42020-03-06 18:55:36838 _wrapper_output_name = "run_${target_name}"
839 ios_test_runner_wrapper(_wrapper_output_name) {
840 forward_variables_from(invoker,
841 [
Cameron Higgins69d21be2023-12-04 17:57:21842 "clones",
Jeff Yoonf7f4eb42020-03-06 18:55:36843 "data",
Jeff Yoonf7f4eb42020-03-06 18:55:36844 "deps",
845 "executable_args",
846 "retries",
Jeff Yoonf7f4eb42020-03-06 18:55:36847 ])
848
849 _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
850
851 if (!defined(executable_args)) {
852 executable_args = []
853 }
854 executable_args += [
855 "--app",
856 "@WrappedPath(${_root_build_dir}/${_test_target}.app)",
857 ]
858
859 wrapper_output_name = "${_wrapper_output_name}"
Dirk Pranke19a58732021-03-24 22:26:22860
861 if (!defined(data)) {
862 data = []
863 }
Jamie Madilldd60ee62021-04-13 19:25:52864 if (tests_have_location_tags) {
865 data += [ "//testing/location_tags.json" ]
866 }
Jeff Yoonf7f4eb42020-03-06 18:55:36867 }
868
sdefresne012857872016-03-16 10:55:37869 _resources_bundle_data = target_name + "_resources_bundle_data"
870
871 bundle_data(_resources_bundle_data) {
sdefresne047490e2016-07-22 08:49:34872 visibility = [ ":$_test_target" ]
Nico Weber852532f2020-01-28 18:17:22873 sources = [ "//testing/gtest_ios/Default.png" ]
874 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
dpranke2a294622015-08-07 05:23:01875 }
876
Mirko Bonadei15522bc2020-09-16 20:38:39877 force_xctest = enable_run_ios_unittests_with_xctest ||
878 (defined(invoker.is_xctest) && invoker.is_xctest)
879
danakjfae603fc602022-11-18 18:40:22880 mixed_test(_test_target) {
881 if (force_xctest) {
882 target_type = "ios_xctest_test"
883 } else {
884 target_type = "ios_app_bundle"
885 }
dpranke2a294622015-08-07 05:23:01886 testonly = true
sdefresnea828c282016-05-30 18:04:20887
Mirko Bonadei15522bc2020-09-16 20:38:39888 if (force_xctest && build_with_chromium) {
Rohit Raof9b096d2019-09-09 22:26:23889 xctest_module_target = "//base/test:google_test_runner"
890 }
891
Andrew Grieve1b290e4a22020-11-24 20:07:01892 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
sdefresne9e147e02016-06-07 00:10:13893
894 # Provide sensible defaults in case invoker did not define any of those
895 # required variables.
sdefresne05b97ca2016-06-08 07:19:46896 if (!defined(info_plist) && !defined(info_plist_target)) {
sdefresne9e147e02016-06-07 00:10:13897 info_plist = "//testing/gtest_ios/unittest-Info.plist"
898 }
sdefresne9e147e02016-06-07 00:10:13899
Sylvain Defresne8c0fc9a2023-10-16 17:26:13900 bundle_identifier = shared_bundle_id_for_test_apps
dpranke2a294622015-08-07 05:23:01901
sdefresne047490e2016-07-22 08:49:34902 if (!defined(bundle_deps)) {
903 bundle_deps = []
904 }
905 bundle_deps += [ ":$_resources_bundle_data" ]
Jeff Yoonf7f4eb42020-03-06 18:55:36906
907 if (!defined(data_deps)) {
908 data_deps = []
909 }
910
Kevin Marshall23529362022-02-23 16:50:36911 data_deps += [ "//testing:test_scripts_shared" ]
912
Jeff Yoonf7f4eb42020-03-06 18:55:36913 # Include the generate_wrapper as part of data_deps
914 data_deps += [ ":${_wrapper_output_name}" ]
Mirko Bonadei50e251d2020-09-14 18:05:46915 write_runtime_deps = _runtime_deps_file
Adrian Taylor62dbea52023-10-25 20:29:16916 if (!defined(deps)) {
917 deps = []
918 }
dpranke2a294622015-08-07 05:23:01919 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11920 } else if ((is_chromeos_ash || (is_chromeos_lacros && is_chromeos_device)) &&
921 cros_board != "") {
Dirk Pranke79d065d2020-08-29 03:28:30922 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
923
Yuke Liao2a9b2f0e2021-04-16 00:40:11924 # Building for a cros board (ie: not linux-chromeos or linux-lacros).
Benjamin Pastene3bce864e2018-04-14 01:16:32925
Benjamin Pastene3bce864e2018-04-14 01:16:32926 _gen_runner_target = "${target_name}__runner"
927 _runtime_deps_file =
928 "$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
929 "/" + get_label_info(target_name, "name") + ".runtime_deps"
930
Xinan Linf3f5aa52023-08-24 22:07:28931 if (is_skylab && (defined(tast_attr_expr) || defined(tast_tests) ||
932 defined(tast_disabled_tests))) {
933 generate_skylab_tast_filter(_gen_runner_target) {
Yuke Liaoacb74b12021-04-23 23:37:34934 }
Xinan Lin6be01252021-06-25 23:07:36935 } else {
936 generate_runner_script(_gen_runner_target) {
Xinan Linf3f5aa52023-08-24 22:07:28937 generated_script = "$root_build_dir/bin/run_" + invoker.target_name
Xinan Lin6be01252021-06-25 23:07:36938 test_exe = invoker.target_name
939 runtime_deps_file = _runtime_deps_file
Yuke Liaoacb74b12021-04-23 23:37:34940
Xinan Lin6be01252021-06-25 23:07:36941 if (is_chromeos_lacros) {
942 # At build time, Lacros tests don't know whether they'll run on VM or
943 # HW, and instead, these flags are specified at runtime when invoking
944 # the generated runner script.
945 skip_generating_board_args = true
946 }
Greg Guterman6963dc02021-04-07 05:20:59947
Xinan Lin6be01252021-06-25 23:07:36948 if (tests_have_location_tags) {
949 data = [ "//testing/location_tags.json" ]
950 }
Greg Guterman6963dc02021-04-07 05:20:59951 }
Benjamin Pastene3bce864e2018-04-14 01:16:32952 }
953
danakjebb9cc42022-03-04 21:30:11954 mixed_test(target_name) {
955 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:01956 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
957 forward_variables_from(invoker, [ "visibility" ])
Benjamin Pastene3bce864e2018-04-14 01:16:32958 if (!defined(deps)) {
959 deps = []
960 }
961 if (!defined(data)) {
962 data = []
963 }
964
Ben Pastene41041782019-02-16 04:21:58965 # We use a special trigger script for CrOS hardware tests.
966 data += [ "//testing/trigger_scripts/chromeos_device_trigger.py" ]
967
Benjamin Pastene3bce864e2018-04-14 01:16:32968 write_runtime_deps = _runtime_deps_file
969 data += [ _runtime_deps_file ]
Tom Andersonce772fa2018-05-30 22:20:37970 deps += [ ":$_gen_runner_target" ]
Greg Guterman6963dc02021-04-07 05:20:59971
Kevin Marshall23529362022-02-23 16:50:36972 if (!defined(data_deps)) {
973 data_deps = []
974 }
975
976 data_deps += [ "//testing:test_scripts_shared" ]
Benjamin Pastene3bce864e2018-04-14 01:16:32977 }
Yuke Liao2a9b2f0e2021-04-16 00:40:11978 } else if (is_chromeos_lacros && !is_chromeos_device) {
Yuke Liaoe703384b2020-07-16 01:05:24979 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
980 _executable = target_name
981 _gen_runner_target = "${target_name}__runner"
982
Yuke Liao32af4242020-07-16 21:48:02983 if (defined(invoker.use_xvfb)) {
984 _use_xvfb = invoker.use_xvfb
985 } else {
986 _use_xvfb = false
987 }
988
Yuke Liaod037abc2020-10-06 22:48:22989 # When use_xvfb is set by the invoker, it indicates that running this test
990 # target requires a window, and in lacros build, ash-chrome serves as the
991 # display server. Note that even though the tests themselves do not require
992 # xvfb anymore, xvfb.py is still needed to invoke the lacros test runner
993 # because ash-chrome is based on x11.
994 _use_ash_chrome = _use_xvfb
995
Yuke Liaoe703384b2020-07-16 01:05:24996 generate_wrapper(_gen_runner_target) {
Yuke Liaoe703384b2020-07-16 01:05:24997 wrapper_script = "$root_build_dir/bin/run_" + _executable
Yuke Liao32af4242020-07-16 21:48:02998
Yuke Liao2e4953cf2020-07-26 19:20:19999 data = []
Will Harrisd35e2c92021-04-07 01:42:021000 data_deps = [ "//testing:test_scripts_shared" ]
1001
Yuke Liao32af4242020-07-16 21:48:021002 if (_use_xvfb) {
1003 executable = "//testing/xvfb.py"
Takuto Ikuta38ebd0e2022-01-19 17:56:221004 data += [ "//.vpython3" ]
Yuke Liao32af4242020-07-16 21:48:021005 } else {
1006 executable = "//testing/test_env.py"
1007 }
Jamie Madilldd60ee62021-04-13 19:25:521008 if (tests_have_location_tags) {
1009 data += [ "//testing/location_tags.json" ]
1010 }
Yuke Liao32af4242020-07-16 21:48:021011
Yuke Liaoe703384b2020-07-16 01:05:241012 executable_args = [
Yuke Liao32af4242020-07-16 21:48:021013 "@WrappedPath(../../build/lacros/test_runner.py)",
Yuke Liao240816d2020-07-22 00:10:391014 "test",
Yuke Liaoe703384b2020-07-16 01:05:241015 "@WrappedPath(./${_executable})",
1016 "--test-launcher-bot-mode",
1017 ]
Yuke Liao32af4242020-07-16 21:48:021018
Yuke Liaof540c742020-07-29 16:28:341019 if (_use_ash_chrome) {
Sven Zheng6d089f02021-09-13 17:59:371020 executable_args += [ "--ash-chrome-path" ]
1021
1022 # Can't use --ash-chrome-path=path because WrappedPath
1023 # won't be expanded for that usage.
1024 executable_args += [ "@WrappedPath(./ash_clang_x64/test_ash_chrome)" ]
Yuke Liao240816d2020-07-22 00:10:391025 }
1026
Yuke Liaoe703384b2020-07-16 01:05:241027 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:001028 executable_args += [ "--asan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241029 }
1030 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001031 executable_args += [ "--msan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241032 }
1033 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001034 executable_args += [ "--tsan=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241035 }
1036 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001037 executable_args += [ "--cfi-diag=1" ]
Yuke Liaoe703384b2020-07-16 01:05:241038 }
Ian Struiksma2ebc3222023-05-24 00:28:461039 if (fail_on_san_warnings) {
1040 executable_args += [ "--fail-san=1" ]
1041 }
Yuke Liaoe703384b2020-07-16 01:05:241042
Takuto Ikuta38ebd0e2022-01-19 17:56:221043 data += [ "//build/lacros/test_runner.py" ]
Yuke Liaoe703384b2020-07-16 01:05:241044 }
1045
danakjebb9cc42022-03-04 21:30:111046 mixed_test(target_name) {
1047 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011048 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1049 forward_variables_from(invoker, [ "visibility" ])
Yuke Liaoe703384b2020-07-16 01:05:241050 if (!defined(deps)) {
1051 deps = []
1052 }
1053
Yuke Liaod037abc2020-10-06 22:48:221054 if (!defined(data_deps)) {
1055 data_deps = []
1056 }
1057
Kevin Marshall23529362022-02-23 16:50:361058 data_deps += [ "//testing:test_scripts_shared" ]
1059
Yuke Liaoe703384b2020-07-16 01:05:241060 write_runtime_deps = _runtime_deps_file
1061 deps += [ ":$_gen_runner_target" ]
Yuke Liaod037abc2020-10-06 22:48:221062 if (_use_ash_chrome && also_build_ash_chrome) {
Sven Zheng74d4bd42021-06-02 02:48:561063 data_deps += [ "//chrome/test:test_ash_chrome(//build/toolchain/linux:ash_clang_x64)" ]
Yuke Liaod037abc2020-10-06 22:48:221064 }
Yuke Liaoe703384b2020-07-16 01:05:241065 }
Dirk Prankedd4ff742020-11-18 19:57:321066 } else if (!is_nacl) {
Dirk Pranke79d065d2020-08-29 03:28:301067 if (is_mac || is_win) {
1068 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
1069 }
1070
Dirk Prankedd4ff742020-11-18 19:57:321071 _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
1072 _executable = target_name
1073 _gen_runner_target = "${target_name}__runner"
Dirk Pranke31e346e2020-07-15 00:54:061074
Dirk Prankedd4ff742020-11-18 19:57:321075 if ((is_linux || is_chromeos) && defined(invoker.use_xvfb)) {
1076 _use_xvfb = invoker.use_xvfb
1077 } else {
1078 _use_xvfb = false
1079 }
1080
1081 generate_wrapper(_gen_runner_target) {
Dirk Prankedd4ff742020-11-18 19:57:321082 wrapper_script = "$root_build_dir/bin/run_" + _executable
1083
1084 data = []
Will Harrisd35e2c92021-04-07 01:42:021085 data_deps = [ "//testing:test_scripts_shared" ]
1086
Dirk Prankedd4ff742020-11-18 19:57:321087 if (_use_xvfb) {
1088 executable = "//testing/xvfb.py"
Dirk Pranke31e346e2020-07-15 00:54:061089 } else {
Dirk Prankedd4ff742020-11-18 19:57:321090 executable = "//testing/test_env.py"
Dirk Pranke31e346e2020-07-15 00:54:061091 }
Jamie Madilldd60ee62021-04-13 19:25:521092 if (tests_have_location_tags) {
1093 data += [ "//testing/location_tags.json" ]
1094 }
Dirk Pranke31e346e2020-07-15 00:54:061095
Dirk Prankedd4ff742020-11-18 19:57:321096 executable_args = [
1097 "@WrappedPath(./${_executable})",
1098 "--test-launcher-bot-mode",
1099 ]
1100 if (is_asan) {
Sven Zhenga006f4f2022-10-26 18:38:001101 executable_args += [ "--asan=1" ]
Dirk Pranke31e346e2020-07-15 00:54:061102 }
Dirk Prankedd4ff742020-11-18 19:57:321103 if (is_msan) {
Sven Zhenga006f4f2022-10-26 18:38:001104 executable_args += [ "--msan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321105 }
1106 if (is_tsan) {
Sven Zhenga006f4f2022-10-26 18:38:001107 executable_args += [ "--tsan=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321108 }
1109 if (use_cfi_diag) {
Sven Zhenga006f4f2022-10-26 18:38:001110 executable_args += [ "--cfi-diag=1" ]
Dirk Prankedd4ff742020-11-18 19:57:321111 }
Ian Struiksma2ebc3222023-05-24 00:28:461112 if (fail_on_san_warnings) {
1113 executable_args += [ "--fail-san=1" ]
1114 }
Dirk Pranke31e346e2020-07-15 00:54:061115 }
1116
danakjebb9cc42022-03-04 21:30:111117 mixed_test(target_name) {
1118 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011119 forward_variables_from(invoker,
1120 "*",
1121 TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
1122 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke31e346e2020-07-15 00:54:061123 if (!defined(deps)) {
1124 deps = []
1125 }
1126
Dirk Pranke31e346e2020-07-15 00:54:061127 deps += [
1128 # Give tests the default manifest on Windows (a no-op elsewhere).
1129 "//build/win:default_exe_manifest",
1130 ]
1131
Dirk Prankedd4ff742020-11-18 19:57:321132 write_runtime_deps = _runtime_deps_file
1133 deps += [ ":$_gen_runner_target" ]
Greg Guterman50ed4b42021-04-08 01:15:111134
Kevin Marshall23529362022-02-23 16:50:361135 if (!defined(data_deps)) {
1136 data_deps = []
1137 }
1138
1139 data_deps += [ "//testing:test_scripts_shared" ]
Dirk Prankedd4ff742020-11-18 19:57:321140 }
1141 } else {
1142 # This is a catch-all clause for NaCl toolchains and other random
1143 # configurations that might define tests; test() in these configs
1144 # will just define the underlying executables.
1145 assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb,
1146 "use_xvfb should not be defined for a non-linux configuration")
danakjebb9cc42022-03-04 21:30:111147 mixed_test(target_name) {
1148 target_type = "executable"
Andrew Grieve1b290e4a22020-11-24 20:07:011149 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
1150 forward_variables_from(invoker, [ "visibility" ])
Dirk Prankedd4ff742020-11-18 19:57:321151 if (!defined(deps)) {
1152 deps = []
Dirk Pranke31e346e2020-07-15 00:54:061153 }
Greg Guterman6963dc02021-04-07 05:20:591154
Kevin Marshall23529362022-02-23 16:50:361155 if (!defined(data_deps)) {
1156 data_deps = []
1157 }
1158
1159 data_deps += [ "//testing:test_scripts_shared" ]
Dirk Pranke31e346e2020-07-15 00:54:061160 }
qsrfb5251d12015-01-21 15:57:221161 }
1162}
brettwedb6ecc2016-07-14 23:37:031163
Dirk Pranke6188075b2020-10-01 19:31:281164# Defines a type of test that invokes a script to run, rather than
1165# invoking an executable.
1166#
1167# The script must implement the
1168# [test executable API](//docs/testing/test_executable_api.md).
1169#
Andrew Grievea16222d42023-02-10 15:31:101170# The template must be passed the `script` parameter, which specifies the path
1171# to the script to run. It may optionally be passed a `args` parameter, which
1172# can be used to include a list of args to be specified by default. The
1173# template will produce a `$root_build_dir/run_$target_name` wrapper and write
1174# the runtime_deps for the target to
1175# $root_build_dir/${target_name}.runtime_deps, as per the conventions listed in
1176# the [test wrapper API](//docs/testing/test_wrapper_api.md).
Dirk Pranke6188075b2020-10-01 19:31:281177template("script_test") {
1178 generate_wrapper(target_name) {
1179 testonly = true
1180 wrapper_script = "${root_build_dir}/bin/run_${target_name}"
1181
1182 executable = "//testing/test_env.py"
1183
1184 executable_args =
1185 [ "@WrappedPath(" + rebase_path(invoker.script, root_build_dir) + ")" ]
1186 if (defined(invoker.args)) {
1187 executable_args += invoker.args
1188 }
1189
Will Harrisd35e2c92021-04-07 01:42:021190 data = [ invoker.script ]
Dirk Pranke2dd666cd2021-03-03 16:57:471191
Dirk Pranke6188075b2020-10-01 19:31:281192 if (defined(invoker.data)) {
1193 data += invoker.data
1194 }
Jamie Madilldd60ee62021-04-13 19:25:521195 if (tests_have_location_tags) {
1196 data += [ "//testing/location_tags.json" ]
1197 }
Dirk Pranke19a58732021-03-24 22:26:221198
Will Harrisd35e2c92021-04-07 01:42:021199 data_deps = [ "//testing:test_scripts_shared" ]
Dirk Pranke6188075b2020-10-01 19:31:281200 if (defined(invoker.data_deps)) {
1201 data_deps += invoker.data_deps
1202 }
1203
1204 forward_variables_from(invoker,
Andrew Grievea16222d42023-02-10 15:31:101205 "*",
Andrew Grieve1b290e4a22020-11-24 20:07:011206 TESTONLY_AND_VISIBILITY + [
Andrew Grievea16222d42023-02-10 15:31:101207 "args",
Andrew Grieve1b290e4a22020-11-24 20:07:011208 "data",
1209 "data_deps",
1210 "script",
Andrew Grieve1b290e4a22020-11-24 20:07:011211 ])
1212 forward_variables_from(invoker, [ "visibility" ])
Dirk Pranke6188075b2020-10-01 19:31:281213
1214 write_runtime_deps = "${root_build_dir}/${target_name}.runtime_deps"
1215 }
1216}
1217
Andrew Grievea16222d42023-02-10 15:31:101218# Defines a test target that uses exit code for pass/fail.
1219template("isolated_script_test") {
1220 script_test(target_name) {
1221 forward_variables_from(invoker,
1222 "*",
1223 TESTONLY_AND_VISIBILITY + [
1224 "args",
1225 "deps",
1226 "script",
1227 ])
1228 forward_variables_from(invoker, [ "visibility" ])
1229 deps = [ "//testing:run_isolated_script_test" ]
1230 if (defined(invoker.deps)) {
1231 deps += invoker.deps
1232 }
1233 script = "//testing/scripts/run_isolated_script_test.py"
1234 data = [ invoker.script ]
1235 args = [
1236 rebase_path(invoker.script, root_build_dir),
1237 "--script-type=bare",
1238 ]
1239 if (defined(invoker.args)) {
1240 args += invoker.args
1241 }
1242 }
1243}
1244
brettwedb6ecc2016-07-14 23:37:031245# Test defaults.
1246set_defaults("test") {
1247 if (is_android) {
1248 configs = default_shared_library_configs
Yipeng Wang158dbc5c2017-06-30 18:16:411249 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Thomas Anderson11c1d9822019-01-15 06:32:591250 configs += [ "//build/config/android:hide_all_but_jni" ]
Andrew Grieved5fdf2af2022-08-23 07:47:551251
1252 # Compress sections to stay under 4gb hard limit on 32-bit current_cpu.
1253 # https://crbug.com/1354616
1254 if (symbol_level == 2 && !use_debug_fission &&
1255 (current_cpu == "arm" || current_cpu == "x86")) {
1256 configs += [ "//build/config:compress_debug_sections" ]
1257 }
brettwedb6ecc2016-07-14 23:37:031258 } else {
1259 configs = default_executable_configs
1260 }
1261}