Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ios/chrome/browser/memory/memory_wedge.h" | |
| 6 | |
| 7 #include "ios/chrome/browser/memory/memory_metrics.h" | |
| 8 #include "testing/gtest/include/gtest/gtest-param-test.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 // The number of bytes in a megabyte. | |
| 14 const uint64 kNumBytesInMB = 1024 * 1024; | |
| 15 | |
| 16 // Note: in the following tests, only memory_util::GetInternalVMBytes, | |
| 17 // and memory_util::GetRealMemoryUsedInBytes are used to check the state of the | |
| 18 // memory before and after an action. | |
| 19 // memory_util::GetFreePhysicalBytes and memory_util::GetDirtyVMBytes are not | |
| 20 // used because external events can change these values, making them not | |
| 21 // reliable. | |
| 22 | |
| 23 // Performs a snapshot of the memory when constructed. Deviation from the | |
| 24 // initial values can be verified with VerifyDeviation. The comparison is | |
| 25 // on the integer part of the values in MB. | |
| 26 class MemoryChecker { | |
| 27 public: | |
| 28 MemoryChecker() { | |
| 29 internal_vm_ = memory_util::GetInternalVMBytes() / kNumBytesInMB; | |
| 30 real_memory_used_ = memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB; | |
| 31 } | |
| 32 | |
| 33 // Verifies that the memory metrics deviated only by |deviation| in MB. | |
| 34 void VerifyDeviation(uint64 deviation) const { | |
| 35 EXPECT_NEAR(memory_util::GetInternalVMBytes() / kNumBytesInMB, | |
| 36 deviation + internal_vm_, 1); | |
| 37 EXPECT_NEAR(memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB, | |
| 38 deviation + real_memory_used_, 1); | |
| 39 } | |
| 40 | |
| 41 private: | |
| 42 uint64 internal_vm_; | |
| 43 uint64 real_memory_used_; | |
| 44 }; | |
|
Alexei Svitkine (slow)
2015/04/28 16:52:58
DISALLOW_COPY_AND_ASSIGN()
lpromero
2015/04/28 18:12:46
Done.
| |
| 45 | |
| 46 class MemoryWedgeTest : public testing::TestWithParam<unsigned> {}; | |
| 47 | |
| 48 // Checks that the wedge size passed to AddWedge is indeed added to the global | |
| 49 // footprint of the app. | |
| 50 TEST_P(MemoryWedgeTest, WedgeSize) { | |
| 51 const MemoryChecker memory_checker; | |
| 52 unsigned wedge_size = GetParam(); | |
| 53 | |
| 54 memory_wedge::AddWedge(wedge_size); | |
| 55 | |
| 56 memory_checker.VerifyDeviation(wedge_size); | |
| 57 if (wedge_size > 0) | |
| 58 memory_wedge::RemoveWedge(); | |
| 59 } | |
| 60 | |
| 61 INSTANTIATE_TEST_CASE_P( | |
| 62 /* No InstantiationName */, | |
| 63 MemoryWedgeTest, | |
| 64 testing::Values(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)); | |
| 65 | |
| 66 } // namespace | |
| OLD | NEW |