[PATCH] D54861: [SanitizerCommon] Test `CombinedAllocator::ForEachChunk()` in unit tests.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 27 09:13:57 PST 2018


delcypher updated this revision to Diff 175504.
delcypher added a comment.

Make inline lambda into a variable instead for readability.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54861/new/

https://reviews.llvm.org/D54861

Files:
  lib/sanitizer_common/tests/sanitizer_allocator_test.cc


Index: lib/sanitizer_common/tests/sanitizer_allocator_test.cc
===================================================================
--- lib/sanitizer_common/tests/sanitizer_allocator_test.cc
+++ lib/sanitizer_common/tests/sanitizer_allocator_test.cc
@@ -615,6 +615,22 @@
 
     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));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54861.175504.patch
Type: text/x-patch
Size: 1096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181127/7fc5ad58/attachment-0001.bin>


More information about the llvm-commits mailing list