diff options
author | Elliott Hughes <enh@google.com> | 2020-10-22 13:22:35 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2020-10-22 13:22:35 -0700 |
commit | 7cda75f1d3e147a300d7ff4d690b13e36bff5c5d (patch) | |
tree | 0d4390746ae35c223432964fce5041d3dc280bed /tests/malloc_test.cpp | |
parent | 9aa6b15d799ac246e842552fca555920a93ce46b (diff) |
Add DoNotOptimize and use it in tests.
Bug: http://b/148307629
Test: treehugger
Change-Id: I3b1726ae55116f6553ea38fe163abdde179c21f0
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r-- | tests/malloc_test.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp index 4ea6d2b37..ddd3416be 100644 --- a/tests/malloc_test.cpp +++ b/tests/malloc_test.cpp @@ -925,12 +925,8 @@ TEST(malloc, DISABLED_alloc_after_fork) { std::thread* t = new std::thread([&stop] { while (!stop) { for (size_t size = kMinAllocationSize; size <= kMaxAllocationSize; size <<= 1) { - void* ptr = malloc(size); - if (ptr == nullptr) { - return; - } - // Make sure this value is not optimized away. - asm volatile("" : : "r,m"(ptr) : "memory"); + void* ptr; + DoNotOptimize(ptr = malloc(size)); free(ptr); } } @@ -943,10 +939,9 @@ TEST(malloc, DISABLED_alloc_after_fork) { pid_t pid; if ((pid = fork()) == 0) { for (size_t size = kMinAllocationSize; size <= kMaxAllocationSize; size <<= 1) { - void* ptr = malloc(size); + void* ptr; + DoNotOptimize(ptr = malloc(size)); ASSERT_TRUE(ptr != nullptr); - // Make sure this value is not optimized away. - asm volatile("" : : "r,m"(ptr) : "memory"); // Make sure we can touch all of the allocation. memset(ptr, 0x1, size); ASSERT_LE(size, malloc_usable_size(ptr)); |