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

Side by Side Diff: ios/chrome/browser/memory/memory_wedge_unittest.cc

Issue 1107963002: Add MemoryWedge to ios/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback. Created 5 years, 7 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 | « ios/chrome/browser/memory/memory_wedge.cc ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "base/macros.h"
8 #include "ios/chrome/browser/memory/memory_metrics.h"
9 #include "testing/gtest/include/gtest/gtest-param-test.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace memory_wedge {
13
14 namespace {
15
16 // The number of bytes in a megabyte.
17 const uint64 kNumBytesInMB = 1024 * 1024;
18
19 // Note: in the following tests, only memory_util::GetInternalVMBytes,
20 // and memory_util::GetRealMemoryUsedInBytes are used to check the state of the
21 // memory before and after an action.
22 // memory_util::GetFreePhysicalBytes and memory_util::GetDirtyVMBytes are not
23 // used because external events can change these values, making them not
24 // reliable.
25
26 // Performs a snapshot of the memory when constructed. Deviation from the
27 // initial values can be verified with VerifyDeviation. The comparison is
28 // on the integer part of the values in MB.
29 class MemoryChecker {
30 public:
31 MemoryChecker() {
32 internal_vm_ = memory_util::GetInternalVMBytes() / kNumBytesInMB;
33 real_memory_used_ = memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB;
34 }
35
36 // Verifies that the memory metrics deviated only by |deviation| in MB.
37 void VerifyDeviation(uint64 deviation) const {
38 EXPECT_NEAR(memory_util::GetInternalVMBytes() / kNumBytesInMB,
39 deviation + internal_vm_, 1);
40 EXPECT_NEAR(memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB,
41 deviation + real_memory_used_, 1);
42 }
43
44 private:
45 uint64 internal_vm_;
46 uint64 real_memory_used_;
47
48 DISALLOW_COPY_AND_ASSIGN(MemoryChecker);
49 };
50
51 class MemoryWedgeTest : public testing::TestWithParam<size_t> {};
52
53 } // namespace
54
55 // Checks that the wedge size passed to AddWedge is indeed added to the global
56 // footprint of the app.
57 TEST_P(MemoryWedgeTest, WedgeSize) {
58 const MemoryChecker memory_checker;
59 size_t wedge_size = GetParam();
60
61 AddWedge(wedge_size);
62
63 memory_checker.VerifyDeviation(wedge_size);
64 if (wedge_size > 0)
65 RemoveWedgeForTesting();
66 }
67
68 INSTANTIATE_TEST_CASE_P(
69 /* No InstantiationName */,
70 MemoryWedgeTest,
71 testing::Values(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100));
72
73 } // namespace memory_wedge
OLDNEW
« no previous file with comments | « ios/chrome/browser/memory/memory_wedge.cc ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698