#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/gwp_asan/client/guarded_page_allocator.h"
#include <algorithm>
#include <array>
#include <set>
#include <utility>
#include <vector>
#include "base/allocator/buildflags.h"
#include "base/bits.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/page_size.h"
#include "base/memory/raw_ptr.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/threading/simple_thread.h"
#include "build/build_config.h"
#include "components/gwp_asan/client/gwp_asan.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gwp_asan {
namespace internal {
static constexpr size_t kMaxMetadata = …;
static constexpr size_t kMaxSlots = …;
class BaseGpaTest : public testing::Test { … };
class GuardedPageAllocatorTest : public BaseGpaTest,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(GuardedPageAllocatorTest, SingleAllocDealloc) { … }
TEST_P(GuardedPageAllocatorTest, CrashOnBadDeallocPointer) { … }
TEST_P(GuardedPageAllocatorTest, PointerIsMine) { … }
TEST_P(GuardedPageAllocatorTest, GetRequestedSize) { … }
TEST_P(GuardedPageAllocatorTest, LeftAlignedAllocation) { … }
TEST_P(GuardedPageAllocatorTest, RightAlignedAllocation) { … }
TEST_P(GuardedPageAllocatorTest, AllocationAlignment) { … }
TEST_P(GuardedPageAllocatorTest, OutOfMemoryCallback) { … }
class GuardedPageAllocatorParamTest
: public BaseGpaTest,
public testing::WithParamInterface<size_t> { … };
TEST_P(GuardedPageAllocatorParamTest, AllocDeallocAllPages) { … }
INSTANTIATE_TEST_SUITE_P(…);
class ThreadedAllocCountDelegate : public base::DelegateSimpleThread::Delegate { … };
TEST_P(GuardedPageAllocatorTest, ThreadedAllocCount) { … }
class ThreadedHighContentionDelegate
: public base::DelegateSimpleThread::Delegate { … };
TEST_P(GuardedPageAllocatorTest, ThreadedHighContention) { … }
class GuardedPageAllocatorPartitionAllocTest : public BaseGpaTest { … };
TEST_F(GuardedPageAllocatorPartitionAllocTest,
DifferentPartitionsNeverOverlap) { … }
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_GWP_ASAN_STORE)
constexpr size_t kSmallMaxSlots = …;
class GuardedPageAllocatorRawPtrTest : public BaseGpaTest { … };
TEST_F(GuardedPageAllocatorRawPtrTest, DeferDeallocation) { … }
#endif
}
}