Commit 09bb5f10 authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich Committed by Commit Bot

GWP-ASan: Add GetSizeEstimate test

Bug: 909720
Change-Id: Ie88f31f58de2094583722884bb25fbbbee8a85ee
Reviewed-on: https://chromium-review.googlesource.com/c/1357575
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: default avatarVitaly Buka <vitalybuka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612881}
parent 8a9326ce
...@@ -26,6 +26,15 @@ ...@@ -26,6 +26,15 @@
#if BUILDFLAG(USE_ALLOCATOR_SHIM) #if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if defined(OS_WIN)
#include <malloc.h>
static size_t GetAllocatedSize(void *mem) {
return _msize(mem);
}
#else // defined(OS_WIN)
#error "Needs to be implemented for platform."
#endif // defined(OS_WIN)
namespace gwp_asan { namespace gwp_asan {
namespace internal { namespace internal {
...@@ -202,6 +211,28 @@ TEST_F(SamplingAllocatorShimsTest, CrashKey) { ...@@ -202,6 +211,28 @@ TEST_F(SamplingAllocatorShimsTest, CrashKey) {
runTest("CrashKey"); runTest("CrashKey");
} }
MULTIPROCESS_TEST_MAIN(GetSizeEstimate) {
InstallAllocatorHooks(AllocatorState::kGpaMaxPages, kSamplingFrequency);
constexpr size_t kAllocationSize = 123;
for (size_t i = 0; i < kLoopIterations; i++) {
std::unique_ptr<void, decltype(&free)> alloc(malloc(kAllocationSize), free);
CHECK_NE(alloc.get(), nullptr);
size_t alloc_sz = GetAllocatedSize(alloc.get());
if (GetGpaForTesting().PointerIsMine(alloc.get()))
CHECK_EQ(alloc_sz, kAllocationSize);
else
CHECK_GE(alloc_sz, kAllocationSize);
}
return kSuccess;
}
TEST_F(SamplingAllocatorShimsTest, GetSizeEstimate) {
runTest("GetSizeEstimate");
}
} // namespace } // namespace
} // namespace internal } // namespace internal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment