Unify test targets under perfetto_{tests,benchmarks}

To avoid collisions in chrome on binary names like base_unittests.
Also drop the ipc_test.cc which was a half demo and not really a
test. The full code and real tests will come in the next weeks.

Bug: 68710794
Change-Id: Ib472cc344e0a3316dfbad90108c9638647409809
diff --git a/.travis.yml b/.travis.yml
index 85e45f1..e432830 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -142,16 +142,9 @@
   - build/ninja -C out/dist -j8 all
   - |
     TEST_TARGETS="
-    perfetto_base_unittests
-    protozero_unittests
-    tracing_unittests
-    tracing_benchmarks
-    sanitizers_unittests
-    ftrace_reader_unittests
+    perfetto_tests
+    perfetto_benchmarks
     "
-
-    # TODO add ipc_unittests
-
     if [[ "$CFG" != android-* ]]; then
       for TEST_TARGET in $TEST_TARGETS; do
         "out/dist/$TEST_TARGET"
diff --git a/BUILD.gn b/BUILD.gn
index a9f9a35..7db89ed 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -17,27 +17,39 @@
 group("all") {
   testonly = true  # allow to build also test targets
   deps = [
-    ":tests",
+    ":perfetto_tests",
     "src/ftrace_reader:ftrace_reader_demo",
     "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
     "src/protozero/protoc_plugin($host_toolchain)",
     "tools/ftrace_proto_gen:ftrace_proto_gen",
   ]
+  if (!build_with_chromium) {
+    deps += [
+      ":perfetto_benchmarks",
+      "src/ftrace_reader:ftrace_reader_integrationtests",
+    ]
+  }
 }
 
-group("tests") {
+executable("perfetto_tests") {
   testonly = true
   deps = [
-    "src/base:perfetto_base_unittests",
-    "src/ftrace_reader:ftrace_reader_integrationtests",
+    "gn:default_deps",
+    "src/base:base_unittests",
     "src/ftrace_reader:ftrace_reader_unittests",
     "src/ipc:perfetto_ipc_unittests",
     "src/protozero:protozero_unittests",
     "src/tracing:tracing_unittests",
     "tools/sanitizers_unittests",
   ]
+}
 
-  if (!build_with_chromium) {
-    deps += [ "src/tracing:tracing_benchmarks" ]
+if (!build_with_chromium) {
+  executable("perfetto_benchmarks") {
+    testonly = true
+    deps = [
+      "gn:default_deps",
+      "src/tracing:tracing_benchmarks",
+    ]
   }
 }
diff --git a/build/run_android_test b/build/run_android_test
index c5a0443..83aa845 100755
--- a/build/run_android_test
+++ b/build/run_android_test
@@ -114,7 +114,8 @@
   parser = argparse.ArgumentParser()
   parser.add_argument('--no-cleanup', '-n', action='store_true')
   parser.add_argument('out_dir', help='out/android/')
-  parser.add_argument('test_name', help='tracing_unittests')
+  parser.add_argument('test_name', help='perfetto_tests',
+                      default='perfetto_tests')
   parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
   args = parser.parse_args()
 
diff --git a/src/base/BUILD.gn b/src/base/BUILD.gn
index 267d4b7..b91fccb 100644
--- a/src/base/BUILD.gn
+++ b/src/base/BUILD.gn
@@ -58,7 +58,7 @@
   ]
 }
 
-executable("perfetto_base_unittests") {
+source_set("base_unittests") {
   testonly = true
   deps = [
     ":base",
diff --git a/src/ftrace_reader/BUILD.gn b/src/ftrace_reader/BUILD.gn
index 2cd02e0..172638f 100644
--- a/src/ftrace_reader/BUILD.gn
+++ b/src/ftrace_reader/BUILD.gn
@@ -12,10 +12,23 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-executable("ftrace_reader_unittests") {
+source_set("test_support") {
+  testonly = true
+  deps = [
+    "../../gn:default_deps",
+    "../protozero",
+  ]
+  sources = [
+    "test/scattered_stream_delegate_for_testing.cc",
+    "test/scattered_stream_delegate_for_testing.h",
+  ]
+}
+
+source_set("ftrace_reader_unittests") {
   testonly = true
   deps = [
     ":ftrace_reader",
+    ":test_support",
     "../../gn:default_deps",
     "../../gn:gtest_deps",
     "../../gn:protobuf_full_deps",
@@ -27,7 +40,6 @@
     "ftrace_controller_unittest.cc",
     "ftrace_to_proto_unittest.cc",
     "proto_translation_table_unittest.cc",
-    "scattered_stream_delegate_for_testing.h",
   ]
 }
 
@@ -37,6 +49,7 @@
   testonly = true
   deps = [
     ":ftrace_reader",
+    ":test_support",
     "../../gn:default_deps",
     "../../gn:gtest_deps",
     "../../protos/ftrace:full",
@@ -55,6 +68,7 @@
   ]
   deps = [
     ":ftrace_reader",
+    ":test_support",
     "../../gn:default_deps",
     "../../gn:gtest_prod_config",
     "../base",
diff --git a/src/ftrace_reader/cpu_reader_unittest.cc b/src/ftrace_reader/cpu_reader_unittest.cc
index ebc9397..d9d10d7 100644
--- a/src/ftrace_reader/cpu_reader_unittest.cc
+++ b/src/ftrace_reader/cpu_reader_unittest.cc
@@ -21,7 +21,7 @@
 #include "proto_translation_table.h"
 
 #include "perfetto/protozero/scattered_stream_writer.h"
-#include "scattered_stream_delegate_for_testing.h"
+#include "src/ftrace_reader/test/scattered_stream_delegate_for_testing.h"
 
 #include "protos/ftrace/ftrace_event.pb.h"
 #include "protos/ftrace/ftrace_event_bundle.pb.h"
diff --git a/src/ftrace_reader/end_to_end_integrationtest.cc b/src/ftrace_reader/end_to_end_integrationtest.cc
index 53c764f..7e35ffa 100644
--- a/src/ftrace_reader/end_to_end_integrationtest.cc
+++ b/src/ftrace_reader/end_to_end_integrationtest.cc
@@ -24,7 +24,7 @@
 #include "perfetto/base/unix_task_runner.h"
 #include "perfetto/ftrace_reader/ftrace_controller.h"
 #include "perfetto/protozero/scattered_stream_writer.h"
-#include "scattered_stream_delegate_for_testing.h"
+#include "src/ftrace_reader/test/scattered_stream_delegate_for_testing.h"
 
 #include "protos/ftrace/ftrace_event_bundle.pb.h"
 #include "protos/ftrace/ftrace_event_bundle.pbzero.h"
diff --git a/src/ftrace_reader/main.cc b/src/ftrace_reader/main.cc
index f0b95c7..2f47f6b 100644
--- a/src/ftrace_reader/main.cc
+++ b/src/ftrace_reader/main.cc
@@ -27,7 +27,7 @@
 #include "perfetto/base/unix_task_runner.h"
 #include "perfetto/ftrace_reader/ftrace_controller.h"
 #include "perfetto/protozero/scattered_stream_writer.h"
-#include "scattered_stream_delegate_for_testing.h"
+#include "src/ftrace_reader/test/scattered_stream_delegate_for_testing.h"
 
 #include "protos/ftrace/ftrace_event_bundle.pbzero.h"
 
diff --git a/src/ftrace_reader/scattered_stream_delegate_for_testing.h b/src/ftrace_reader/test/scattered_stream_delegate_for_testing.cc
similarity index 64%
rename from src/ftrace_reader/scattered_stream_delegate_for_testing.h
rename to src/ftrace_reader/test/scattered_stream_delegate_for_testing.cc
index e27b170..fa6e178 100644
--- a/src/ftrace_reader/scattered_stream_delegate_for_testing.h
+++ b/src/ftrace_reader/test/scattered_stream_delegate_for_testing.cc
@@ -14,38 +14,10 @@
  * limitations under the License.
  */
 
-#ifndef SRC_FTRACE_READER_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_
-#define SRC_FTRACE_READER_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_
+#include "src/ftrace_reader/test/scattered_stream_delegate_for_testing.h"
 
 namespace perfetto {
 
-class ScatteredStreamDelegateForTesting
-    : public protozero::ScatteredStreamWriter::Delegate {
- public:
-  explicit ScatteredStreamDelegateForTesting(size_t chunk_size);
-  ~ScatteredStreamDelegateForTesting() override;
-
-  // protozero::ScatteredStreamWriter::Delegate implementation.
-  protozero::ContiguousMemoryRange GetNewBuffer() override;
-
-  // Stitch all the chunks into a single contiguous buffer.
-  std::unique_ptr<uint8_t[]> StitchChunks(size_t size);
-
-  const std::vector<std::unique_ptr<uint8_t[]>>& chunks() const {
-    return chunks_;
-  }
-
-  void set_writer(protozero::ScatteredStreamWriter* writer) {
-    writer_ = writer;
-  }
-
- private:
-  const size_t chunk_size_;
-  protozero::ScatteredStreamWriter* writer_ = nullptr;
-  std::vector<size_t> chunks_used_size_;
-  std::vector<std::unique_ptr<uint8_t[]>> chunks_;
-};
-
 ScatteredStreamDelegateForTesting::ScatteredStreamDelegateForTesting(
     size_t chunk_size)
     : chunk_size_(chunk_size) {}
@@ -87,5 +59,3 @@
 }
 
 }  // namespace perfetto
-
-#endif  // SRC_FTRACE_READER_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_
diff --git a/src/ftrace_reader/test/scattered_stream_delegate_for_testing.h b/src/ftrace_reader/test/scattered_stream_delegate_for_testing.h
new file mode 100644
index 0000000..a743577
--- /dev/null
+++ b/src/ftrace_reader/test/scattered_stream_delegate_for_testing.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#ifndef SRC_FTRACE_READER_TEST_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_
+#define SRC_FTRACE_READER_TEST_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_
+
+#include <memory>
+#include <vector>
+
+#include "perfetto/base/logging.h"
+#include "perfetto/protozero/scattered_stream_writer.h"
+
+namespace perfetto {
+
+class ScatteredStreamDelegateForTesting
+    : public protozero::ScatteredStreamWriter::Delegate {
+ public:
+  explicit ScatteredStreamDelegateForTesting(size_t chunk_size);
+  ~ScatteredStreamDelegateForTesting() override;
+
+  // protozero::ScatteredStreamWriter::Delegate implementation.
+  protozero::ContiguousMemoryRange GetNewBuffer() override;
+
+  // Stitch all the chunks into a single contiguous buffer.
+  std::unique_ptr<uint8_t[]> StitchChunks(size_t size);
+
+  const std::vector<std::unique_ptr<uint8_t[]>>& chunks() const {
+    return chunks_;
+  }
+
+  void set_writer(protozero::ScatteredStreamWriter* writer) {
+    writer_ = writer;
+  }
+
+ private:
+  const size_t chunk_size_;
+  protozero::ScatteredStreamWriter* writer_ = nullptr;
+  std::vector<size_t> chunks_used_size_;
+  std::vector<std::unique_ptr<uint8_t[]>> chunks_;
+};
+
+}  // namespace perfetto
+
+#endif  // SRC_FTRACE_READER_TEST_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_
diff --git a/src/ipc/BUILD.gn b/src/ipc/BUILD.gn
index a42e2fe..1439094 100644
--- a/src/ipc/BUILD.gn
+++ b/src/ipc/BUILD.gn
@@ -38,7 +38,7 @@
   ]
 }
 
-executable("perfetto_ipc_unittests") {
+source_set("perfetto_ipc_unittests") {
   testonly = true
   deps = [
     ":ipc",
diff --git a/src/ipc/client_impl_unittest.cc b/src/ipc/client_impl_unittest.cc
index 769ee47..2268943 100644
--- a/src/ipc/client_impl_unittest.cc
+++ b/src/ipc/client_impl_unittest.cc
@@ -28,6 +28,7 @@
 #include "perfetto/ipc/service_proxy.h"
 #include "src/base/test/test_task_runner.h"
 #include "src/ipc/buffered_frame_deserializer.h"
+#include "src/ipc/test/test_socket.h"
 #include "src/ipc/unix_socket.h"
 
 #include "src/ipc/test/client_unittest_messages.pb.h"
@@ -41,7 +42,7 @@
 using ::testing::Invoke;
 using ::testing::Mock;
 
-constexpr char kSockName[] = "/tmp/perfetto_client_impl_unittest.sock";
+constexpr char kSockName[] = TEST_SOCK_NAME("client_impl_unittest");
 
 // A fake ServiceProxy. This fakes the client-side class that would be
 // auto-generated from .proto-files.
@@ -99,11 +100,11 @@
   };  // FakeService.
 
   explicit FakeHost(base::TaskRunner* task_runner) {
-    unlink(kSockName);
+    DESTROY_TEST_SOCK(kSockName);
     listening_sock = UnixSocket::Listen(kSockName, this, task_runner);
     EXPECT_TRUE(listening_sock->is_listening());
   }
-  ~FakeHost() override { unlink(kSockName); }
+  ~FakeHost() override { DESTROY_TEST_SOCK(kSockName); }
 
   FakeService* AddFakeService(const std::string& name) {
     auto it_and_inserted =
@@ -458,6 +459,7 @@
   proxy->BeginInvoke("FakeMethod1", req, std::move(deferred_reply));
   EXPECT_CALL(proxy_events_, OnDisconnect());
   cli_.reset();
+  host_.reset();  // Prevent spurious OnInvoke callbacks on the fake host.
   task_runner_->RunUntilCheckpoint("on_reject");
 }
 
diff --git a/src/ipc/host_impl_unittest.cc b/src/ipc/host_impl_unittest.cc
index 72ab226..46e905b 100644
--- a/src/ipc/host_impl_unittest.cc
+++ b/src/ipc/host_impl_unittest.cc
@@ -25,6 +25,7 @@
 #include "perfetto/ipc/service_descriptor.h"
 #include "src/base/test/test_task_runner.h"
 #include "src/ipc/buffered_frame_deserializer.h"
+#include "src/ipc/test/test_socket.h"
 #include "src/ipc/unix_socket.h"
 
 #include "src/ipc/test/client_unittest_messages.pb.h"
@@ -38,7 +39,7 @@
 using ::testing::Invoke;
 using ::testing::InvokeWithoutArgs;
 
-constexpr char kSockName[] = "/tmp/perfetto_host_impl_unittest.sock";
+constexpr char kSockName[] = TEST_SOCK_NAME("host_impl_unittest.sock");
 
 // RequestProto and ReplyProto are defined in client_unittest_messages.proto.
 
@@ -155,7 +156,7 @@
 class HostImplTest : public ::testing::Test {
  public:
   void SetUp() override {
-    unlink(kSockName);
+    DESTROY_TEST_SOCK(kSockName);
     task_runner_.reset(new base::TestTaskRunner());
     Host* host = Host::CreateInstance(kSockName, task_runner_.get()).release();
     ASSERT_NE(nullptr, host);
@@ -172,7 +173,7 @@
     host_.reset();
     task_runner_->RunUntilIdle();
     task_runner_.reset();
-    unlink(kSockName);
+    DESTROY_TEST_SOCK(kSockName);
   }
 
   // ::testing::StrictMock<MockEventListener> proxy_events_;
diff --git a/src/ipc/test/ipc_integrationtest.cc b/src/ipc/test/ipc_integrationtest.cc
index 6addb28..9a299c3 100644
--- a/src/ipc/test/ipc_integrationtest.cc
+++ b/src/ipc/test/ipc_integrationtest.cc
@@ -19,6 +19,7 @@
 #include "perfetto/ipc/client.h"
 #include "perfetto/ipc/host.h"
 #include "src/base/test/test_task_runner.h"
+#include "src/ipc/test/test_socket.h"
 
 #include "src/ipc/test/greeter_service.ipc.h"
 #include "src/ipc/test/greeter_service.pb.h"
@@ -35,7 +36,7 @@
 using ::perfetto::ipc::Service;
 using ::perfetto::ipc::ServiceProxy;
 
-constexpr char kSockName[] = "/tmp/perfetto_ipc_test.sock";
+constexpr char kSockName[] = TEST_SOCK_NAME("ipc_integrationtest");
 
 class MockEventListener : public ServiceProxy::EventListener {
  public:
@@ -62,8 +63,8 @@
 
 class IPCIntegrationTest : public ::testing::Test {
  protected:
-  void SetUp() override { unlink(kSockName); }
-  void TearDown() override { unlink(kSockName); }
+  void SetUp() override { DESTROY_TEST_SOCK(kSockName); }
+  void TearDown() override { DESTROY_TEST_SOCK(kSockName); }
 
   perfetto::base::TestTaskRunner task_runner_;
   MockEventListener svc_proxy_events_;
diff --git a/src/ipc/test/test_socket.h b/src/ipc/test/test_socket.h
new file mode 100644
index 0000000..1702549
--- /dev/null
+++ b/src/ipc/test/test_socket.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#ifndef SRC_IPC_TEST_TEST_SOCKET_H_
+#define SRC_IPC_TEST_TEST_SOCKET_H_
+
+#include "perfetto/base/build_config.h"
+
+#if BUILDFLAG(OS_ANDROID)
+#define TEST_SOCK_NAME(x) "@" x
+#define DESTROY_TEST_SOCK(x) \
+  do {                       \
+  } while (0)
+#else
+#include <unistd.h>
+#define TEST_SOCK_NAME(x) "/tmp/" x ".sock"
+#define DESTROY_TEST_SOCK(x) unlink(x)
+#endif
+
+#endif  // SRC_IPC_TEST_TEST_SOCKET_H_
diff --git a/src/ipc/unix_socket_unittest.cc b/src/ipc/unix_socket_unittest.cc
index e5586a8..ed7d664 100644
--- a/src/ipc/unix_socket_unittest.cc
+++ b/src/ipc/unix_socket_unittest.cc
@@ -26,6 +26,7 @@
 #include "perfetto/base/logging.h"
 #include "perfetto/base/utils.h"
 #include "src/base/test/test_task_runner.h"
+#include "src/ipc/test/test_socket.h"
 
 namespace perfetto {
 namespace ipc {
@@ -35,16 +36,7 @@
 using ::testing::Invoke;
 using ::testing::Mock;
 
-// Mac OS X doesn't support abstract (i.e. unnamed) sockets.
-#if BUILDFLAG(OS_MACOSX)
-static const char kSocketName[] = "/tmp/test_socket";
-void UnlinkSocket() {
-  unlink(kSocketName);
-}
-#else
-static const char kSocketName[] = "@test_socket";
-void UnlinkSocket() {}
-#endif
+static const char kSocketName[] = TEST_SOCK_NAME("unix_socket_unittest");
 
 class MockEventListener : public UnixSocket::EventListener {
  public:
@@ -75,8 +67,8 @@
 
 class UnixSocketTest : public ::testing::Test {
  protected:
-  void SetUp() override { UnlinkSocket(); }
-  void TearDown() override { UnlinkSocket(); }
+  void SetUp() override { DESTROY_TEST_SOCK(kSocketName); }
+  void TearDown() override { DESTROY_TEST_SOCK(kSocketName); }
 
   base::TestTaskRunner task_runner_;
   MockEventListener event_listener_;
diff --git a/src/protozero/BUILD.gn b/src/protozero/BUILD.gn
index 885d934..0640efb 100644
--- a/src/protozero/BUILD.gn
+++ b/src/protozero/BUILD.gn
@@ -34,7 +34,7 @@
   ]
 }
 
-executable("protozero_unittests") {
+source_set("protozero_unittests") {
   testonly = true
   deps = [
     ":protozero",
diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn
index 4723c4e..8bcf572 100644
--- a/src/tracing/BUILD.gn
+++ b/src/tracing/BUILD.gn
@@ -67,7 +67,7 @@
   ]
 }
 
-executable("tracing_unittests") {
+source_set("tracing_unittests") {
   testonly = true
   deps = [
     ":ipc",
@@ -86,24 +86,8 @@
   ]
 }
 
-executable("tracing_test") {
-  testonly = true
-  deps = [
-    ":ipc",
-    ":ipc_protos",
-    ":tracing",
-    "../../gn:default_deps",
-    "../base",
-    "../base:test_support",
-    "../ipc",
-  ]
-  sources = [
-    "test/ipc_test.cc",
-  ]
-}
-
 if (!build_with_chromium) {
-  executable("tracing_benchmarks") {
+  source_set("tracing_benchmarks") {
     testonly = true
     deps = [
       "../../gn:default_deps",
diff --git a/src/tracing/test/ipc_test.cc b/src/tracing/test/ipc_test.cc
deleted file mode 100644
index 09e4a0a..0000000
--- a/src/tracing/test/ipc_test.cc
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "perfetto/base/logging.h"
-#include "perfetto/tracing/core/data_source_config.h"
-#include "perfetto/tracing/core/data_source_descriptor.h"
-#include "perfetto/tracing/core/producer.h"
-#include "perfetto/tracing/core/service.h"
-#include "perfetto/tracing/ipc/producer_ipc_client.h"
-#include "perfetto/tracing/ipc/service_ipc_host.h"
-#include "src/base/test/test_task_runner.h"
-#include "src/tracing/core/service_impl.h"
-#include "src/tracing/ipc/posix_shared_memory.h"
-#include "src/tracing/ipc/producer/producer_ipc_client_impl.h"
-#include "src/tracing/ipc/service/service_ipc_host_impl.h"
-
-namespace perfetto {
-
-namespace {
-
-const char kSocketName[] = "/tmp/perfetto-ipc-test.sock";
-
-class TestProducer : public Producer {
- public:
-  void OnConnect() override {
-    PERFETTO_DLOG("Connected as Producer");
-    if (on_connect)
-      on_connect();
-  }
-
-  void OnDisconnect() override {
-    PERFETTO_DLOG("Disconnected from tracing service");
-  }
-
-  void CreateDataSourceInstance(DataSourceInstanceID dsid,
-                                const DataSourceConfig& cfg) override {
-    PERFETTO_DLOG(
-        "The tracing service requested us to start a new data source %" PRIu64
-        ", config: %s",
-        dsid, cfg.trace_category_filters.c_str());
-  }
-
-  void TearDownDataSourceInstance(DataSourceInstanceID instance_id) override {
-    PERFETTO_DLOG(
-        "The tracing service requested us to shutdown the data source %" PRIu64,
-        instance_id);
-  }
-
-  std::function<void()> on_connect;
-};
-
-void __attribute__((noreturn)) ProducerMain() {
-  base::TestTaskRunner task_runner;
-  TestProducer producer;
-  std::unique_ptr<Service::ProducerEndpoint> endpoint =
-      ProducerIPCClient::Connect(kSocketName, &producer, &task_runner);
-  producer.on_connect = task_runner.CreateCheckpoint("connect");
-  task_runner.RunUntilCheckpoint("connect");
-
-  for (int i = 0; i < 3; i++) {
-    DataSourceDescriptor descriptor;
-    descriptor.name = "perfetto.test.data_source";
-    auto reg_checkpoint =
-        task_runner.CreateCheckpoint("register" + std::to_string(i));
-    auto on_register = [reg_checkpoint](DataSourceID id) {
-      printf("Service acked RegisterDataSource() with ID %" PRIu64 "\n", id);
-      reg_checkpoint();
-    };
-    endpoint->RegisterDataSource(descriptor, on_register);
-    task_runner.RunUntilCheckpoint("register" + std::to_string(i));
-
-    auto* ipc_client = static_cast<ProducerIPCClientImpl*>(endpoint.get());
-    void* shm = ipc_client->shared_memory()->start();
-    char buf[32];
-    memcpy(buf, shm, sizeof(buf));
-    buf[sizeof(buf) - 1] = '\0';
-    printf("Shared Memory contents: \"%s\"\n", buf);
-  }
-  task_runner.Run();
-}
-
-void __attribute__((noreturn)) ServiceMain() {
-  unlink(kSocketName);
-  base::TestTaskRunner task_runner;
-  std::unique_ptr<ServiceIPCHostImpl> host(static_cast<ServiceIPCHostImpl*>(
-      ServiceIPCHost::CreateInstance(&task_runner).release()));
-
-  class Observer : public Service::ObserverForTesting {
-   public:
-    explicit Observer(ServiceImpl* svc) : svc_(svc) {}
-    void OnProducerConnected(ProducerID prid) override {
-      printf("Producer connected: ID=%" PRIu64 "\n", prid);
-    }
-
-    void OnProducerDisconnected(ProducerID prid) override {
-      printf("Producer disconnected: ID=%" PRIu64 "\n", prid);
-    }
-
-    void OnDataSourceRegistered(ProducerID prid, DataSourceID dsid) override {
-      printf("Data source registered, Producer=%" PRIu64 " DataSource=%" PRIu64
-             "\n",
-             prid, dsid);
-      DataSourceConfig cfg;
-      cfg.trace_category_filters = "foo,bar";
-      SharedMemory* shm = svc_->GetProducer(prid)->shared_memory();
-      char shm_contents[32];
-      sprintf(shm_contents, "shmem @ iteration %" PRIu64, dsid);
-      memcpy(shm->start(), shm_contents, sizeof(shm_contents));
-      svc_->GetProducer(prid)->producer()->CreateDataSourceInstance(42, cfg);
-    }
-
-    void OnDataSourceUnregistered(ProducerID prid, DataSourceID dsid) override {
-      printf("Data source unregistered, Producer=%" PRIu64
-             " DataSource=%" PRIu64 "\n",
-             prid, dsid);
-    }
-
-    ServiceImpl* svc_;
-  };
-
-  host->Start(kSocketName);
-  Observer observer(static_cast<ServiceImpl*>(host->service_for_testing()));
-  host->service_for_testing()->set_observer_for_testing(&observer);
-  task_runner.Run();
-}
-
-}  // namespace.
-}  // namespace perfetto
-
-int main(int argc, char** argv) {
-  if (argc == 2 && !strcmp(argv[1], "producer"))
-    perfetto::ProducerMain();
-  if (argc == 2 && !strcmp(argv[1], "service"))
-    perfetto::ServiceMain();
-
-  fprintf(stderr, "Usage: %s producer | service\n", argv[0]);
-  return 1;
-}
diff --git a/tools/sanitizers_unittests/BUILD.gn b/tools/sanitizers_unittests/BUILD.gn
index 02de5df..72c6c5c 100644
--- a/tools/sanitizers_unittests/BUILD.gn
+++ b/tools/sanitizers_unittests/BUILD.gn
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-executable("sanitizers_unittests") {
+source_set("sanitizers_unittests") {
   testonly = true
   deps = [
     "../../gn:default_deps",