forked from OSchip/llvm-project
[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
This commit is contained in:
parent
f0785c1f7a
commit
5556616b5b
|
@ -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},
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gwp_asan/tests/harness.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 @@ protected:
|
|||
MaxSimultaneousAllocations;
|
||||
};
|
||||
|
||||
class CustomGuardedPoolAllocator : public ::testing::Test {
|
||||
class CustomGuardedPoolAllocator : public Test {
|
||||
public:
|
||||
void
|
||||
InitNumSlots(decltype(gwp_asan::options::Options::MaxSimultaneousAllocations)
|
||||
|
@ -74,7 +80,7 @@ protected:
|
|||
MaxSimultaneousAllocations;
|
||||
};
|
||||
|
||||
class BacktraceGuardedPoolAllocator : public ::testing::Test {
|
||||
class BacktraceGuardedPoolAllocator : public Test {
|
||||
public:
|
||||
void SetUp() override {
|
||||
gwp_asan::options::Options Opts;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "gwp_asan/mutex.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gwp_asan/tests/harness.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue