#include "perfetto/ext/base/paged_memory.h"
#include <stdint.h>
#include "perfetto/base/build_config.h"
#include "perfetto/ext/base/utils.h"
#include "src/base/test/vm_test_utils.h"
#include "test/gtest_and_gmock.h"
#if !PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) && \
!PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) && \
!PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
#include <sys/resource.h>
#endif
namespace perfetto {
namespace base {
namespace {
TEST(PagedMemoryTest, Basic) { … }
TEST(PagedMemoryTest, SubPageGranularity) { … }
TEST(PagedMemoryTest, Uncommitted) { … }
#if defined(ADDRESS_SANITIZER)
TEST(PagedMemoryTest, AccessUncommittedMemoryTriggersASAN) {
EXPECT_DEATH_IF_SUPPORTED(
{
const size_t kNumPages = 2000;
const size_t kSize = GetSysPageSize() * kNumPages;
PagedMemory mem =
PagedMemory::Allocate(kSize, PagedMemory::kDontCommit);
ASSERT_TRUE(mem.IsValid());
char* ptr_raw = reinterpret_cast<char*>(mem.Get());
const size_t kMappedSize = GetSysPageSize() * 1024;
ptr_raw[kMappedSize] = 'x';
abort();
},
"AddressSanitizer: .*");
}
#endif
TEST(PagedMemoryTest, GuardRegions) { … }
#if !PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) && \
!PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) && \
!PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA) && !defined(ADDRESS_SANITIZER) && \
!defined(LEAK_SANITIZER) && !defined(THREAD_SANITIZER) && \
!defined(MEMORY_SANITIZER)
#pragma GCC diagnostic push
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wdisabled-macro-expansion"
#endif
TEST(PagedMemoryTest, Unchecked) { … }
#pragma GCC diagnostic pop
#endif
}
}
}