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

Unified 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: Synced Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
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..4f5999fd16661b18fdd969b3b5909d50a4db5869
--- /dev/null
+++ b/ios/chrome/browser/memory/memory_wedge_unittest.cc
@@ -0,0 +1,66 @@
+// 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 "ios/chrome/browser/memory/memory_metrics.h"
+#include "testing/gtest/include/gtest/gtest-param-test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// 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_;
+};
Alexei Svitkine (slow) 2015/04/28 16:52:58 DISALLOW_COPY_AND_ASSIGN()
lpromero 2015/04/28 18:12:46 Done.
+
+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::RemoveWedge();
+}
+
+INSTANTIATE_TEST_CASE_P(
+ /* No InstantiationName */,
+ MemoryWedgeTest,
+ testing::Values(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100));
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698