| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/thread_heap_usage_tracker.h" | 5 #include "base/debug/thread_heap_usage_tracker.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_shim.h" | 9 #include "base/allocator/allocator_shim.h" |
| 10 #include "base/allocator/features.h" | 10 #include "base/allocator/features.h" |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 alloc = MockAllocAligned(1, kAllocSize); | 546 alloc = MockAllocAligned(1, kAllocSize); |
| 547 estimate = MockGetSizeEstimate(alloc); | 547 estimate = MockGetSizeEstimate(alloc); |
| 548 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); | 548 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); |
| 549 | 549 |
| 550 alloc = MockRealloc(alloc, kAllocSize); | 550 alloc = MockRealloc(alloc, kAllocSize); |
| 551 estimate = MockGetSizeEstimate(alloc); | 551 estimate = MockGetSizeEstimate(alloc); |
| 552 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); | 552 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); |
| 553 MockFree(alloc); | 553 MockFree(alloc); |
| 554 } | 554 } |
| 555 | 555 |
| 556 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 556 #if BUILDFLAG(USE_ALLOCATOR_SHIM) |
| 557 class ThreadHeapUsageShimTest : public testing::Test { | 557 class ThreadHeapUsageShimTest : public testing::Test { |
| 558 #if defined(OS_MACOSX) | 558 #if defined(OS_MACOSX) |
| 559 void SetUp() override { allocator::InitializeAllocatorShim(); } | 559 void SetUp() override { allocator::InitializeAllocatorShim(); } |
| 560 void TearDown() override { allocator::UninterceptMallocZonesForTesting(); } | 560 void TearDown() override { allocator::UninterceptMallocZonesForTesting(); } |
| 561 #endif | 561 #endif |
| 562 }; | 562 }; |
| 563 | 563 |
| 564 TEST_F(ThreadHeapUsageShimTest, HooksIntoMallocWhenShimAvailable) { | 564 TEST_F(ThreadHeapUsageShimTest, HooksIntoMallocWhenShimAvailable) { |
| 565 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); | 565 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); |
| 566 | 566 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 594 // Verify that at least the bytes above were recorded. | 594 // Verify that at least the bytes above were recorded. |
| 595 EXPECT_LE(u1.alloc_bytes + kAllocSize, u2.alloc_bytes); | 595 EXPECT_LE(u1.alloc_bytes + kAllocSize, u2.alloc_bytes); |
| 596 | 596 |
| 597 // Verify that at least the one free operation above was recorded. | 597 // Verify that at least the one free operation above was recorded. |
| 598 EXPECT_LE(u2.free_ops + 1, u3.free_ops); | 598 EXPECT_LE(u2.free_ops + 1, u3.free_ops); |
| 599 | 599 |
| 600 TestingThreadHeapUsageTracker::DisableHeapTrackingForTesting(); | 600 TestingThreadHeapUsageTracker::DisableHeapTrackingForTesting(); |
| 601 | 601 |
| 602 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); | 602 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); |
| 603 } | 603 } |
| 604 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 604 #endif // BUILDFLAG(USE_ALLOCATOR_SHIM) |
| 605 | 605 |
| 606 } // namespace debug | 606 } // namespace debug |
| 607 } // namespace base | 607 } // namespace base |
| OLD | NEW |