• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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")
11import("//third_party/protobuf/proto_library.gni")
12
13if (is_android) {
14  import("//build/config/android/rules.gni")
15  import("//third_party/jni_zero/jni_zero.gni")
16}
17
18if (is_ios) {
19  import("//build/config/ios/rules.gni")
20}
21
22if (enable_base_tracing) {
23  import("//third_party/perfetto/gn/perfetto_cc_proto_descriptor.gni")
24}
25
26static_library("test_config") {
27  testonly = true
28  sources = [
29    "test_switches.cc",
30    "test_switches.h",
31    "test_timeouts.cc",
32    "test_timeouts.h",
33  ]
34  deps = [
35    "//base",
36    "//base:clang_profiling_buildflags",
37    "//build:chromeos_buildflags",
38  ]
39}
40
41static_library("test_support") {
42  testonly = true
43  sources = [
44    "../task/sequence_manager/test/fake_task.cc",
45    "../task/sequence_manager/test/fake_task.h",
46    "../task/sequence_manager/test/mock_time_domain.cc",
47    "../task/sequence_manager/test/mock_time_domain.h",
48    "../task/sequence_manager/test/mock_time_message_pump.cc",
49    "../task/sequence_manager/test/mock_time_message_pump.h",
50    "../task/sequence_manager/test/sequence_manager_for_test.cc",
51    "../task/sequence_manager/test/sequence_manager_for_test.h",
52    "../task/sequence_manager/test/test_task_time_observer.h",
53    "../timer/mock_timer.cc",
54    "../timer/mock_timer.h",
55    "allow_check_is_test_for_testing.h",
56    "bind.cc",
57    "bind.h",
58    "copy_only_int.cc",
59    "copy_only_int.h",
60    "gmock_callback_support.h",
61    "gmock_expected_support.h",
62    "gmock_move_support.h",
63    "gtest_links.cc",
64    "gtest_links.h",
65    "gtest_tags.cc",
66    "gtest_tags.h",
67    "gtest_util.cc",
68    "gtest_util.h",
69    "gtest_xml_unittest_result_printer.cc",
70    "gtest_xml_unittest_result_printer.h",
71    "gtest_xml_util.cc",
72    "gtest_xml_util.h",
73    "icu_test_util.cc",
74    "icu_test_util.h",
75    "launcher/test_result.cc",
76    "launcher/test_result.h",
77    "launcher/test_results_tracker.h",
78    "launcher/unit_test_launcher.h",
79    "metrics/histogram_enum_reader.cc",
80    "metrics/histogram_enum_reader.h",
81    "metrics/histogram_tester.cc",
82    "metrics/histogram_tester.h",
83    "metrics/user_action_tester.cc",
84    "metrics/user_action_tester.h",
85    "mock_callback.h",
86    "mock_devices_changed_observer.cc",
87    "mock_devices_changed_observer.h",
88    "mock_entropy_provider.cc",
89    "mock_entropy_provider.h",
90    "mock_log.cc",
91    "mock_log.h",
92    "move_only_int.h",
93    "multiprocess_test.h",
94    "null_task_runner.cc",
95    "null_task_runner.h",
96    "perf_log.cc",
97    "perf_log.h",
98    "perf_test_suite.cc",
99    "perf_test_suite.h",
100    "perf_time_logger.cc",
101    "perf_time_logger.h",
102    "power_monitor_test.cc",
103    "power_monitor_test.h",
104    "power_monitor_test_utils.cc",
105    "power_monitor_test_utils.h",
106    "protobuf_matchers.h",
107    "rectify_callback.h",
108    "rectify_callback_internal.h",
109    "repeating_test_future.h",
110    "run_until.cc",
111    "run_until.h",
112    "scoped_amount_of_physical_memory_override.cc",
113    "scoped_amount_of_physical_memory_override.h",
114    "scoped_block_tests_writing_to_special_dirs.cc",
115    "scoped_block_tests_writing_to_special_dirs.h",
116    "scoped_command_line.cc",
117    "scoped_command_line.h",
118    "scoped_feature_list.cc",
119    "scoped_feature_list.h",
120    "scoped_mock_clock_override.cc",
121    "scoped_mock_clock_override.h",
122    "scoped_mock_time_message_loop_task_runner.cc",
123    "scoped_mock_time_message_loop_task_runner.h",
124    "scoped_path_override.cc",
125    "scoped_path_override.h",
126    "scoped_run_loop_timeout.cc",
127    "scoped_run_loop_timeout.h",
128    "sequenced_task_runner_test_template.cc",
129    "sequenced_task_runner_test_template.h",
130    "simple_test_clock.cc",
131    "simple_test_clock.h",
132    "simple_test_tick_clock.cc",
133    "simple_test_tick_clock.h",
134    "task_environment.cc",
135    "task_environment.h",
136    "task_runner_test_template.cc",
137    "task_runner_test_template.h",
138    "test_discardable_memory_allocator.cc",
139    "test_discardable_memory_allocator.h",
140    "test_file_util.cc",
141    "test_file_util.h",
142    "test_future.h",
143    "test_future_internal.h",
144    "test_io_thread.cc",
145    "test_io_thread.h",
146    "test_message_loop.cc",
147    "test_message_loop.h",
148    "test_mock_time_task_runner.cc",
149    "test_mock_time_task_runner.h",
150    "test_pending_task.cc",
151    "test_pending_task.h",
152    "test_shared_memory_util.cc",
153    "test_shared_memory_util.h",
154    "test_simple_task_runner.cc",
155    "test_simple_task_runner.h",
156    "test_suite.cc",
157    "test_suite.h",
158    "test_waitable_event.cc",
159    "test_waitable_event.h",
160    "thread_test_helper.cc",
161    "thread_test_helper.h",
162    "to_vector.h",
163    "values_test_util.cc",
164    "values_test_util.h",
165    "with_feature_override.cc",
166    "with_feature_override.h",
167  ]
168
169  configs += [ "//build/config:precompiled_headers" ]
170
171  public_deps = [
172    ":test_config",
173    "//base",
174    "//base:base_static",
175    "//base:i18n",
176    "//build:blink_buildflags",
177    "//testing/gmock",
178    "//testing/gtest",
179  ]
180
181  deps = [
182    "//base/third_party/dynamic_annotations",
183    "//build:chromeos_buildflags",
184    "//third_party/google_benchmark",
185    "//third_party/icu:icuuc",
186    "//third_party/libxml:libxml_utils",
187    "//third_party/libxml:xml_reader",
188  ]
189
190  if (enable_base_tracing) {
191    public_deps += [ "//third_party/perfetto:perfetto_test_support" ]
192    public_deps += [ ":test_trace_processor" ]
193    sources += [
194      "test_trace_processor.cc",
195      "test_trace_processor.h",
196    ]
197    deps += [
198      ":amalgamated_perfetto_sql_stdlib",
199      ":gen_cc_chrome_track_event_descriptor",
200    ]
201    if (is_ios) {
202      deps += [
203        ":test_trace_processor+bundle",
204        ":test_trace_processor+link",
205      ]
206    }
207  }
208
209  if (is_win) {
210    sources += [
211      "async_results_test_values_win.h",
212      "fake_iasync_operation_win.h",
213      "scoped_os_info_override_win.cc",
214      "scoped_os_info_override_win.h",
215      "test_file_util_win.cc",
216      "test_reg_util_win.cc",
217      "test_reg_util_win.h",
218      "test_shortcut_win.cc",
219      "test_shortcut_win.h",
220    ]
221  }
222
223  if (is_chromeos) {
224    sources += [
225      "scoped_chromeos_version_info.cc",
226      "scoped_chromeos_version_info.h",
227      "scoped_running_on_chromeos.cc",
228      "scoped_running_on_chromeos.h",
229    ]
230  }
231
232  if (is_linux || is_chromeos) {
233    sources += [ "test_file_util_linux.cc" ]
234    public_deps += [ "//third_party/test_fonts/fontconfig:test_support" ]
235  }
236
237  if (is_mac) {
238    frameworks = [ "AppKit.framework" ]
239    sources += [
240      "mock_chrome_application_mac.h",
241      "mock_chrome_application_mac.mm",
242      "test_file_util_mac.cc",
243    ]
244  }
245
246  if (is_android) {
247    sources += [
248      "android/java_handler_thread_helpers.cc",
249      "android/java_handler_thread_helpers.h",
250      "android/url_utils.cc",
251      "android/url_utils.h",
252      "multiprocess_test_android.cc",
253      "reached_code_profiler_android.cc",
254      "test_file_util_android.cc",
255      "test_file_util_linux.cc",
256      "test_support_android.cc",
257      "test_support_android.h",
258      "thread_pool_test_helpers_android.cc",
259    ]
260    deps += [
261      ":base_unittests_jni_headers",
262      ":test_support_jni_headers",
263    ]
264    public_deps += [ ":test_support_java" ]
265  }
266
267  if (is_ios) {
268    sources += [
269      "ios/wait_util.h",
270      "ios/wait_util.mm",
271      "test_file_util_mac.cc",
272      "test_listener_ios.h",
273      "test_listener_ios.mm",
274      "test_support_ios.h",
275      "test_support_ios.mm",
276    ]
277    deps += [
278      ":google_test_runner_shared_headers",
279      "//build:blink_buildflags",
280    ]
281
282    # With blink, we use the standard unit_test_launcher.cc.
283    if (!use_blink) {
284      sources += [ "launcher/unit_test_launcher_ios.cc" ]
285    }
286  }
287
288  if (is_posix || is_fuchsia) {
289    sources += [
290      "scoped_locale.cc",
291      "scoped_locale.h",
292      "test_file_util_posix.cc",
293    ]
294  }
295
296  if (is_fuchsia) {
297    deps += [
298      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io:fuchsia.io_cpp_hlcpp_conversion",
299      "//third_party/fuchsia-sdk/sdk/pkg/zx",
300    ]
301    public_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp" ]
302    sources += [
303      "../fuchsia/test_component_context_for_process.cc",
304      "../fuchsia/test_component_context_for_process.h",
305      "scoped_dev_zero_fuchsia.cc",
306      "scoped_dev_zero_fuchsia.h",
307    ]
308  }
309
310  if (use_blink) {
311    sources += [
312      "launcher/test_launcher.cc",
313      "launcher/test_launcher.h",
314      "launcher/test_launcher_test_utils.cc",
315      "launcher/test_launcher_test_utils.h",
316      "launcher/test_launcher_tracer.cc",
317      "launcher/test_launcher_tracer.h",
318      "launcher/test_results_tracker.cc",
319      "launcher/unit_test_launcher.cc",
320      "multiprocess_test.cc",
321    ]
322  }
323
324  if (enable_base_tracing) {
325    sources += [
326      "../trace_event/trace_config_memory_test_util.h",
327      "trace_event_analyzer.cc",
328      "trace_event_analyzer.h",
329      "trace_test_utils.cc",
330      "trace_test_utils.h",
331      "trace_to_file.cc",
332      "trace_to_file.h",
333    ]
334  }
335}
336
337component("proto_test_support") {
338  testonly = true
339
340  sources = [
341    "test_proto_loader.cc",
342    "test_proto_loader.h",
343  ]
344
345  defines = [ "PROTO_TEST_IMPLEMENTATION" ]
346
347  deps = [
348    "//base",
349    "//third_party/protobuf:protobuf_full",
350  ]
351}
352
353proto_library("test_proto") {
354  sources = [ "test.proto" ]
355  cc_generator_options = "lite"
356}
357
358proto_library("test_proto_descriptor") {
359  sources = [ "test.proto" ]
360  generate_cc = false
361  generate_python = false
362  generate_descriptor = "test_proto.descriptor"
363}
364
365config("base_test_implementation") {
366  defines = [ "IS_BASE_TEST_IMPL" ]
367}
368
369config("perf_test_config") {
370  defines = [ "PERF_TEST" ]
371}
372
373# This is a source set instead of a static library because it seems like some
374# linkers get confused when "main" is in a static library, and if you link to
375# this, you always want the object file anyway.
376source_set("test_support_perf") {
377  testonly = true
378  sources = [ "run_all_perftests.cc" ]
379  deps = [
380    ":test_support",
381    "//base",
382    "//testing/gtest",
383  ]
384
385  public_configs = [ ":perf_test_config" ]
386}
387
388static_library("run_all_unittests") {
389  testonly = true
390  sources = [ "run_all_unittests.cc" ]
391  deps = [ ":test_support" ]
392}
393
394# These sources are linked into both the base_unittests binary and the test
395# shared library target below.
396source_set("native_library_test_utils") {
397  testonly = true
398  sources = [
399    "native_library_test_utils.cc",
400    "native_library_test_utils.h",
401  ]
402}
403
404# This shared library is dynamically loaded by ImmediateCrash unittests.
405shared_library("immediate_crash_test_helper") {
406  sources = [ "immediate_crash_test_helper.cc" ]
407
408  # Note: the helper has a header-only dependency on //base/immediate_helper.h.
409  # However, the build rule intentionally omits an explicit //base dependency
410  # to avoid potential ODR violations and minimize the amount of code linked in.
411  # We do however need to depend upon a buildflag header included in
412  # base/immediate_crash.h.
413  deps = [ "//base:fuzzing_buildflags" ]
414
415  # Try to minimize the risk of non-official builds generating different code.
416  if (!is_official_build) {
417    configs -= [ "//build/config/compiler:default_optimization" ]
418    configs += [ "//build/config/compiler:optimize_max" ]
419  }
420
421  # Disable sanitization: sanitized builds are assumed to be saner than normal,
422  # and can affect codegen in surprising ways, which breaks the tests.
423  configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ]
424
425  if (is_android) {
426    configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
427  }
428}
429
430# This shared library is dynamically loaded by NativeLibrary unittests.
431shared_library("test_shared_library") {
432  testonly = true
433  sources = [ "test_shared_library.cc" ]
434
435  deps = [ ":native_library_test_utils" ]
436}
437
438if (is_fuchsia || is_linux || is_chromeos) {
439  shared_library("malloc_wrapper") {
440    testonly = true
441    sources = [
442      "malloc_wrapper.cc",
443      "malloc_wrapper.h",
444    ]
445  }
446}
447
448if (is_android) {
449  generate_jni("base_unittests_jni_headers") {
450    testonly = true
451    sources = [
452      "android/java/src/org/chromium/base/ContentUriTestUtils.java",
453      "android/java/src/org/chromium/base/JavaHandlerThreadHelpers.java",
454    ]
455  }
456
457  generate_jni("test_support_jni_headers") {
458    testonly = true
459    sources = [
460      "android/java/src/org/chromium/base/MainReturnCodeResult.java",
461      "android/java/src/org/chromium/base/MultiprocessTestClientLauncher.java",
462      "android/javatests/src/org/chromium/base/test/ReachedCodeProfiler.java",
463      "android/javatests/src/org/chromium/base/test/task/ThreadPoolTestHelpers.java",
464      "android/javatests/src/org/chromium/base/test/util/UrlUtils.java",
465    ]
466  }
467
468  android_library("test_support_java") {
469    testonly = true
470
471    deps = [
472      "//base:base_java",
473      "//base:process_launcher_java",
474      "//testing/android/native_test:native_main_runner_java",
475      "//third_party/android_deps:com_google_code_findbugs_jsr305_java",
476      "//third_party/jni_zero:jni_zero_java",
477    ]
478
479    srcjar_deps = [ ":test_support_java_aidl" ]
480    sources = [
481      "android/java/src/org/chromium/base/GarbageCollectionTestUtils.java",
482      "android/java/src/org/chromium/base/MainReturnCodeResult.java",
483      "android/java/src/org/chromium/base/MultiprocessTestClientLauncher.java",
484      "android/java/src/org/chromium/base/MultiprocessTestClientService.java",
485      "android/java/src/org/chromium/base/MultiprocessTestClientService0.java",
486      "android/java/src/org/chromium/base/MultiprocessTestClientService1.java",
487      "android/java/src/org/chromium/base/MultiprocessTestClientService2.java",
488      "android/java/src/org/chromium/base/MultiprocessTestClientService3.java",
489      "android/java/src/org/chromium/base/MultiprocessTestClientService4.java",
490      "android/java/src/org/chromium/base/MultiprocessTestClientService5.java",
491      "android/java/src/org/chromium/base/MultiprocessTestClientService6.java",
492      "android/java/src/org/chromium/base/MultiprocessTestClientService7.java",
493      "android/java/src/org/chromium/base/MultiprocessTestClientService8.java",
494      "android/java/src/org/chromium/base/MultiprocessTestClientService9.java",
495      "android/java/src/org/chromium/base/MultiprocessTestClientServiceDelegate.java",
496    ]
497  }
498
499  android_aidl("test_support_java_aidl") {
500    testonly = true
501    import_include = [
502      "android/java/src",
503      "//base/android/java/src",
504    ]
505    sources = [
506      "android/java/src/org/chromium/base/ITestCallback.aidl",
507      "android/java/src/org/chromium/base/ITestController.aidl",
508    ]
509  }
510}
511
512if (is_ios) {
513  source_set("google_test_runner_shared_headers") {
514    sources = [ "ios/google_test_runner_delegate.h" ]
515  }
516
517  source_set("google_test_runner") {
518    sources = [ "ios/google_test_runner.mm" ]
519    deps = [ ":google_test_runner_shared_headers" ]
520    frameworks = [ "UIKit.framework" ]
521    configs += [ "//build/config/ios:xctest_config" ]
522  }
523}
524
525# Trivial executable which outputs space-delimited argv to stdout,
526# used for testing.
527executable("test_child_process") {
528  testonly = true
529  sources = [ "test_child_process.cc" ]
530}
531
532if (enable_base_tracing) {
533  perfetto_cc_proto_descriptor("gen_cc_chrome_track_event_descriptor") {
534    descriptor_name = "chrome_track_event.descriptor"
535    descriptor_target = "//base/tracing/protos:chrome_track_event"
536  }
537
538  import("//base/tracing/stdlib/chrome/perfetto_sql_files.gni")
539  action("amalgamated_perfetto_sql_stdlib") {
540    script = "//third_party/perfetto/tools/gen_amalgamated_sql.py"
541    sources = rebase_path(chrome_stdlib_sql_files,
542                          ".",
543                          "//base/tracing/stdlib/chrome")
544    stdlib_header = "$root_gen_dir/base/test/perfetto_sql_stdlib.h"
545    outputs = [ stdlib_header ]
546    args = [
547             "--namespace",
548             "chrome_stdlib",
549             "--cpp-out",
550             rebase_path(stdlib_header, root_build_dir),
551           ] + rebase_path(sources, root_build_dir)
552  }
553
554  # We encapsulate the trace processor in a separate shared library to prevent
555  # any duplicate symbol issues. Perfetto symbols are exported by chromium’s
556  # base via a public_dep on libperfetto; libtrace_processor also depends on
557  # these symbols. So we “hide” the perfetto symbols exported from this
558  # interface. Also, chrome targets depend on chromium_sqlite and the trace
559  # processor depends on dev_sqlite. The two share the same symbols but have
560  # different implementations, so we need to hide dev_sqlite in this shared
561  # library even in non-component builds to prevent duplicate symbols.
562  _target_type = "shared_library"
563  if (is_ios) {
564    _target_type = "ios_framework_bundle"
565  }
566
567  target(_target_type, "test_trace_processor") {
568    defines = [ "TEST_TRACE_PROCESSOR_IMPL" ]
569    testonly = true
570    sources = [
571      "test_trace_processor_export.h",
572      "test_trace_processor_impl.cc",
573      "test_trace_processor_impl.h",
574    ]
575    deps = [
576      "//third_party/abseil-cpp:absl",
577      "//third_party/perfetto:libtrace_processor",
578    ]
579    if (is_android) {
580      configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
581    }
582
583    if (is_ios) {
584      info_plist = "test_trace_processor_impl.plist"
585      output_name = "TestTraceProcessor"
586      bundle_deps_filter = [ "//third_party/icu:icudata" ]
587    }
588
589    # Set rpath on dependent tests so that they can find the shared library
590    # in a non-component build.
591    if (!is_component_build) {
592      all_dependent_configs = []
593      if (is_linux || is_chromeos) {
594        all_dependent_configs +=
595            [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
596      }
597      if (is_mac) {
598        # We need the lib to be in $root_out_dir/Libraries so the library is where
599        # the linker expects it, since we set the install_name flag. We need to
600        # set this flag so that the library can be found when it is bundled in the
601        # Content Shell Framework (see test_trace_processor_bundle_data).
602        output_dir = "$root_out_dir/Libraries"
603        ldflags = [ "-Wl,-install_name,@loader_path/Libraries/libtest_trace_processor.dylib" ]
604      }
605    }
606  }
607
608  if (!is_component_build && is_mac) {
609    bundle_data("test_trace_processor_bundle_data") {
610      testonly = true
611      sources = [ "$root_out_dir/Libraries/libtest_trace_processor.dylib" ]
612      outputs = [ "{{bundle_contents_dir}}/Libraries/{{source_file_part}}" ]
613      public_deps = [ ":test_trace_processor" ]
614    }
615  }
616} else if (!is_component_build && is_mac) {
617  # Provide a dummy target in order for clients to not have to special-case
618  # the dependency.
619  group("test_trace_processor_bundle_data") {
620    testonly = true
621  }
622}
623
624if (is_android) {
625  android_library("public_transit_java") {
626    testonly = true
627
628    deps = [
629      "//base:base_java",
630      "//base:base_java_test_support",
631      "//build/android:build_java",
632      "//third_party/android_deps:espresso_java",
633      "//third_party/android_deps:guava_android_java",
634      "//third_party/androidx:androidx_annotation_annotation_java",
635      "//third_party/androidx:androidx_core_core_java",
636      "//third_party/androidx:androidx_test_monitor_java",
637      "//third_party/hamcrest:hamcrest_java",
638      "//third_party/junit",
639    ]
640
641    sources = [
642      "android/javatests/src/org/chromium/base/test/transit/CallbackCondition.java",
643      "android/javatests/src/org/chromium/base/test/transit/Condition.java",
644      "android/javatests/src/org/chromium/base/test/transit/ConditionChecker.java",
645      "android/javatests/src/org/chromium/base/test/transit/ConditionWaiter.java",
646      "android/javatests/src/org/chromium/base/test/transit/ConditionalState.java",
647      "android/javatests/src/org/chromium/base/test/transit/Elements.java",
648      "android/javatests/src/org/chromium/base/test/transit/FacilityCheckIn.java",
649      "android/javatests/src/org/chromium/base/test/transit/FacilityCheckOut.java",
650      "android/javatests/src/org/chromium/base/test/transit/InstrumentationThreadCondition.java",
651      "android/javatests/src/org/chromium/base/test/transit/PublicTransitConfig.java",
652      "android/javatests/src/org/chromium/base/test/transit/StationFacility.java",
653      "android/javatests/src/org/chromium/base/test/transit/TrafficControl.java",
654      "android/javatests/src/org/chromium/base/test/transit/TransitAsserts.java",
655      "android/javatests/src/org/chromium/base/test/transit/TransitStation.java",
656      "android/javatests/src/org/chromium/base/test/transit/Transition.java",
657      "android/javatests/src/org/chromium/base/test/transit/TravelException.java",
658      "android/javatests/src/org/chromium/base/test/transit/Trip.java",
659      "android/javatests/src/org/chromium/base/test/transit/UiThreadCondition.java",
660      "android/javatests/src/org/chromium/base/test/transit/ViewConditions.java",
661    ]
662  }
663}
664