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/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_;