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

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
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 {
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.
13
14 // The number of bytes in a megabyte.
15 const uint64 kNumBytesInMB = 1024 * 1024;
16
17 // Note: in the following tests, only memory_util::GetInternalVMBytes,
18 // and memory_util::GetRealMemoryUsedInBytes are used to check the state of the
19 // memory before and after an action.
20 // memory_util::GetFreePhysicalBytes and memory_util::GetDirtyVMBytes are not
21 // used because external events can change these values, making them not
22 // reliable.
23
24 // Performs a snapshot of the memory when constructed. Deviation from the
25 // initial values can be verified with VerifyDeviation. The comparison is
26 // on the integer part of the values in MB.
27 class MemoryChecker {
28 public:
29 MemoryChecker() {
30 internal_vm_ = memory_util::GetInternalVMBytes() / kNumBytesInMB;
31 real_memory_used_ = memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB;
32 }
33
34 // Verifies that the memory metrics deviated only by |deviation| in MB.
35 void VerifyDeviation(uint64 deviation) const {
36 EXPECT_NEAR(memory_util::GetInternalVMBytes() / kNumBytesInMB,
37 deviation + internal_vm_, 1);
38 EXPECT_NEAR(memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB,
39 deviation + real_memory_used_, 1);
40 }
41
42 private:
43 uint64 internal_vm_;
44 uint64 real_memory_used_;
45
46 DISALLOW_COPY_AND_ASSIGN(MemoryChecker);
47 };
48
49 class MemoryWedgeTest : public testing::TestWithParam<unsigned> {};
50
51 // Checks that the wedge size passed to AddWedge is indeed added to the global
52 // footprint of the app.
53 TEST_P(MemoryWedgeTest, WedgeSize) {
54 const MemoryChecker memory_checker;
55 unsigned wedge_size = GetParam();
56
57 memory_wedge::AddWedge(wedge_size);
58
59 memory_checker.VerifyDeviation(wedge_size);
60 if (wedge_size > 0)
61 memory_wedge::RemoveWedgeForTesting();
62 }
63
64 INSTANTIATE_TEST_CASE_P(
65 /* No InstantiationName */,
66 MemoryWedgeTest,
67 testing::Values(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100));
68
69 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698