From: Dan Liew Date: Tue, 4 Dec 2018 14:03:55 +0000 (+0000) Subject: [SanitizerCommon] Test `CombinedAllocator::ForEachChunk()` in unit tests. X-Git-Tag: llvmorg-8.0.0-rc1~2940 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f73b782105ec151c01d03b9f433e4e6c8d3aaf45;p=platform%2Fupstream%2Fllvm.git [SanitizerCommon] Test `CombinedAllocator::ForEachChunk()` in unit tests. Summary: Previously we weren't testing this function in the unit tests. Reviewers: kcc, cryptoad, dvyukov, eugenis, kubamracek Subscribers: #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D54861 llvm-svn: 348260 --- diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc index 05fef25..c13da36 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -615,6 +615,22 @@ void TestCombinedAllocator() { std::shuffle(allocated.begin(), allocated.end(), r); + // Test ForEachChunk(...) + { + std::set reported_chunks; + auto cb = [](uptr chunk, void *arg) { + auto reported_chunks_ptr = reinterpret_cast *>(arg); + auto pair = + reported_chunks_ptr->insert(reinterpret_cast(chunk)); + // Check chunk is never reported more than once. + ASSERT_TRUE(pair.second); + }; + a->ForEachChunk(cb, reinterpret_cast(&reported_chunks)); + for (const auto &allocated_ptr : allocated) { + ASSERT_NE(reported_chunks.find(allocated_ptr), reported_chunks.end()); + } + } + for (uptr i = 0; i < kNumAllocs; i++) { void *x = allocated[i]; uptr *meta = reinterpret_cast(a->GetMetaData(x));