diff options
author | Kostya Serebryany <kcc@google.com> | 2013-05-30 08:43:30 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2013-05-30 08:43:30 +0000 |
commit | f8c3f3db72780cd57ce7959e70167b7553e55fb8 (patch) | |
tree | c55149ccd1a4bc059e31f2c575e034aac92fac8b /lib/sanitizer_common/tests/sanitizer_allocator_test.cc | |
parent | 41dcb1c8848c8677c06216c6fcaa9b001f736778 (diff) |
[sanitizer] introduce LargeMmapAllocator::GetBlockBeginFastSingleThreaded, required for LeakSanitizer to work faster. Also fix lint.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182917 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/tests/sanitizer_allocator_test.cc')
-rw-r--r-- | lib/sanitizer_common/tests/sanitizer_allocator_test.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/lib/sanitizer_common/tests/sanitizer_allocator_test.cc index 5b859bbc9..eefbfb23e 100644 --- a/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -708,9 +708,8 @@ TEST(SanitizerCommon, LargeMmapAllocatorIteration) { char *allocated[kNumAllocs]; static const uptr size = 40; // Allocate some. - for (uptr i = 0; i < kNumAllocs; i++) { + for (uptr i = 0; i < kNumAllocs; i++) allocated[i] = (char *)a.Allocate(&stats, size, 1); - } std::set<void *> reported_chunks; IterationTestCallback callback(&reported_chunks); @@ -722,8 +721,46 @@ TEST(SanitizerCommon, LargeMmapAllocatorIteration) { // Don't use EXPECT_NE. Reporting the first mismatch is enough. ASSERT_NE(reported_chunks.find(allocated[i]), reported_chunks.end()); } + for (uptr i = 0; i < kNumAllocs; i++) + a.Deallocate(&stats, allocated[i]); +} + +TEST(SanitizerCommon, LargeMmapAllocatorBlockBegin) { + LargeMmapAllocator<> a; + a.Init(); + AllocatorStats stats; + stats.Init(); + + static const uptr kNumAllocs = 1024; + static const uptr kNumExpectedFalseLookups = 10000000; + char *allocated[kNumAllocs]; + static const uptr size = 4096; + // Allocate some. + for (uptr i = 0; i < kNumAllocs; i++) { + allocated[i] = (char *)a.Allocate(&stats, size, 1); + } + + for (uptr i = 0; i < kNumAllocs * kNumAllocs; i++) { + // if ((i & (i - 1)) == 0) fprintf(stderr, "[%zd]\n", i); + char *p1 = allocated[i % kNumAllocs]; + EXPECT_EQ(p1, a.GetBlockBeginFastSingleThreaded(p1)); + EXPECT_EQ(p1, a.GetBlockBeginFastSingleThreaded(p1 + size / 2)); + EXPECT_EQ(p1, a.GetBlockBeginFastSingleThreaded(p1 + size - 1)); + EXPECT_EQ(p1, a.GetBlockBeginFastSingleThreaded(p1 - 100)); + } + + for (uptr i = 0; i < kNumExpectedFalseLookups; i++) { + void *p = reinterpret_cast<void *>(i % 1024); + EXPECT_EQ((void *)0, a.GetBlockBeginFastSingleThreaded(p)); + p = reinterpret_cast<void *>(~0L - (i % 1024)); + EXPECT_EQ((void *)0, a.GetBlockBeginFastSingleThreaded(p)); + } + + for (uptr i = 0; i < kNumAllocs; i++) + a.Deallocate(&stats, allocated[i]); } + #if SANITIZER_WORDSIZE == 64 // Regression test for out-of-memory condition in PopulateFreeList(). TEST(SanitizerCommon, SizeClassAllocator64PopulateFreeListOOM) { |