[GWP-ASan] Port tests to Fuchsia

This modifies the tests so that they can be run on Fuchsia:
- add the necessary includes for `set`/`vector` etc
- do the few modifications required to use zxtest instead og gtest

`backtrace.cpp` requires stacktrace support that Fuchsia doesn't have
yet, and `enable_disable.cpp` currently uses `fork()` which Fuchsia
doesn't support yet. I'll revisit this later.

I chose to use `harness.h` to hold my "platform-specific" include and
namespace, and using this header in tests rather than `gtest.h`,
which I am open to change if someone would rather go another direction.

Differential Revision: https://reviews.llvm.org/D91575

GitOrigin-RevId: 5556616b5b5223f95607ad94053a55f0deaf2762
diff --git a/tests/alignment.cpp b/tests/alignment.cpp
index bf98f1f..2489ff8 100644
--- a/tests/alignment.cpp
+++ b/tests/alignment.cpp
@@ -9,6 +9,8 @@
 #include "gwp_asan/tests/harness.h"
 #include "gwp_asan/utilities.h"
 
+#include <vector>
+
 TEST(AlignmentTest, PowerOfTwo) {
   std::vector<std::pair<size_t, size_t>> AskedSizeToAlignedSize = {
       {1, 1},   {2, 2},   {3, 4},       {4, 4},       {5, 8},   {7, 8},
diff --git a/tests/compression.cpp b/tests/compression.cpp
index 7a5894d..2423c86 100644
--- a/tests/compression.cpp
+++ b/tests/compression.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "gwp_asan/stack_trace_compressor.h"
-#include "gtest/gtest.h"
+#include "gwp_asan/tests/harness.h"
 
 namespace gwp_asan {
 namespace compression {
diff --git a/tests/crash_handler_api.cpp b/tests/crash_handler_api.cpp
index 10a014e..cb30636 100644
--- a/tests/crash_handler_api.cpp
+++ b/tests/crash_handler_api.cpp
@@ -16,7 +16,7 @@
 using AllocationMetadata = gwp_asan::AllocationMetadata;
 using AllocatorState = gwp_asan::AllocatorState;
 
-class CrashHandlerAPITest : public ::testing::Test {
+class CrashHandlerAPITest : public Test {
 public:
   void SetUp() override { setupState(); }
 
diff --git a/tests/driver.cpp b/tests/driver.cpp
index b402cec..02ab360 100644
--- a/tests/driver.cpp
+++ b/tests/driver.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
+#include "gwp_asan/tests/harness.h"
 
 int main(int argc, char **argv) {
   testing::InitGoogleTest(&argc, argv);
diff --git a/tests/harness.cpp b/tests/harness.cpp
index 77c25ee..e668c73 100644
--- a/tests/harness.cpp
+++ b/tests/harness.cpp
@@ -1,4 +1,12 @@
-#include "harness.h"
+//===-- harness.cpp ---------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "gwp_asan/tests/harness.h"
 
 namespace gwp_asan {
 namespace test {
diff --git a/tests/harness.h b/tests/harness.h
index d303b2c..26be4a4 100644
--- a/tests/harness.h
+++ b/tests/harness.h
@@ -11,7 +11,13 @@
 
 #include <stdarg.h>
 
+#if defined(__Fuchsia__)
+#include <zxtest/zxtest.h>
+using Test = ::zxtest::Test;
+#else
 #include "gtest/gtest.h"
+using Test = ::testing::Test;
+#endif
 
 #include "gwp_asan/guarded_pool_allocator.h"
 #include "gwp_asan/optional/backtrace.h"
@@ -32,7 +38,7 @@
 }; // namespace test
 }; // namespace gwp_asan
 
-class DefaultGuardedPoolAllocator : public ::testing::Test {
+class DefaultGuardedPoolAllocator : public Test {
 public:
   void SetUp() override {
     gwp_asan::options::Options Opts;
@@ -51,7 +57,7 @@
       MaxSimultaneousAllocations;
 };
 
-class CustomGuardedPoolAllocator : public ::testing::Test {
+class CustomGuardedPoolAllocator : public Test {
 public:
   void
   InitNumSlots(decltype(gwp_asan::options::Options::MaxSimultaneousAllocations)
@@ -74,7 +80,7 @@
       MaxSimultaneousAllocations;
 };
 
-class BacktraceGuardedPoolAllocator : public ::testing::Test {
+class BacktraceGuardedPoolAllocator : public Test {
 public:
   void SetUp() override {
     gwp_asan::options::Options Opts;
diff --git a/tests/iterate.cpp b/tests/iterate.cpp
index c40df15..2b8635d 100644
--- a/tests/iterate.cpp
+++ b/tests/iterate.cpp
@@ -8,6 +8,9 @@
 
 #include "gwp_asan/tests/harness.h"
 
+#include <set>
+#include <vector>
+
 TEST_F(CustomGuardedPoolAllocator, Iterate) {
   InitNumSlots(7);
   std::vector<std::pair<void *, size_t>> Allocated;
diff --git a/tests/late_init.cpp b/tests/late_init.cpp
index c7d62c8..8a94727 100644
--- a/tests/late_init.cpp
+++ b/tests/late_init.cpp
@@ -8,7 +8,7 @@
 
 #include "gwp_asan/guarded_pool_allocator.h"
 #include "gwp_asan/options.h"
-#include "gtest/gtest.h"
+#include "gwp_asan/tests/harness.h"
 
 TEST(LateInit, CheckLateInitIsOK) {
   gwp_asan::GuardedPoolAllocator GPA;
diff --git a/tests/mutex_test.cpp b/tests/mutex_test.cpp
index 5bc53b9..f68619c 100644
--- a/tests/mutex_test.cpp
+++ b/tests/mutex_test.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "gwp_asan/mutex.h"
-#include "gtest/gtest.h"
+#include "gwp_asan/tests/harness.h"
 
 #include <atomic>
 #include <mutex>
diff --git a/tests/slot_reuse.cpp b/tests/slot_reuse.cpp
index ee4b671..f2a77b0 100644
--- a/tests/slot_reuse.cpp
+++ b/tests/slot_reuse.cpp
@@ -8,6 +8,8 @@
 
 #include "gwp_asan/tests/harness.h"
 
+#include <set>
+
 void singleByteGoodAllocDealloc(gwp_asan::GuardedPoolAllocator *GPA) {
   void *Ptr = GPA->allocate(1);
   EXPECT_NE(nullptr, Ptr);