Chromium Code Reviews| Index: ios/chrome/browser/memory/memory_wedge_unittest.cc |
| diff --git a/ios/chrome/browser/memory/memory_wedge_unittest.cc b/ios/chrome/browser/memory/memory_wedge_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a10ba1ea081319daa71fdadae5ee0dd37e3986d3 |
| --- /dev/null |
| +++ b/ios/chrome/browser/memory/memory_wedge_unittest.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ios/chrome/browser/memory/memory_wedge.h" |
| + |
| +#include "base/macros.h" |
| +#include "ios/chrome/browser/memory/memory_metrics.h" |
| +#include "testing/gtest/include/gtest/gtest-param-test.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
|
Alexei Svitkine (slow)
2015/04/28 18:43:40
Use namespace memory_wedge to match the cc file.
lpromero
2015/04/28 22:01:45
Done.
|
| + |
| +// The number of bytes in a megabyte. |
| +const uint64 kNumBytesInMB = 1024 * 1024; |
| + |
| +// Note: in the following tests, only memory_util::GetInternalVMBytes, |
| +// and memory_util::GetRealMemoryUsedInBytes are used to check the state of the |
| +// memory before and after an action. |
| +// memory_util::GetFreePhysicalBytes and memory_util::GetDirtyVMBytes are not |
| +// used because external events can change these values, making them not |
| +// reliable. |
| + |
| +// Performs a snapshot of the memory when constructed. Deviation from the |
| +// initial values can be verified with VerifyDeviation. The comparison is |
| +// on the integer part of the values in MB. |
| +class MemoryChecker { |
| + public: |
| + MemoryChecker() { |
| + internal_vm_ = memory_util::GetInternalVMBytes() / kNumBytesInMB; |
| + real_memory_used_ = memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB; |
| + } |
| + |
| + // Verifies that the memory metrics deviated only by |deviation| in MB. |
| + void VerifyDeviation(uint64 deviation) const { |
| + EXPECT_NEAR(memory_util::GetInternalVMBytes() / kNumBytesInMB, |
| + deviation + internal_vm_, 1); |
| + EXPECT_NEAR(memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB, |
| + deviation + real_memory_used_, 1); |
| + } |
| + |
| + private: |
| + uint64 internal_vm_; |
| + uint64 real_memory_used_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MemoryChecker); |
| +}; |
| + |
| +class MemoryWedgeTest : public testing::TestWithParam<unsigned> {}; |
| + |
| +// Checks that the wedge size passed to AddWedge is indeed added to the global |
| +// footprint of the app. |
| +TEST_P(MemoryWedgeTest, WedgeSize) { |
| + const MemoryChecker memory_checker; |
| + unsigned wedge_size = GetParam(); |
| + |
| + memory_wedge::AddWedge(wedge_size); |
| + |
| + memory_checker.VerifyDeviation(wedge_size); |
| + if (wedge_size > 0) |
| + memory_wedge::RemoveWedgeForTesting(); |
| +} |
| + |
| +INSTANTIATE_TEST_CASE_P( |
| + /* No InstantiationName */, |
| + MemoryWedgeTest, |
| + testing::Values(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)); |
| + |
| +} // namespace |