1# Copyright 2013 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/compiled_action.gni") 6import("//build/config/chromeos/ui_mode.gni") 7import("//build/config/features.gni") 8import("//build/config/nacl/config.gni") 9import("//build/config/ui.gni") 10import("//build_overrides/build.gni") 11 12if (is_android) { 13 import("//build/config/android/rules.gni") 14} 15 16if (is_ios) { 17 import("//build/config/ios/rules.gni") 18} 19 20static_library("test_config") { 21 testonly = true 22 sources = [ 23 "test_switches.cc", 24 "test_switches.h", 25 "test_timeouts.cc", 26 "test_timeouts.h", 27 ] 28 deps = [ 29 "//base", 30 "//base:clang_profiling_buildflags", 31 "//build:chromeos_buildflags", 32 ] 33} 34 35static_library("test_support") { 36 testonly = true 37 sources = [ 38 "../task/sequence_manager/test/fake_task.cc", 39 "../task/sequence_manager/test/fake_task.h", 40 "../task/sequence_manager/test/mock_time_domain.cc", 41 "../task/sequence_manager/test/mock_time_domain.h", 42 "../task/sequence_manager/test/mock_time_message_pump.cc", 43 "../task/sequence_manager/test/mock_time_message_pump.h", 44 "../task/sequence_manager/test/sequence_manager_for_test.cc", 45 "../task/sequence_manager/test/sequence_manager_for_test.h", 46 "../task/sequence_manager/test/test_task_time_observer.h", 47 "../timer/mock_timer.cc", 48 "../timer/mock_timer.h", 49 "allow_check_is_test_for_testing.h", 50 "bind.cc", 51 "bind.h", 52 "copy_only_int.cc", 53 "copy_only_int.h", 54 "gmock_callback_support.h", 55 "gmock_move_support.h", 56 "gtest_links.cc", 57 "gtest_links.h", 58 "gtest_tags.cc", 59 "gtest_tags.h", 60 "gtest_util.cc", 61 "gtest_util.h", 62 "gtest_xml_unittest_result_printer.cc", 63 "gtest_xml_unittest_result_printer.h", 64 "gtest_xml_util.cc", 65 "gtest_xml_util.h", 66 "icu_test_util.cc", 67 "icu_test_util.h", 68 "launcher/test_result.cc", 69 "launcher/test_result.h", 70 "launcher/test_results_tracker.h", 71 "launcher/unit_test_launcher.h", 72 "metrics/histogram_enum_reader.cc", 73 "metrics/histogram_enum_reader.h", 74 "metrics/histogram_tester.cc", 75 "metrics/histogram_tester.h", 76 "metrics/user_action_tester.cc", 77 "metrics/user_action_tester.h", 78 "mock_callback.h", 79 "mock_devices_changed_observer.cc", 80 "mock_devices_changed_observer.h", 81 "mock_entropy_provider.cc", 82 "mock_entropy_provider.h", 83 "mock_log.cc", 84 "mock_log.h", 85 "move_only_int.h", 86 "multiprocess_test.h", 87 "null_task_runner.cc", 88 "null_task_runner.h", 89 "perf_log.cc", 90 "perf_log.h", 91 "perf_test_suite.cc", 92 "perf_test_suite.h", 93 "perf_time_logger.cc", 94 "perf_time_logger.h", 95 "power_monitor_test.cc", 96 "power_monitor_test.h", 97 "power_monitor_test_utils.cc", 98 "power_monitor_test_utils.h", 99 "rectify_callback.h", 100 "rectify_callback_internal.h", 101 "repeating_test_future.h", 102 "scoped_command_line.cc", 103 "scoped_command_line.h", 104 "scoped_feature_list.cc", 105 "scoped_feature_list.h", 106 "scoped_mock_clock_override.cc", 107 "scoped_mock_clock_override.h", 108 "scoped_mock_time_message_loop_task_runner.cc", 109 "scoped_mock_time_message_loop_task_runner.h", 110 "scoped_path_override.cc", 111 "scoped_path_override.h", 112 "scoped_run_loop_timeout.cc", 113 "scoped_run_loop_timeout.h", 114 "sequenced_task_runner_test_template.cc", 115 "sequenced_task_runner_test_template.h", 116 "simple_test_clock.cc", 117 "simple_test_clock.h", 118 "simple_test_tick_clock.cc", 119 "simple_test_tick_clock.h", 120 "task_environment.cc", 121 "task_environment.h", 122 "task_runner_test_template.cc", 123 "task_runner_test_template.h", 124 "test_discardable_memory_allocator.cc", 125 "test_discardable_memory_allocator.h", 126 "test_file_util.cc", 127 "test_file_util.h", 128 "test_future.h", 129 "test_future_internal.h", 130 "test_io_thread.cc", 131 "test_io_thread.h", 132 "test_message_loop.cc", 133 "test_message_loop.h", 134 "test_mock_time_task_runner.cc", 135 "test_mock_time_task_runner.h", 136 "test_pending_task.cc", 137 "test_pending_task.h", 138 "test_shared_memory_util.cc", 139 "test_shared_memory_util.h", 140 "test_simple_task_runner.cc", 141 "test_simple_task_runner.h", 142 "test_suite.cc", 143 "test_suite.h", 144 "test_waitable_event.cc", 145 "test_waitable_event.h", 146 "thread_test_helper.cc", 147 "thread_test_helper.h", 148 "values_test_util.cc", 149 "values_test_util.h", 150 "with_feature_override.cc", 151 "with_feature_override.h", 152 ] 153 154 configs += [ "//build/config:precompiled_headers" ] 155 156 public_deps = [ 157 ":test_config", 158 "//base", 159 "//base:base_static", 160 "//base:i18n", 161 "//testing/gmock", 162 "//testing/gtest", 163 ] 164 165 deps = [ 166 "//base/third_party/dynamic_annotations", 167 "//build:chromeos_buildflags", 168 "//third_party/icu:icuuc", 169 "//third_party/libxml:libxml_utils", 170 "//third_party/libxml:xml_reader", 171 ] 172 173 if (enable_base_tracing) { 174 public_deps += [ "//third_party/perfetto:perfetto_test_support" ] 175 if (!is_chromeos) { 176 # TODO(rasikan): Add to ios and chromeos when unblocked by the chromiumos 177 # change to add the shared lib to the chrome-binary-tests directory. 178 public_deps += [ ":test_trace_processor" ] 179 if (is_ios) { 180 deps += [ 181 ":test_trace_processor+bundle", 182 ":test_trace_processor+link", 183 ] 184 } 185 } 186 } 187 188 if (is_win) { 189 sources += [ 190 "async_results_test_values_win.h", 191 "fake_iasync_operation_win.h", 192 "scoped_os_info_override_win.cc", 193 "scoped_os_info_override_win.h", 194 "test_file_util_win.cc", 195 "test_reg_util_win.cc", 196 "test_reg_util_win.h", 197 "test_shortcut_win.cc", 198 "test_shortcut_win.h", 199 ] 200 } 201 202 if (is_chromeos) { 203 sources += [ 204 "scoped_chromeos_version_info.cc", 205 "scoped_chromeos_version_info.h", 206 "scoped_running_on_chromeos.cc", 207 "scoped_running_on_chromeos.h", 208 ] 209 } 210 211 if (is_linux || is_chromeos) { 212 sources += [ "test_file_util_linux.cc" ] 213 public_deps += [ "//third_party/test_fonts/fontconfig:test_support" ] 214 } 215 216 if (is_mac) { 217 frameworks = [ "AppKit.framework" ] 218 sources += [ 219 "mock_chrome_application_mac.h", 220 "mock_chrome_application_mac.mm", 221 "test_file_util_mac.cc", 222 ] 223 } 224 225 if (is_android) { 226 sources += [ 227 "android/java_handler_thread_helpers.cc", 228 "android/java_handler_thread_helpers.h", 229 "android/url_utils.cc", 230 "android/url_utils.h", 231 "multiprocess_test_android.cc", 232 "reached_code_profiler_android.cc", 233 "test_file_util_android.cc", 234 "test_file_util_linux.cc", 235 "test_support_android.cc", 236 "test_support_android.h", 237 "thread_pool_test_helpers_android.cc", 238 ] 239 deps += [ 240 ":base_unittests_jni_headers", 241 ":test_support_jni_headers", 242 ] 243 public_deps += [ ":test_support_java" ] 244 } 245 246 if (is_ios) { 247 sources += [ 248 "ios/wait_util.h", 249 "ios/wait_util.mm", 250 "test_file_util_mac.cc", 251 "test_listener_ios.h", 252 "test_listener_ios.mm", 253 "test_support_ios.h", 254 "test_support_ios.mm", 255 ] 256 deps += [ 257 ":google_test_runner_shared_headers", 258 "//build:blink_buildflags", 259 ] 260 261 # With blink, we use the standard unit_test_launcher.cc. 262 if (!use_blink) { 263 sources += [ "launcher/unit_test_launcher_ios.cc" ] 264 } 265 } 266 267 if (is_posix || is_fuchsia) { 268 sources += [ 269 "scoped_locale.cc", 270 "scoped_locale.h", 271 "test_file_util_posix.cc", 272 ] 273 } 274 275 if (is_fuchsia) { 276 deps += [ 277 "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io:fuchsia.io_cpp_hlcpp_conversion", 278 "//third_party/fuchsia-sdk/sdk/pkg/zx", 279 ] 280 public_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp" ] 281 sources += [ 282 "../fuchsia/test_component_context_for_process.cc", 283 "../fuchsia/test_component_context_for_process.h", 284 "scoped_dev_zero_fuchsia.cc", 285 "scoped_dev_zero_fuchsia.h", 286 ] 287 } 288 289 if (use_blink) { 290 sources += [ 291 "launcher/test_launcher.cc", 292 "launcher/test_launcher.h", 293 "launcher/test_launcher_test_utils.cc", 294 "launcher/test_launcher_test_utils.h", 295 "launcher/test_launcher_tracer.cc", 296 "launcher/test_launcher_tracer.h", 297 "launcher/test_results_tracker.cc", 298 "launcher/unit_test_launcher.cc", 299 "multiprocess_test.cc", 300 ] 301 } 302 303 if (enable_base_tracing) { 304 sources += [ 305 "../trace_event/trace_config_memory_test_util.h", 306 "trace_event_analyzer.cc", 307 "trace_event_analyzer.h", 308 "trace_test_utils.cc", 309 "trace_test_utils.h", 310 "trace_to_file.cc", 311 "trace_to_file.h", 312 ] 313 } 314} 315 316config("base_test_implementation") { 317 defines = [ "IS_BASE_TEST_IMPL" ] 318} 319 320config("perf_test_config") { 321 defines = [ "PERF_TEST" ] 322} 323 324# This is a source set instead of a static library because it seems like some 325# linkers get confused when "main" is in a static library, and if you link to 326# this, you always want the object file anyway. 327source_set("test_support_perf") { 328 testonly = true 329 sources = [ "run_all_perftests.cc" ] 330 deps = [ 331 ":test_support", 332 "//base", 333 "//testing/gtest", 334 ] 335 336 public_configs = [ ":perf_test_config" ] 337} 338 339static_library("run_all_unittests") { 340 testonly = true 341 sources = [ "run_all_unittests.cc" ] 342 deps = [ ":test_support" ] 343} 344 345# These sources are linked into both the base_unittests binary and the test 346# shared library target below. 347source_set("native_library_test_utils") { 348 testonly = true 349 sources = [ 350 "native_library_test_utils.cc", 351 "native_library_test_utils.h", 352 ] 353} 354 355# This shared library is dynamically loaded by ImmediateCrash unittests. 356shared_library("immediate_crash_test_helper") { 357 sources = [ "immediate_crash_test_helper.cc" ] 358 359 # Note: the helper has a header-only dependency on //base/immediate_helper.h. 360 # However, the build rule intentionally omits an explicit //base dependency 361 # to avoid potential ODR violations and minimize the amount of code linked in. 362 363 # Try to minimize the risk of non-official builds generating different code. 364 if (!is_official_build) { 365 configs -= [ "//build/config/compiler:default_optimization" ] 366 configs += [ "//build/config/compiler:optimize_max" ] 367 } 368 369 # Disable sanitization: sanitized builds are assumed to be saner than normal, 370 # and can affect codegen in surprising ways, which breaks the tests. 371 configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ] 372 373 if (is_android) { 374 configs -= [ "//build/config/android:hide_all_but_jni_onload" ] 375 } 376} 377 378# This shared library is dynamically loaded by NativeLibrary unittests. 379shared_library("test_shared_library") { 380 testonly = true 381 sources = [ "test_shared_library.cc" ] 382 383 deps = [ ":native_library_test_utils" ] 384} 385 386if (is_fuchsia || is_linux || is_chromeos) { 387 shared_library("malloc_wrapper") { 388 testonly = true 389 sources = [ "malloc_wrapper.cc" ] 390 deps = [ "//base" ] 391 } 392} 393 394if (is_android) { 395 generate_jni("base_unittests_jni_headers") { 396 testonly = true 397 sources = [ 398 "android/java/src/org/chromium/base/ContentUriTestUtils.java", 399 "android/java/src/org/chromium/base/JavaHandlerThreadHelpers.java", 400 ] 401 } 402 403 generate_jni("test_support_jni_headers") { 404 testonly = true 405 sources = [ 406 "android/java/src/org/chromium/base/MainReturnCodeResult.java", 407 "android/java/src/org/chromium/base/MultiprocessTestClientLauncher.java", 408 "android/javatests/src/org/chromium/base/test/ReachedCodeProfiler.java", 409 "android/javatests/src/org/chromium/base/test/task/ThreadPoolTestHelpers.java", 410 "android/javatests/src/org/chromium/base/test/util/UrlUtils.java", 411 ] 412 } 413 414 android_library("test_support_java") { 415 testonly = true 416 417 deps = [ 418 "//base:base_java", 419 "//base:jni_java", 420 "//base:process_launcher_java", 421 "//testing/android/native_test:native_main_runner_java", 422 "//third_party/android_deps:com_google_code_findbugs_jsr305_java", 423 ] 424 425 srcjar_deps = [ ":test_support_java_aidl" ] 426 sources = [ 427 "android/java/src/org/chromium/base/GarbageCollectionTestUtils.java", 428 "android/java/src/org/chromium/base/MainReturnCodeResult.java", 429 "android/java/src/org/chromium/base/MultiprocessTestClientLauncher.java", 430 "android/java/src/org/chromium/base/MultiprocessTestClientService.java", 431 "android/java/src/org/chromium/base/MultiprocessTestClientService0.java", 432 "android/java/src/org/chromium/base/MultiprocessTestClientService1.java", 433 "android/java/src/org/chromium/base/MultiprocessTestClientService2.java", 434 "android/java/src/org/chromium/base/MultiprocessTestClientService3.java", 435 "android/java/src/org/chromium/base/MultiprocessTestClientService4.java", 436 "android/java/src/org/chromium/base/MultiprocessTestClientService5.java", 437 "android/java/src/org/chromium/base/MultiprocessTestClientService6.java", 438 "android/java/src/org/chromium/base/MultiprocessTestClientService7.java", 439 "android/java/src/org/chromium/base/MultiprocessTestClientService8.java", 440 "android/java/src/org/chromium/base/MultiprocessTestClientService9.java", 441 "android/java/src/org/chromium/base/MultiprocessTestClientServiceDelegate.java", 442 ] 443 } 444 445 android_aidl("test_support_java_aidl") { 446 testonly = true 447 import_include = [ 448 "android/java/src", 449 "//base/android/java/src", 450 ] 451 sources = [ 452 "android/java/src/org/chromium/base/ITestCallback.aidl", 453 "android/java/src/org/chromium/base/ITestController.aidl", 454 ] 455 } 456} 457 458if (is_ios) { 459 source_set("google_test_runner_shared_headers") { 460 sources = [ "ios/google_test_runner_delegate.h" ] 461 } 462 463 source_set("google_test_runner") { 464 sources = [ "ios/google_test_runner.mm" ] 465 deps = [ 466 ":google_test_runner_shared_headers", 467 "//base", 468 ] 469 frameworks = [ "UIKit.framework" ] 470 configs += [ 471 "//build/config/compiler:enable_arc", 472 "//build/config/ios:xctest_config", 473 ] 474 } 475} 476 477# Trivial executable which outputs space-delimited argv to stdout, 478# used for testing. 479executable("test_child_process") { 480 testonly = true 481 sources = [ "test_child_process.cc" ] 482} 483 484if (enable_base_tracing) { 485 # We encapsulate the trace processor in a separate shared library to prevent 486 # any duplicate symbol issues. Perfetto symbols are exported by chromium’s 487 # base via a public_dep on libperfetto; libtrace_processor also depends on 488 # these symbols. So we “hide” the perfetto symbols exported from this 489 # interface. Also, chrome targets depend on chromium_sqlite and the trace 490 # processor depends on dev_sqlite. The two share the same symbols but have 491 # different implementations, so we need to hide dev_sqlite in this shared 492 # library even in non-component builds to prevent duplicate symbols. 493 _target_type = "shared_library" 494 if (is_ios) { 495 _target_type = "ios_framework_bundle" 496 } 497 498 target(_target_type, "test_trace_processor") { 499 defines = [ "TEST_TRACE_PROCESSOR_IMPL" ] 500 testonly = true 501 sources = [ 502 "test_trace_processor.cc", 503 "test_trace_processor.h", 504 "test_trace_processor_export.h", 505 ] 506 deps = [ 507 "//third_party/abseil-cpp:absl", 508 "//third_party/perfetto:libtrace_processor", 509 ] 510 if (is_android) { 511 configs -= [ "//build/config/android:hide_all_but_jni_onload" ] 512 } 513 514 if (is_ios) { 515 info_plist = "test_trace_processor.plist" 516 output_name = "TestTraceProcessor" 517 bundle_deps_filter = [ "//third_party/icu:icudata" ] 518 } 519 520 # Set rpath on dependent tests so that they can find the shared library 521 # in a non-component build. 522 if (!is_component_build) { 523 all_dependent_configs = [] 524 if (is_linux || is_chromeos) { 525 all_dependent_configs += 526 [ "//build/config/gcc:rpath_for_built_shared_libraries" ] 527 } 528 if (is_mac) { 529 # We need the lib to be in $root_out_dir/Libraries so the library is where 530 # the linker expects it, since we set the install_name flag. We need to 531 # set this flag so that the library can be found when it is bundled in the 532 # Content Shell Framework (see test_trace_processor_bundle_data). 533 output_dir = "$root_out_dir/Libraries" 534 ldflags = [ "-Wl,-install_name,@loader_path/Libraries/libtest_trace_processor.dylib" ] 535 } 536 } 537 } 538 539 if (!is_component_build && is_mac) { 540 bundle_data("test_trace_processor_bundle_data") { 541 testonly = true 542 sources = [ "$root_out_dir/Libraries/libtest_trace_processor.dylib" ] 543 outputs = [ "{{bundle_contents_dir}}/Libraries/{{source_file_part}}" ] 544 public_deps = [ ":test_trace_processor" ] 545 } 546 } 547} 548