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

Unified Diff: components/memory_pressure/direct_memory_pressure_calculator_linux_unittest.cc

Issue 1603413003: Add memory pressure monitor for Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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: components/memory_pressure/direct_memory_pressure_calculator_linux_unittest.cc
diff --git a/components/memory_pressure/direct_memory_pressure_calculator_win_unittest.cc b/components/memory_pressure/direct_memory_pressure_calculator_linux_unittest.cc
similarity index 76%
copy from components/memory_pressure/direct_memory_pressure_calculator_win_unittest.cc
copy to components/memory_pressure/direct_memory_pressure_calculator_linux_unittest.cc
index cce65a405e5493ff82a6a7a743979a6c35d36c32..52c922c72b56bf95df396a01f5b7bfb5468ebd8c 100644
--- a/components/memory_pressure/direct_memory_pressure_calculator_win_unittest.cc
+++ b/components/memory_pressure/direct_memory_pressure_calculator_linux_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/memory_pressure/direct_memory_pressure_calculator_win.h"
+#include "components/memory_pressure/direct_memory_pressure_calculator_linux.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -11,6 +11,7 @@ namespace memory_pressure {
namespace {
static const int kKBperMB = 1024;
+static const int kTotalMemoryInMB = 4096;
} // namespace
@@ -19,13 +20,13 @@ static const int kKBperMB = 1024;
class TestDirectMemoryPressureCalculator
: public DirectMemoryPressureCalculator {
public:
- explicit TestDirectMemoryPressureCalculator(bool large_memory)
+ explicit TestDirectMemoryPressureCalculator()
: DirectMemoryPressureCalculator(20, 10) {
// The values passed to the MemoryPressureCalculator constructor are dummy
// values that are immediately overwritten by InferTresholds.
- // Generate a plausible amount of memory.
- mem_info_.total = GenerateTotalMemoryMb(large_memory) * kKBperMB;
+ // Simulate 4GB of RAM.
+ mem_info_.total = kTotalMemoryInMB * kKBperMB;
// Run InferThresholds using the test fixture's GetSystemMemoryStatus.
InferThresholds();
@@ -39,17 +40,6 @@ class TestDirectMemoryPressureCalculator
mem_info_.total = total_memory_mb * kKBperMB;
}
- // Generates an amount of total memory that is consistent with the requested
- // memory model.
- static int GenerateTotalMemoryMb(bool large_memory) {
- int total_mb = 64;
- while (total_mb < kLargeMemoryThresholdMb)
- total_mb *= 2;
- if (large_memory)
- return total_mb * 2;
- return total_mb / 2;
- }
-
// Sets up the memory status to reflect the provided absolute memory left.
void SetMemoryFree(int phys_left_mb) {
// |total| is set in the constructor and not modified.
@@ -125,30 +115,15 @@ class DirectMemoryPressureCalculatorTest : public testing::Test {
// Tests the fundamental direct calculation of memory pressure with automatic
// small-memory thresholds.
TEST_F(DirectMemoryPressureCalculatorTest,
- CalculateCurrentMemoryPressureLevelSmall) {
- static const int kModerateMb =
- DirectMemoryPressureCalculator::kSmallMemoryDefaultModerateThresholdMb;
- static const int kCriticalMb =
- DirectMemoryPressureCalculator::kSmallMemoryDefaultCriticalThresholdMb;
-
- TestDirectMemoryPressureCalculator calc(false); // Small-memory model.
-
- EXPECT_EQ(kModerateMb, calc.moderate_threshold_mb());
- EXPECT_EQ(kCriticalMb, calc.critical_threshold_mb());
-
- ASSERT_NO_FATAL_FAILURE(CalculateCurrentPressureLevelTest(&calc));
-}
+ CalculateCurrentMemoryPressureLevel) {
+ TestDirectMemoryPressureCalculator calc;
-// Tests the fundamental direct calculation of memory pressure with automatic
-// large-memory thresholds.
-TEST_F(DirectMemoryPressureCalculatorTest,
- CalculateCurrentMemoryPressureLevelLarge) {
static const int kModerateMb =
- DirectMemoryPressureCalculator::kLargeMemoryDefaultModerateThresholdMb;
+ (100 - DirectMemoryPressureCalculator::kDefaultModerateThresholdPc) *
+ kTotalMemoryInMB / 100;
static const int kCriticalMb =
- DirectMemoryPressureCalculator::kLargeMemoryDefaultCriticalThresholdMb;
-
- TestDirectMemoryPressureCalculator calc(true); // Large-memory model.
+ (100 - DirectMemoryPressureCalculator::kDefaultCriticalThresholdPc) *
+ kTotalMemoryInMB / 100;
EXPECT_EQ(kModerateMb, calc.moderate_threshold_mb());
EXPECT_EQ(kCriticalMb, calc.critical_threshold_mb());

Powered by Google App Engine
This is Rietveld 408576698