summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2018-12-04 14:03:55 +0000
committerDan Liew <dan@su-root.co.uk>2018-12-04 14:03:55 +0000
commitf73b782105ec151c01d03b9f433e4e6c8d3aaf45 (patch)
tree07b6b74d0a4b168cfb121c4142a3eb207cd1c885 /compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
parentdd702e217b1990a9c8178091e59c002ff3d49e18 (diff)
downloadbcm5719-llvm-f73b782105ec151c01d03b9f433e4e6c8d3aaf45.tar.gz
bcm5719-llvm-f73b782105ec151c01d03b9f433e4e6c8d3aaf45.zip
[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
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc')
-rw-r--r--compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc16
1 files changed, 16 insertions, 0 deletions
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 05fef252bf8..c13da36ce75 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<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));
OpenPOWER on IntegriCloud