Fix fuzzer build

Removes dependencies on gtest from fuzzer target. In turn this
implies removing gtest deps from base:test_support.
The fuzzer build has beeen failing in a very mysterious way for
a while (https://pastebin.com/1Ana2BnY).
The failure seems to go away by removing gtest dependencies
from the fuzzer targets.
I bisected the change to the point where I just removed the
googletest/googletest/src/gtest-all.cc from the gtest target.
I don't have a full explanation of what's happening. I can only
observe that when gtest is built as part of a fuzzer build, the
FuzzerDriver constructor fails with this https://pastebin.com/TeXPD5X9
while initializing it's piecewise_constant_distribution member.
The failure becomes more evident if building with is_debug=true.
I suspect some static initializer in gtest somehow corrupts the
state of <random> in a way that libfuzzer doesn't like.

Test: build and run trace_processor_fuzzer
Change-Id: Ic3da3625835644896705aa7443c1be6ec91069bc
diff --git a/Android.bp b/Android.bp
index 15e84a4..924cf8c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -892,6 +892,7 @@
     "test/end_to_end_integrationtest.cc",
     "test/fake_producer.cc",
     "test/task_runner_thread.cc",
+    "test/task_runner_thread_delegates.cc",
     "test/test_helper.cc",
   ],
   shared_libs: [
@@ -4181,6 +4182,7 @@
     "test/end_to_end_integrationtest.cc",
     "test/fake_producer.cc",
     "test/task_runner_thread.cc",
+    "test/task_runner_thread_delegates.cc",
     "test/test_helper.cc",
   ],
   export_include_dirs: [
@@ -4206,6 +4208,7 @@
     "src/base/android_task_runner.cc",
     "src/base/test/test_task_runner.cc",
     "test/fake_producer.cc",
+    "test/task_runner_thread_delegates.cc",
   ],
   shared_libs: [
     "libprotobuf-cpp-lite",
diff --git a/Android.bp.extras b/Android.bp.extras
index 54de0c9..a2db5ed 100644
--- a/Android.bp.extras
+++ b/Android.bp.extras
@@ -14,6 +14,7 @@
     "test/end_to_end_integrationtest.cc",
     "test/fake_producer.cc",
     "test/task_runner_thread.cc",
+    "test/task_runner_thread_delegates.cc",
     "test/test_helper.cc",
   ],
   export_include_dirs: [
@@ -39,6 +40,7 @@
     "src/base/android_task_runner.cc",
     "src/base/test/test_task_runner.cc",
     "test/fake_producer.cc",
+    "test/task_runner_thread_delegates.cc",
   ],
   shared_libs: [
     "libprotobuf-cpp-lite",
diff --git a/gn/standalone/sanitizers/sanitizers.gni b/gn/standalone/sanitizers/sanitizers.gni
index 95f40d1..9b0ec00 100644
--- a/gn/standalone/sanitizers/sanitizers.gni
+++ b/gn/standalone/sanitizers/sanitizers.gni
@@ -54,8 +54,3 @@
     }
   }
 }
-
-using_sanitizer = is_asan || is_lsan || is_tsan || is_msan || is_ubsan
-assert(!using_sanitizer || is_clang, "is_*san requires is_clang=true'")
-assert(!is_msan || is_linux, "msan only supported on linux")
-assert(!is_tsan || (is_linux || is_mac), "tsan only supported on linux and mac")
diff --git a/src/base/BUILD.gn b/src/base/BUILD.gn
index ac5868c..043225b 100644
--- a/src/base/BUILD.gn
+++ b/src/base/BUILD.gn
@@ -113,7 +113,6 @@
   deps = [
     ":base",
     "../../gn:default_deps",
-    "../../gn:gtest_and_gmock",
   ]
   sources = [
     "test/utils.cc",
diff --git a/src/base/test/utils.h b/src/base/test/utils.h
index 2884b57..c2125e7 100644
--- a/src/base/test/utils.h
+++ b/src/base/test/utils.h
@@ -19,10 +19,8 @@
 
 #include <string>
 
-#include <gtest/gtest.h>
 #include "perfetto/base/logging.h"
 
-#if defined(GTEST_HAS_DEATH_TEST)
 #if PERFETTO_DCHECK_IS_ON()
 
 #define EXPECT_DCHECK_DEATH(statement) EXPECT_DEATH(statement, "PERFETTO_CHECK")
@@ -36,7 +34,6 @@
     GTEST_EXECUTE_STATEMENT_(statement, "PERFETTO_CHECK")
 
 #endif  // PERFETTO_DCHECK_IS_ON()
-#endif  // defined(GTEST_HAS_DEATH_TEST)
 
 namespace perfetto {
 namespace base {
diff --git a/src/base/test/vm_test_utils.cc b/src/base/test/vm_test_utils.cc
index 58a81a6..0c0a1a6 100644
--- a/src/base/test/vm_test_utils.cc
+++ b/src/base/test/vm_test_utils.cc
@@ -32,15 +32,15 @@
 #include <sys/stat.h>
 #endif
 
-#include <gtest/gtest.h>
 #include "perfetto/base/build_config.h"
+#include "perfetto/base/logging.h"
 
 namespace perfetto {
 namespace base {
 namespace vm_test_utils {
 
 bool IsMapped(void* start, size_t size) {
-  EXPECT_EQ(0u, size % kPageSize);
+  PERFETTO_CHECK(size % kPageSize == 0);
 #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
   int retries = 5;
   int number_of_entries = 4000;  // Just a guess.
@@ -61,10 +61,7 @@
     if (QueryWorkingSet(GetCurrentProcess(), &buffer[0], buffer_size))
       break;  // Success
 
-    if (GetLastError() != ERROR_BAD_LENGTH) {
-      EXPECT_EQ(true, false);
-      return false;
-    }
+    PERFETTO_CHECK(GetLastError() == ERROR_BAD_LENGTH);
 
     number_of_entries = ws_info->NumberOfEntries;
 
@@ -72,11 +69,7 @@
     // take that into account. Increasing by 10% should generally be enough.
     number_of_entries *= 1.1;
 
-    if (--retries == 0) {
-      // If we're looping, eventually fail.
-      EXPECT_EQ(true, false);
-      return false;
-    }
+    PERFETTO_CHECK(--retries > 0);  // If we're looping, eventually fail.
   }
 
   void* end = reinterpret_cast<char*>(start) + size;
@@ -112,7 +105,7 @@
   // MacOS instead returns 0 but leaves the page_states empty.
   if (res == -1 && errno == ENOMEM)
     return false;
-  EXPECT_EQ(0, res);
+  PERFETTO_CHECK(res == 0);
   for (size_t i = 0; i < num_pages; i++) {
     if (!(page_states[i] & kIncoreMask))
       return false;
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index aa3ccab..08ebf91 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -323,12 +323,6 @@
   deps = [
     ":lib",
     "../../gn:default_deps",
-    "../../gn:default_deps",
-    "../../gn:gtest_and_gmock",
-    "../../gn:sqlite",
-    "../../protos/perfetto/trace:lite",
-    "../../protos/perfetto/trace_processor:lite",
     "../base",
-    "../base:test_support",
   ]
 }
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 8805cec..69a7513 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -110,6 +110,7 @@
   sources = [
     "fake_producer.cc",
     "fake_producer.h",
+    "task_runner_thread_delegates.cc",
     "task_runner_thread_delegates.h",
   ]
 }
diff --git a/test/end_to_end_shared_memory_fuzzer.cc b/test/end_to_end_shared_memory_fuzzer.cc
index 3ac92bb..c92842b 100644
--- a/test/end_to_end_shared_memory_fuzzer.cc
+++ b/test/end_to_end_shared_memory_fuzzer.cc
@@ -98,7 +98,7 @@
   void StopDataSource(DataSourceInstanceID) override {}
   void OnTracingSetup() override {}
   void Flush(FlushRequestID, const DataSourceInstanceID*, size_t) override {}
-  void ClearIncrementalState(const DataSourceInstanceID*, size_t) {}
+  void ClearIncrementalState(const DataSourceInstanceID*, size_t) override {}
 
  private:
   const std::string name_;
diff --git a/test/fake_producer.cc b/test/fake_producer.cc
index 944c8cb..0df0b71 100644
--- a/test/fake_producer.cc
+++ b/test/fake_producer.cc
@@ -19,7 +19,6 @@
 #include <condition_variable>
 #include <mutex>
 
-#include <gtest/gtest.h>
 #include "perfetto/base/logging.h"
 #include "perfetto/ext/base/time.h"
 #include "perfetto/ext/base/utils.h"
@@ -58,7 +57,7 @@
 
 void FakeProducer::OnDisconnect() {
   PERFETTO_DCHECK_THREAD(thread_checker_);
-  FAIL() << "Producer unexpectedly disconnected from the service";
+  PERFETTO_FATAL("Producer unexpectedly disconnected from the service");
 }
 
 void FakeProducer::SetupDataSource(DataSourceInstanceID,
diff --git a/test/task_runner_thread_delegates.cc b/test/task_runner_thread_delegates.cc
new file mode 100644
index 0000000..291482f
--- /dev/null
+++ b/test/task_runner_thread_delegates.cc
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2019 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 "test/task_runner_thread_delegates.h"
+
+namespace perfetto {
+
+ServiceDelegate::~ServiceDelegate() = default;
+ProbesProducerDelegate::~ProbesProducerDelegate() = default;
+FakeProducerDelegate::~FakeProducerDelegate() = default;
+
+}  // namespace perfetto
diff --git a/test/task_runner_thread_delegates.h b/test/task_runner_thread_delegates.h
index dc19c0a..bea384a 100644
--- a/test/task_runner_thread_delegates.h
+++ b/test/task_runner_thread_delegates.h
@@ -29,7 +29,7 @@
   ServiceDelegate(const std::string& producer_socket,
                   const std::string& consumer_socket)
       : producer_socket_(producer_socket), consumer_socket_(consumer_socket) {}
-  ~ServiceDelegate() override = default;
+  ~ServiceDelegate() override;
 
   void Initialize(base::TaskRunner* task_runner) override {
     svc_ = ServiceIPCHost::CreateInstance(task_runner);
@@ -49,7 +49,7 @@
  public:
   ProbesProducerDelegate(const std::string& producer_socket)
       : producer_socket_(producer_socket) {}
-  ~ProbesProducerDelegate() override = default;
+  ~ProbesProducerDelegate() override;
 
   void Initialize(base::TaskRunner* task_runner) override {
     producer_.reset(new ProbesProducer);
@@ -69,7 +69,7 @@
       : producer_socket_(producer_socket),
         setup_callback_(std::move(setup_callback)),
         connect_callback_(std::move(connect_callback)) {}
-  ~FakeProducerDelegate() override = default;
+  ~FakeProducerDelegate() override;
 
   void Initialize(base::TaskRunner* task_runner) override {
     producer_.reset(new FakeProducer("android.perfetto.FakeProducer"));
diff --git a/test/test_helper.cc b/test/test_helper.cc
index a64794e..7ad5cba 100644
--- a/test/test_helper.cc
+++ b/test/test_helper.cc
@@ -16,7 +16,6 @@
 
 #include "test/test_helper.h"
 
-#include <gtest/gtest.h>
 #include "perfetto/ext/traced/traced.h"
 #include "perfetto/ext/tracing/core/trace_packet.h"
 #include "test/task_runner_thread_delegates.h"
@@ -52,7 +51,7 @@
 }
 
 void TestHelper::OnDisconnect() {
-  FAIL() << "Consumer unexpectedly disconnected from the service";
+  PERFETTO_FATAL("Consumer unexpectedly disconnected from the service");
 }
 
 void TestHelper::OnTracingDisabled() {
@@ -62,14 +61,14 @@
 void TestHelper::OnTraceData(std::vector<TracePacket> packets, bool has_more) {
   for (auto& encoded_packet : packets) {
     protos::TracePacket packet;
-    ASSERT_TRUE(encoded_packet.Decode(&packet));
+    PERFETTO_CHECK(encoded_packet.Decode(&packet));
     if (packet.has_clock_snapshot() || packet.has_trace_config() ||
         packet.has_trace_stats() || !packet.synchronization_marker().empty() ||
         packet.has_system_info()) {
       continue;
     }
-    ASSERT_EQ(protos::TracePacket::kTrustedUid,
-              packet.optional_trusted_uid_case());
+    PERFETTO_CHECK(packet.optional_trusted_uid_case() ==
+                   protos::TracePacket::kTrustedUid);
     trace_.push_back(std::move(packet));
   }