[compiler-rt] 5556616 - [GWP-ASan] Port tests to Fuchsia

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 13:36:31 PST 2020


Author: Kostya Kortchinsky
Date: 2020-11-18T13:36:12-08:00
New Revision: 5556616b5b5223f95607ad94053a55f0deaf2762

URL: https://github.com/llvm/llvm-project/commit/5556616b5b5223f95607ad94053a55f0deaf2762
DIFF: https://github.com/llvm/llvm-project/commit/5556616b5b5223f95607ad94053a55f0deaf2762.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/gwp_asan/tests/alignment.cpp
    compiler-rt/lib/gwp_asan/tests/compression.cpp
    compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp
    compiler-rt/lib/gwp_asan/tests/driver.cpp
    compiler-rt/lib/gwp_asan/tests/harness.cpp
    compiler-rt/lib/gwp_asan/tests/harness.h
    compiler-rt/lib/gwp_asan/tests/iterate.cpp
    compiler-rt/lib/gwp_asan/tests/late_init.cpp
    compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
    compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/gwp_asan/tests/alignment.cpp b/compiler-rt/lib/gwp_asan/tests/alignment.cpp
index bf98f1f58338..2489ff888d16 100644
--- a/compiler-rt/lib/gwp_asan/tests/alignment.cpp
+++ b/compiler-rt/lib/gwp_asan/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/compiler-rt/lib/gwp_asan/tests/compression.cpp b/compiler-rt/lib/gwp_asan/tests/compression.cpp
index 7a5894de1251..2423c866a531 100644
--- a/compiler-rt/lib/gwp_asan/tests/compression.cpp
+++ b/compiler-rt/lib/gwp_asan/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/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp b/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp
index 10a014ecd4e3..cb3063631b11 100644
--- a/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp
+++ b/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp
@@ -16,7 +16,7 @@ using GuardedPoolAllocator = gwp_asan::GuardedPoolAllocator;
 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/compiler-rt/lib/gwp_asan/tests/driver.cpp b/compiler-rt/lib/gwp_asan/tests/driver.cpp
index b402cec1126b..02ab36001c70 100644
--- a/compiler-rt/lib/gwp_asan/tests/driver.cpp
+++ b/compiler-rt/lib/gwp_asan/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/compiler-rt/lib/gwp_asan/tests/harness.cpp b/compiler-rt/lib/gwp_asan/tests/harness.cpp
index 77c25ee5a6ea..e668c73057fe 100644
--- a/compiler-rt/lib/gwp_asan/tests/harness.cpp
+++ b/compiler-rt/lib/gwp_asan/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/compiler-rt/lib/gwp_asan/tests/harness.h b/compiler-rt/lib/gwp_asan/tests/harness.h
index d303b2cfa647..26be4a40faf3 100644
--- a/compiler-rt/lib/gwp_asan/tests/harness.h
+++ b/compiler-rt/lib/gwp_asan/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 @@ bool OnlyOnce();
 }; // 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 @@ class DefaultGuardedPoolAllocator : public ::testing::Test {
       MaxSimultaneousAllocations;
 };
 
-class CustomGuardedPoolAllocator : public ::testing::Test {
+class CustomGuardedPoolAllocator : public Test {
 public:
   void
   InitNumSlots(decltype(gwp_asan::options::Options::MaxSimultaneousAllocations)
@@ -74,7 +80,7 @@ class CustomGuardedPoolAllocator : public ::testing::Test {
       MaxSimultaneousAllocations;
 };
 
-class BacktraceGuardedPoolAllocator : public ::testing::Test {
+class BacktraceGuardedPoolAllocator : public Test {
 public:
   void SetUp() override {
     gwp_asan::options::Options Opts;

diff  --git a/compiler-rt/lib/gwp_asan/tests/iterate.cpp b/compiler-rt/lib/gwp_asan/tests/iterate.cpp
index c40df15e09c2..2b8635d5b36d 100644
--- a/compiler-rt/lib/gwp_asan/tests/iterate.cpp
+++ b/compiler-rt/lib/gwp_asan/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/compiler-rt/lib/gwp_asan/tests/late_init.cpp b/compiler-rt/lib/gwp_asan/tests/late_init.cpp
index c7d62c8f3c89..8a947270c2d6 100644
--- a/compiler-rt/lib/gwp_asan/tests/late_init.cpp
+++ b/compiler-rt/lib/gwp_asan/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/compiler-rt/lib/gwp_asan/tests/mutex_test.cpp b/compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
index 5bc53b902185..f68619cb01c9 100644
--- a/compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
+++ b/compiler-rt/lib/gwp_asan/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/compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp b/compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp
index ee4b6713696b..f2a77b094a89 100644
--- a/compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp
+++ b/compiler-rt/lib/gwp_asan/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);


        


More information about the llvm-commits mailing list