summaryrefslogtreecommitdiff
path: root/tests/malloc_test.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2019-02-07 14:20:03 -0800
committerChristopher Ferris <cferris@google.com>2019-02-07 14:20:03 -0800
commit4e56228637b5e82fad30ce11b231a5bfe1cf46ea (patch)
tree5711a3b2a2c73f7f0f3be630be0e604f6e74dd27 /tests/malloc_test.cpp
parent1d3c56bc308c34217e36def4b408d8bae390924e (diff)
Fix flakiness of mallinfo test.
The test was really only supposed to verify that mallinfo eventually increase after allocations of certain sizes. Sometimes the mallinfo returned decreases due to some compaction event, so don't fail in that case. Bug: 124060188 Test: Ran the test 2000 times (32 bit and 64 bit). It would fail within about Test: 200 test iterations before. Change-Id: Ie019107be163dcf275cedf4d1bc5759278def483
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r--tests/malloc_test.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index a3fe5af33..1431cc134 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -588,10 +588,13 @@ TEST(malloc, mallinfo) {
size_t new_allocated = mallinfo().uordblks;
if (allocated != new_allocated) {
size_t usable_size = malloc_usable_size(ptrs[i]);
- ASSERT_GE(new_allocated, allocated + usable_size)
- << "Failed at size " << size << " usable size " << usable_size;
- pass = true;
- break;
+ // Only check if the total got bigger by at least allocation size.
+ // Sometimes the mallinfo numbers can go backwards due to compaction
+ // and/or freeing of cached data.
+ if (new_allocated >= allocated + usable_size) {
+ pass = true;
+ break;
+ }
}
}
for (void* ptr : ptrs) {