# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("../../../gn/perfetto.gni")
import("../../../gn/test.gni")

# Core tracing library, platform independent, no IPC layer, no service.
source_set("core") {
  public_deps = [
    "../../../include/perfetto/ext/tracing/core",
    "../../protozero",
  ]
  deps = [
    "..:common",
    "../../../gn:default_deps",
    "../../../include/perfetto/tracing",
    "../../../protos/perfetto/trace:zero",
    "../../base",
  ]
  sources = [
    "id_allocator.cc",
    "id_allocator.h",
    "in_process_shared_memory.cc",
    "in_process_shared_memory.h",
    "null_trace_writer.cc",
    "null_trace_writer.h",
    "patch_list.h",
    "shared_memory_abi.cc",
    "shared_memory_arbiter_impl.cc",
    "shared_memory_arbiter_impl.h",
    "trace_packet.cc",
    "trace_writer_impl.cc",
    "trace_writer_impl.h",
    "virtual_destructors.cc",
  ]
}

perfetto_unittest_source_set("unittests") {
  testonly = true
  deps = [
    ":core",
    "../../../gn:default_deps",
    "../../../gn:gtest_and_gmock",
    "../../../protos/perfetto/trace:cpp",
    "../../../protos/perfetto/trace:zero",
    "../../../protos/perfetto/trace/ftrace:cpp",
    "../../../protos/perfetto/trace/perfetto:cpp",
    "../../../src/protozero/filtering:bytecode_generator",
    "../../base",
    "../../base:test_support",
    "../test:test_support",
  ]

  sources = [
    "id_allocator_unittest.cc",
    "null_trace_writer_unittest.cc",
    "patch_list_unittest.cc",
    "shared_memory_abi_unittest.cc",
    "trace_packet_unittest.cc",
  ]

  # These tests rely on test_task_runner.h which
  # has no Windows implementation.
  if (!is_win) {
    sources += [
      "shared_memory_arbiter_impl_unittest.cc",
      "trace_writer_impl_unittest.cc",
    ]
  }
}

perfetto_unittest_source_set("test_support") {
  testonly = true
  public_deps = [
    "../../../include/perfetto/ext/tracing/core",
    "../../../protos/perfetto/trace:cpp",
    "../../../protos/perfetto/trace:zero",
    "../../protozero",
  ]
  sources = [
    "trace_writer_for_testing.cc",
    "trace_writer_for_testing.h",
  ]
}
