[compiler-rt] 0d3d4d3 - [scudo][standalone] Make tests work on Fuchsia

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 09:43:04 PST 2019


Author: Kostya Kortchinsky
Date: 2019-11-27T09:17:40-08:00
New Revision: 0d3d4d3b0fc57e577a8f80261bd4390c6cb7c040

URL: https://github.com/llvm/llvm-project/commit/0d3d4d3b0fc57e577a8f80261bd4390c6cb7c040
DIFF: https://github.com/llvm/llvm-project/commit/0d3d4d3b0fc57e577a8f80261bd4390c6cb7c040.diff

LOG: [scudo][standalone] Make tests work on Fuchsia

Summary:
This CL makes unit tests compatible with Fuchsia's zxtest. This
required a few changes here and there, but also unearthed some
incompatibilities that had to be addressed.

A header is introduced to allow to account for the zxtest/gtest
differences, some `#if SCUDO_FUCHSIA` are used to disable incompatible
code (the 32-bit primary, or the exclusive TSD).

It also brought to my attention that I was using
`__scudo_default_options` in different tests, which ended up in a
single binary, and I am not sure how that ever worked. So move
this to the main cpp.

Additionally fully disable the secondary freelist on Fuchsia as we do
not track VMOs for secondary allocations, so no release possible.

With some modifications to Scudo's BUILD.gn in Fuchsia:
```
[==========] 79 tests from 23 test cases ran (10280 ms total).
[  PASSED  ] 79 tests
```

Reviewers: mcgrathr, phosek, hctim, pcc, eugenis, cferris

Subscribers: srhines, jfb, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

Added: 
    compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h

Modified: 
    compiler-rt/lib/scudo/standalone/allocator_config.h
    compiler-rt/lib/scudo/standalone/secondary.h
    compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp
    compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp
    compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp
    compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp
    compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
    compiler-rt/lib/scudo/standalone/tests/flags_test.cpp
    compiler-rt/lib/scudo/standalone/tests/list_test.cpp
    compiler-rt/lib/scudo/standalone/tests/map_test.cpp
    compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp
    compiler-rt/lib/scudo/standalone/tests/primary_test.cpp
    compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
    compiler-rt/lib/scudo/standalone/tests/release_test.cpp
    compiler-rt/lib/scudo/standalone/tests/report_test.cpp
    compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp
    compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
    compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp
    compiler-rt/lib/scudo/standalone/tests/stats_test.cpp
    compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
    compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
    compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
    compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
    compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/allocator_config.h b/compiler-rt/lib/scudo/standalone/allocator_config.h
index 166e19e2b8f2..1d00a5d76d04 100644
--- a/compiler-rt/lib/scudo/standalone/allocator_config.h
+++ b/compiler-rt/lib/scudo/standalone/allocator_config.h
@@ -67,7 +67,7 @@ struct AndroidSvelteConfig {
 struct FuchsiaConfig {
   // 1GB Regions
   typedef SizeClassAllocator64<DefaultSizeClassMap, 30U> Primary;
-  typedef MapAllocator<> Secondary;
+  typedef MapAllocator<0U> Secondary;
   template <class A>
   using TSDRegistryT = TSDRegistrySharedT<A, 8U>; // Shared, max 8 TSDs.
 };

diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index f288fc7d7592..d44d2aeaf686 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -50,6 +50,10 @@ static Header *getHeader(const void *Ptr) {
 
 template <uptr MaxFreeListSize = 32U> class MapAllocator {
 public:
+  // Ensure the freelist is disabled on Fuchsia, since it doesn't support
+  // releasing Secondary blocks yet.
+  COMPILER_CHECK(!SCUDO_FUCHSIA || MaxFreeListSize == 0U);
+
   void initLinkerInitialized(GlobalStats *S) {
     Stats.initLinkerInitialized();
     if (LIKELY(S))
@@ -205,10 +209,11 @@ void *MapAllocator<MaxFreeListSize>::allocate(uptr Size, uptr AlignmentHint,
 template <uptr MaxFreeListSize>
 void MapAllocator<MaxFreeListSize>::deallocate(void *Ptr) {
   LargeBlock::Header *H = LargeBlock::getHeader(Ptr);
+  const uptr Block = reinterpret_cast<uptr>(H);
   {
     ScopedLock L(Mutex);
     InUseBlocks.remove(H);
-    const uptr CommitSize = H->BlockEnd - reinterpret_cast<uptr>(H);
+    const uptr CommitSize = H->BlockEnd - Block;
     FreedBytes += CommitSize;
     NumberOfFrees++;
     Stats.sub(StatAllocated, CommitSize);
@@ -225,11 +230,10 @@ void MapAllocator<MaxFreeListSize>::deallocate(void *Ptr) {
       if (!Inserted)
         FreeBlocks.push_back(H);
       const uptr RoundedAllocationStart =
-          roundUpTo(reinterpret_cast<uptr>(H) + LargeBlock::getHeaderSize(),
-                    getPageSizeCached());
+          roundUpTo(Block + LargeBlock::getHeaderSize(), getPageSizeCached());
       MapPlatformData Data = H->Data;
       // TODO(kostyak): use release_to_os_interval_ms
-      releasePagesToOS(H->MapBase, RoundedAllocationStart - H->MapBase,
+      releasePagesToOS(Block, RoundedAllocationStart - Block,
                        H->BlockEnd - RoundedAllocationStart, &Data);
       return;
     }

diff  --git a/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp b/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp
index 7e6f1d21f6e9..103cd24624ba 100644
--- a/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp
@@ -6,8 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "scudo/standalone/atomic_helpers.h"
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
+
+#include "atomic_helpers.h"
 
 namespace scudo {
 

diff  --git a/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp b/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp
index df0646bcd99d..7db7feb6accd 100644
--- a/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp
@@ -6,10 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "bytemap.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "bytemap.h"
 
+#include <pthread.h>
 #include <string.h>
 
 template <typename T> void testMap(T &Map, scudo::uptr Size) {

diff  --git a/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp b/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp
index 43bbd47a3c35..361d33c7e464 100644
--- a/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "checksum.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "checksum.h"
 
 #include <string.h>
 

diff  --git a/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp b/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp
index 57e128ec8266..13da70eff85b 100644
--- a/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "chunk.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "chunk.h"
 
 #include <stdlib.h>
 

diff  --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index 9205467998ed..849fa713ad1d 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -6,14 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "tests/scudo_unit_test.h"
+
 #include "allocator_config.h"
 #include "combined.h"
 
-#include "gtest/gtest.h"
-
 #include <condition_variable>
 #include <mutex>
 #include <thread>
+#include <vector>
 
 static std::mutex Mutex;
 static std::condition_variable Cv;
@@ -21,17 +22,6 @@ static bool Ready = false;
 
 static constexpr scudo::Chunk::Origin Origin = scudo::Chunk::Origin::Malloc;
 
-// This allows us to turn on the Quarantine for specific tests. The Quarantine
-// parameters are on the low end, to avoid having to loop excessively in some
-// tests.
-static bool UseQuarantine = false;
-extern "C" const char *__scudo_default_options() {
-  if (!UseQuarantine)
-    return "";
-  return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
-         "quarantine_max_chunk_size=1024";
-}
-
 template <class Config> static void testAllocator() {
   using AllocatorT = scudo::Allocator<Config>;
   auto Deleter = [](AllocatorT *A) {
@@ -168,15 +158,15 @@ template <class Config> static void testAllocator() {
 }
 
 TEST(ScudoCombinedTest, BasicCombined) {
-  testAllocator<scudo::DefaultConfig>();
-#if SCUDO_WORDSIZE == 64U
+  UseQuarantine = false;
+  testAllocator<scudo::AndroidSvelteConfig>();
+#if SCUDO_FUCHSIA
   testAllocator<scudo::FuchsiaConfig>();
-#endif
-  // The following configs should work on all platforms.
+#else
+  testAllocator<scudo::DefaultConfig>();
   UseQuarantine = true;
   testAllocator<scudo::AndroidConfig>();
-  UseQuarantine = false;
-  testAllocator<scudo::AndroidSvelteConfig>();
+#endif
 }
 
 template <typename AllocatorT> static void stressAllocator(AllocatorT *A) {
@@ -223,20 +213,21 @@ template <class Config> static void testAllocatorThreaded() {
 }
 
 TEST(ScudoCombinedTest, ThreadedCombined) {
-  testAllocatorThreaded<scudo::DefaultConfig>();
-#if SCUDO_WORDSIZE == 64U
+  UseQuarantine = false;
+  testAllocatorThreaded<scudo::AndroidSvelteConfig>();
+#if SCUDO_FUCHSIA
   testAllocatorThreaded<scudo::FuchsiaConfig>();
-#endif
+#else
+  testAllocatorThreaded<scudo::DefaultConfig>();
   UseQuarantine = true;
   testAllocatorThreaded<scudo::AndroidConfig>();
-  UseQuarantine = false;
-  testAllocatorThreaded<scudo::AndroidSvelteConfig>();
+#endif
 }
 
 struct DeathConfig {
   // Tiny allocator, its Primary only serves chunks of 1024 bytes.
   using DeathSizeClassMap = scudo::SizeClassMap<1U, 10U, 10U, 10U, 1U, 10U>;
-  typedef scudo::SizeClassAllocator32<DeathSizeClassMap, 18U> Primary;
+  typedef scudo::SizeClassAllocator64<DeathSizeClassMap, 20U> Primary;
   typedef scudo::MapAllocator<0U> Secondary;
   template <class A> using TSDRegistryT = scudo::TSDRegistrySharedT<A, 1U>;
 };
@@ -258,8 +249,8 @@ TEST(ScudoCombinedTest, DeathCombined) {
   // Invalid sized deallocation.
   EXPECT_DEATH(Allocator->deallocate(P, Origin, Size + 8U), "");
 
-  // Misaligned pointer.
-  void *MisalignedP =
+  // Misaligned pointer. Potentially unused if EXPECT_DEATH isn't available.
+  UNUSED void *MisalignedP =
       reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(P) | 1U);
   EXPECT_DEATH(Allocator->deallocate(MisalignedP, Origin, Size), "");
   EXPECT_DEATH(Allocator->reallocate(MisalignedP, Size * 2U), "");

diff  --git a/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp b/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp
index 1c07bf13181c..45918ad4d2ca 100644
--- a/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "tests/scudo_unit_test.h"
+
 #include "flags.h"
 #include "flags_parser.h"
 
-#include "gtest/gtest.h"
-
 #include <string.h>
 
 static const char FlagName[] = "flag_name";

diff  --git a/compiler-rt/lib/scudo/standalone/tests/list_test.cpp b/compiler-rt/lib/scudo/standalone/tests/list_test.cpp
index 0a0c050c98cd..8e139916d058 100644
--- a/compiler-rt/lib/scudo/standalone/tests/list_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/list_test.cpp
@@ -6,8 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "scudo/standalone/list.h"
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
+
+#include "list.h"
 
 struct ListItem {
   ListItem *Next;

diff  --git a/compiler-rt/lib/scudo/standalone/tests/map_test.cpp b/compiler-rt/lib/scudo/standalone/tests/map_test.cpp
index ab5dd8ca5fd6..7c40b73ff254 100644
--- a/compiler-rt/lib/scudo/standalone/tests/map_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/map_test.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "common.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "common.h"
 
 #include <string.h>
 #include <unistd.h>
@@ -31,11 +31,10 @@ TEST(ScudoMapTest, MapNoAccessUnmap) {
 
 TEST(ScudoMapTest, MapUnmap) {
   const scudo::uptr Size = 4 * scudo::getPageSizeCached();
-  scudo::MapPlatformData Data = {};
-  void *P = scudo::map(nullptr, Size, MappingName, 0, &Data);
+  void *P = scudo::map(nullptr, Size, MappingName, 0, nullptr);
   EXPECT_NE(P, nullptr);
   memset(P, 0xaa, Size);
-  scudo::unmap(P, Size, 0, &Data);
+  scudo::unmap(P, Size, 0, nullptr);
   EXPECT_DEATH(memset(P, 0xbb, Size), "");
 }
 

diff  --git a/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp b/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp
index c75ef8edb366..ce715a19332f 100644
--- a/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp
@@ -6,10 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "mutex.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "mutex.h"
 
+#include <pthread.h>
 #include <string.h>
 
 class TestData {

diff  --git a/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp
index 7da7b25ca67e..64b625e79bf2 100644
--- a/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp
@@ -6,15 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "tests/scudo_unit_test.h"
+
 #include "primary32.h"
 #include "primary64.h"
 #include "size_class_map.h"
 
-#include "gtest/gtest.h"
-
 #include <condition_variable>
 #include <mutex>
 #include <thread>
+#include <vector>
 
 // Note that with small enough regions, the SizeClassAllocator64 also works on
 // 32-bit architectures. It's not something we want to encourage, but we still
@@ -53,7 +54,9 @@ template <typename Primary> static void testPrimary() {
 
 TEST(ScudoPrimaryTest, BasicPrimary) {
   using SizeClassMap = scudo::DefaultSizeClassMap;
+#if !SCUDO_FUCHSIA
   testPrimary<scudo::SizeClassAllocator32<SizeClassMap, 18U>>();
+#endif
   testPrimary<scudo::SizeClassAllocator64<SizeClassMap, 24U>>();
 }
 
@@ -78,7 +81,7 @@ TEST(ScudoPrimaryTest, Primary64OOM) {
       AllocationFailed = true;
       break;
     }
-    for (scudo::uptr J = 0; J < B->getCount(); J++)
+    for (scudo::u32 J = 0; J < B->getCount(); J++)
       memset(B->get(J), 'B', Size);
     Batches.push_back(B);
   }
@@ -136,7 +139,9 @@ template <typename Primary> static void testIteratePrimary() {
 
 TEST(ScudoPrimaryTest, PrimaryIterate) {
   using SizeClassMap = scudo::DefaultSizeClassMap;
+#if !SCUDO_FUCHSIA
   testIteratePrimary<scudo::SizeClassAllocator32<SizeClassMap, 18U>>();
+#endif
   testIteratePrimary<scudo::SizeClassAllocator64<SizeClassMap, 24U>>();
 }
 
@@ -193,7 +198,9 @@ template <typename Primary> static void testPrimaryThreaded() {
 
 TEST(ScudoPrimaryTest, PrimaryThreaded) {
   using SizeClassMap = scudo::SvelteSizeClassMap;
+#if !SCUDO_FUCHSIA
   testPrimaryThreaded<scudo::SizeClassAllocator32<SizeClassMap, 18U>>();
+#endif
   testPrimaryThreaded<scudo::SizeClassAllocator64<SizeClassMap, 24U>>();
 }
 
@@ -221,6 +228,8 @@ template <typename Primary> static void testReleaseToOS() {
 
 TEST(ScudoPrimaryTest, ReleaseToOS) {
   using SizeClassMap = scudo::DefaultSizeClassMap;
+#if !SCUDO_FUCHSIA
   testReleaseToOS<scudo::SizeClassAllocator32<SizeClassMap, 18U>>();
+#endif
   testReleaseToOS<scudo::SizeClassAllocator64<SizeClassMap, 24U>>();
 }

diff  --git a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
index 28baf8feb653..0422c2ff3736 100644
--- a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
@@ -6,10 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "quarantine.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "quarantine.h"
 
+#include <pthread.h>
 #include <stdlib.h>
 
 static void *FakePtr = reinterpret_cast<void *>(0xFA83FA83);

diff  --git a/compiler-rt/lib/scudo/standalone/tests/release_test.cpp b/compiler-rt/lib/scudo/standalone/tests/release_test.cpp
index 3776768e9a84..22d73d09d53d 100644
--- a/compiler-rt/lib/scudo/standalone/tests/release_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/release_test.cpp
@@ -6,16 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "tests/scudo_unit_test.h"
+
 #include "list.h"
 #include "release.h"
 #include "size_class_map.h"
 
-#include "gtest/gtest.h"
-
 #include <string.h>
 
 #include <algorithm>
 #include <random>
+#include <set>
 
 TEST(ScudoReleaseTest, PackedCounterArray) {
   for (scudo::uptr I = 0; I < SCUDO_WORDSIZE; I++) {

diff  --git a/compiler-rt/lib/scudo/standalone/tests/report_test.cpp b/compiler-rt/lib/scudo/standalone/tests/report_test.cpp
index c2f377d96849..09f03f1ac896 100644
--- a/compiler-rt/lib/scudo/standalone/tests/report_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/report_test.cpp
@@ -6,11 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "scudo/standalone/report.h"
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
+
+#include "report.h"
 
 TEST(ScudoReportTest, Generic) {
-  void *P = reinterpret_cast<void *>(0x42424242U);
+  // Potentially unused if EXPECT_DEATH isn't defined.
+  UNUSED void *P = reinterpret_cast<void *>(0x42424242U);
   EXPECT_DEATH(scudo::reportError("TEST123"), "Scudo ERROR.*TEST123");
   EXPECT_DEATH(scudo::reportInvalidFlag("ABC", "DEF"), "Scudo ERROR.*ABC.*DEF");
   EXPECT_DEATH(scudo::reportHeaderCorruption(P), "Scudo ERROR.*42424242");

diff  --git a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h
new file mode 100644
index 000000000000..55d039ef77c3
--- /dev/null
+++ b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h
@@ -0,0 +1,29 @@
+//===-- scudo_unit_test.h ---------------------------------------*- 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 "platform.h"
+
+#if SCUDO_FUCHSIA
+#include <zxtest/zxtest.h>
+#else
+#include "gtest/gtest.h"
+#endif
+
+// If EXPECT_DEATH isn't defined, make it a no-op.
+#ifndef EXPECT_DEATH
+#define EXPECT_DEATH(X, Y)                                                     \
+  do {                                                                         \
+  } while (0)
+#endif
+
+// If EXPECT_STREQ isn't defined, define our own simple one.
+#ifndef EXPECT_STREQ
+#define EXPECT_STREQ(X, Y) EXPECT_EQ(strcmp(X, Y), 0)
+#endif
+
+extern bool UseQuarantine;

diff  --git a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp
index 60bd5648eef7..e771924354ed 100644
--- a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp
@@ -6,9 +6,25 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
+
+// This allows us to turn on/off a Quarantine for specific tests. The Quarantine
+// parameters are on the low end, to avoid having to loop excessively in some
+// tests.
+bool UseQuarantine = true;
+extern "C" __attribute__((visibility("default"))) const char *
+__scudo_default_options() {
+  if (!UseQuarantine)
+    return "dealloc_type_mismatch=true";
+  return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
+         "quarantine_max_chunk_size=512:dealloc_type_mismatch=true";
+}
 
 int main(int argc, char **argv) {
+#if !SCUDO_FUCHSIA
   testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
+#else
+  return RUN_ALL_TESTS(argc, argv);
+#endif
 }

diff  --git a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
index 047a61653cb2..1e7dcec5861f 100644
--- a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "secondary.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "secondary.h"
 
 #include <stdio.h>
 
@@ -16,6 +16,7 @@
 #include <mutex>
 #include <random>
 #include <thread>
+#include <vector>
 
 template <class SecondaryT> static void testSecondaryBasic(void) {
   scudo::GlobalStats S;
@@ -54,12 +55,18 @@ template <class SecondaryT> static void testSecondaryBasic(void) {
 }
 
 TEST(ScudoSecondaryTest, SecondaryBasic) {
-  testSecondaryBasic<scudo::MapAllocator<>>();
   testSecondaryBasic<scudo::MapAllocator<0U>>();
+#if !SCUDO_FUCHSIA
+  testSecondaryBasic<scudo::MapAllocator<>>();
   testSecondaryBasic<scudo::MapAllocator<64U>>();
+#endif
 }
 
+#if SCUDO_FUCHSIA
+using LargeAllocator = scudo::MapAllocator<0U>;
+#else
 using LargeAllocator = scudo::MapAllocator<>;
+#endif
 
 // This exercises a variety of combinations of size and alignment for the
 // MapAllocator. The size computation done here mimic the ones done by the

diff  --git a/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp b/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp
index 39babc14902e..55850400a765 100644
--- a/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp
@@ -6,8 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "scudo/standalone/size_class_map.h"
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
+
+#include "size_class_map.h"
 
 template <class SizeClassMap> void testSizeClassMap() {
   typedef SizeClassMap SCMap;

diff  --git a/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp b/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp
index 449c1491d555..cdadfbad3cbc 100644
--- a/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp
@@ -6,8 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "scudo/standalone/stats.h"
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
+
+#include "stats.h"
 
 TEST(ScudoStatsTest, LocalStats) {
   scudo::LocalStats LStats;

diff  --git a/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp b/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
index 3b1a5e8743e6..eed174dc586a 100644
--- a/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
@@ -6,8 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "scudo/standalone/string_utils.h"
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
+
+#include "string_utils.h"
 
 #include <limits.h>
 

diff  --git a/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp b/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
index 1941723d5d04..b32c62fe6ca1 100644
--- a/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "tests/scudo_unit_test.h"
+
 #include "tsd_exclusive.h"
 #include "tsd_shared.h"
 
-#include "gtest/gtest.h"
-
 #include <condition_variable>
 #include <mutex>
 #include <thread>
@@ -108,7 +108,9 @@ template <class AllocatorT> static void testRegistry() {
 TEST(ScudoTSDTest, TSDRegistryBasic) {
   testRegistry<MockAllocator<OneCache>>();
   testRegistry<MockAllocator<SharedCaches>>();
+#if !SCUDO_FUCHSIA
   testRegistry<MockAllocator<ExclusiveCaches>>();
+#endif
 }
 
 static std::mutex Mutex;
@@ -164,5 +166,7 @@ template <class AllocatorT> static void testRegistryThreaded() {
 TEST(ScudoTSDTest, TSDRegistryThreaded) {
   testRegistryThreaded<MockAllocator<OneCache>>();
   testRegistryThreaded<MockAllocator<SharedCaches>>();
+#if !SCUDO_FUCHSIA
   testRegistryThreaded<MockAllocator<ExclusiveCaches>>();
+#endif
 }

diff  --git a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
index 946a44eee8e5..d2c6a9b6bb3c 100644
--- a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "vector.h"
+#include "tests/scudo_unit_test.h"
 
-#include "gtest/gtest.h"
+#include "vector.h"
 
 TEST(ScudoVectorTest, Basic) {
   scudo::Vector<int> V;

diff  --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
index cb651f265f02..99e7aa2fa21c 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -6,10 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "platform.h"
-
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
 
+#include <errno.h>
 #include <limits.h>
 #include <malloc.h>
 #include <stdlib.h>
@@ -32,11 +31,6 @@ int malloc_iterate(uintptr_t base, size_t size,
 // We have to use a small quarantine to make sure that our double-free tests
 // trigger. Otherwise EXPECT_DEATH ends up reallocating the chunk that was just
 // freed (this depends on the size obviously) and the following free succeeds.
-extern "C" __attribute__((visibility("default"))) const char *
-__scudo_default_options() {
-  return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
-         "quarantine_max_chunk_size=512";
-}
 
 static const size_t Size = 100U;
 
@@ -200,6 +194,7 @@ TEST(ScudoWrappersCTest, Realloc) {
 #define M_PURGE -101
 #endif
 
+#if !SCUDO_FUCHSIA
 TEST(ScudoWrappersCTest, MallOpt) {
   errno = 0;
   EXPECT_EQ(mallopt(-1000, 1), 0);
@@ -213,8 +208,10 @@ TEST(ScudoWrappersCTest, MallOpt) {
   EXPECT_EQ(mallopt(M_DECAY_TIME, 1), 1);
   EXPECT_EQ(mallopt(M_DECAY_TIME, 0), 1);
 }
+#endif
 
 TEST(ScudoWrappersCTest, OtherAlloc) {
+#if !SCUDO_FUCHSIA
   const size_t PageSize = sysconf(_SC_PAGESIZE);
 
   void *P = pvalloc(Size);
@@ -229,10 +226,12 @@ TEST(ScudoWrappersCTest, OtherAlloc) {
   EXPECT_NE(P, nullptr);
   EXPECT_EQ(reinterpret_cast<uintptr_t>(P) & (PageSize - 1), 0U);
   free(P);
+#endif
 
   EXPECT_EQ(valloc(SIZE_MAX), nullptr);
 }
 
+#if !SCUDO_FUCHSIA
 TEST(ScudoWrappersCTest, MallInfo) {
   const size_t BypassQuarantineSize = 1024U;
 
@@ -248,6 +247,7 @@ TEST(ScudoWrappersCTest, MallInfo) {
   MI = mallinfo();
   EXPECT_GE(static_cast<size_t>(MI.fordblks), Free + BypassQuarantineSize);
 }
+#endif
 
 static uintptr_t BoundaryP;
 static size_t Count;
@@ -282,6 +282,7 @@ TEST(ScudoWrappersCTest, MallocIterateBoundary) {
   free(P);
 }
 
+#if !SCUDO_FUCHSIA
 TEST(ScudoWrappersCTest, MallocInfo) {
   char Buffer[64];
   FILE *F = fmemopen(Buffer, sizeof(Buffer), "w+");
@@ -292,3 +293,4 @@ TEST(ScudoWrappersCTest, MallocInfo) {
   fclose(F);
   EXPECT_EQ(strncmp(Buffer, "<malloc version=\"scudo-", 23), 0);
 }
+#endif

diff  --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
index 5eb65bc89372..28ae41c03f42 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
+#include "tests/scudo_unit_test.h"
 
 #include <condition_variable>
 #include <mutex>
 #include <thread>
+#include <vector>
 
 void operator delete(void *, size_t) noexcept;
 void operator delete[](void *, size_t) noexcept;
@@ -18,12 +19,6 @@ void operator delete[](void *, size_t) noexcept;
 // Note that every Cxx allocation function in the test binary will be fulfilled
 // by Scudo. See the comment in the C counterpart of this file.
 
-extern "C" __attribute__((visibility("default"))) const char *
-__scudo_default_options() {
-  return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
-         "quarantine_max_chunk_size=512:dealloc_type_mismatch=true";
-}
-
 template <typename T> static void testCxxNew() {
   T *P = new T;
   EXPECT_NE(P, nullptr);


        


More information about the llvm-commits mailing list