Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: base/debug/thread_heap_usage_tracker_unittest.cc

Issue 2727463002: mac: Several minor fixes to allocator shim. (Closed)
Patch Set: more compile error. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/allocator/malloc_zone_functions_mac_unittest.cc ('k') | base/process/memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #if defined(OS_MACOSX)
14 #include "base/allocator/allocator_interception_mac.h"
15 #endif
16
13 namespace base { 17 namespace base {
14 namespace debug { 18 namespace debug {
15 19
16 namespace { 20 namespace {
17 21
18 class TestingThreadHeapUsageTracker : public ThreadHeapUsageTracker { 22 class TestingThreadHeapUsageTracker : public ThreadHeapUsageTracker {
19 public: 23 public:
20 using ThreadHeapUsageTracker::DisableHeapTrackingForTesting; 24 using ThreadHeapUsageTracker::DisableHeapTrackingForTesting;
21 using ThreadHeapUsageTracker::EnsureTLSInitialized; 25 using ThreadHeapUsageTracker::EnsureTLSInitialized;
22 using ThreadHeapUsageTracker::GetDispatchForTesting; 26 using ThreadHeapUsageTracker::GetDispatchForTesting;
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 estimate = MockGetSizeEstimate(alloc); 547 estimate = MockGetSizeEstimate(alloc);
544 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); 548 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize);
545 549
546 alloc = MockRealloc(alloc, kAllocSize); 550 alloc = MockRealloc(alloc, kAllocSize);
547 estimate = MockGetSizeEstimate(alloc); 551 estimate = MockGetSizeEstimate(alloc);
548 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); 552 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize);
549 MockFree(alloc); 553 MockFree(alloc);
550 } 554 }
551 555
552 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 556 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
553 TEST(ThreadHeapUsageShimTest, HooksIntoMallocWhenShimAvailable) { 557 class ThreadHeapUsageShimTest : public testing::Test {
554 #if defined(OS_MACOSX) 558 #if defined(OS_MACOSX)
555 allocator::InitializeAllocatorShim(); 559 void SetUp() override { allocator::InitializeAllocatorShim(); }
560 void TearDown() override { allocator::UninterceptMallocZonesForTesting(); }
556 #endif 561 #endif
562 };
557 563
564 TEST_F(ThreadHeapUsageShimTest, HooksIntoMallocWhenShimAvailable) {
558 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); 565 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled());
559 566
560 ThreadHeapUsageTracker::EnableHeapTracking(); 567 ThreadHeapUsageTracker::EnableHeapTracking();
561 568
562 ASSERT_TRUE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); 569 ASSERT_TRUE(ThreadHeapUsageTracker::IsHeapTrackingEnabled());
563 570
564 const size_t kAllocSize = 9993; 571 const size_t kAllocSize = 9993;
565 // This test verifies that the scoped heap data is affected by malloc & 572 // This test verifies that the scoped heap data is affected by malloc &
566 // free only when the shim is available. 573 // free only when the shim is available.
567 ThreadHeapUsageTracker usage_tracker; 574 ThreadHeapUsageTracker usage_tracker;
(...skipping 23 matching lines...) Expand all
591 EXPECT_LE(u2.free_ops + 1, u3.free_ops); 598 EXPECT_LE(u2.free_ops + 1, u3.free_ops);
592 599
593 TestingThreadHeapUsageTracker::DisableHeapTrackingForTesting(); 600 TestingThreadHeapUsageTracker::DisableHeapTrackingForTesting();
594 601
595 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); 602 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled());
596 } 603 }
597 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 604 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
598 605
599 } // namespace debug 606 } // namespace debug
600 } // namespace base 607 } // namespace base
OLDNEW
« no previous file with comments | « base/allocator/malloc_zone_functions_mac_unittest.cc ('k') | base/process/memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698