[compiler-rt] r348260 - [SanitizerCommon] Test `CombinedAllocator::ForEachChunk()` in unit tests.

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 4 06:03:55 PST 2018


Author: delcypher
Date: Tue Dec  4 06:03:55 2018
New Revision: 348260

URL: http://llvm.org/viewvc/llvm-project?rev=348260&view=rev
Log:
[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

Modified:
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc?rev=348260&r1=348259&r2=348260&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc Tue Dec  4 06:03:55 2018
@@ -615,6 +615,22 @@ void TestCombinedAllocator() {
 
     std::shuffle(allocated.begin(), allocated.end(), r);
 
+    // Test ForEachChunk(...)
+    {
+      std::set<void *> reported_chunks;
+      auto cb = [](uptr chunk, void *arg) {
+        auto reported_chunks_ptr = reinterpret_cast<std::set<void *> *>(arg);
+        auto pair =
+            reported_chunks_ptr->insert(reinterpret_cast<void *>(chunk));
+        // Check chunk is never reported more than once.
+        ASSERT_TRUE(pair.second);
+      };
+      a->ForEachChunk(cb, reinterpret_cast<void *>(&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<uptr*>(a->GetMetaData(x));




More information about the llvm-commits mailing list