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

Unified Diff: base/process/process_metrics_unittest.cc

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Rebase. Created 3 years, 9 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: base/process/process_metrics_unittest.cc
diff --git a/base/process/process_metrics_unittest.cc b/base/process/process_metrics_unittest.cc
index 3e059b48a45f565f0bbe6f12060a19e8ada834f6..58ccaf8aa0aceee3688167c11b44fc9446a7401a 100644
--- a/base/process/process_metrics_unittest.cc
+++ b/base/process/process_metrics_unittest.cc
@@ -17,6 +17,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
+#include "base/sys_info.h"
#include "base/test/multiprocess_test.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
@@ -106,6 +107,7 @@ TEST_F(SystemMetricsTest, ParseMeminfo) {
std::string valid_input1 =
"MemTotal: 3981504 kB\n"
"MemFree: 140764 kB\n"
+ "MemAvailable: 535413 kB\n"
"Buffers: 116480 kB\n"
"Cached: 406160 kB\n"
"SwapCached: 21304 kB\n"
@@ -171,6 +173,7 @@ TEST_F(SystemMetricsTest, ParseMeminfo) {
EXPECT_TRUE(ParseProcMeminfo(valid_input1, &meminfo));
EXPECT_EQ(meminfo.total, 3981504);
EXPECT_EQ(meminfo.free, 140764);
+ EXPECT_EQ(meminfo.available, 535413);
EXPECT_EQ(meminfo.buffers, 116480);
EXPECT_EQ(meminfo.cached, 406160);
EXPECT_EQ(meminfo.active_anon, 2972352);
@@ -180,18 +183,33 @@ TEST_F(SystemMetricsTest, ParseMeminfo) {
EXPECT_EQ(meminfo.swap_total, 5832280);
EXPECT_EQ(meminfo.swap_free, 3672368);
EXPECT_EQ(meminfo.dirty, 184);
+ EXPECT_EQ(meminfo.reclaimable, 30936);
#if defined(OS_CHROMEOS)
EXPECT_EQ(meminfo.shmem, 140204);
EXPECT_EQ(meminfo.slab, 54212);
#endif
+#if defined(OS_LINUX) || defined(OS_LINUX)
+ EXPECT_EQ(355725,
+ base::SysInfo::AmountOfAvailablePhysicalMemory(meminfo) / 1024);
+ // Simulate as if there is no MemAvailable.
+ meminfo.available = 0;
+ EXPECT_EQ(374448,
+ base::SysInfo::AmountOfAvailablePhysicalMemory(meminfo) / 1024);
+#endif
+ meminfo = {};
EXPECT_TRUE(ParseProcMeminfo(valid_input2, &meminfo));
EXPECT_EQ(meminfo.total, 255908);
EXPECT_EQ(meminfo.free, 69936);
+ EXPECT_EQ(meminfo.available, 0);
EXPECT_EQ(meminfo.buffers, 15812);
EXPECT_EQ(meminfo.cached, 115124);
EXPECT_EQ(meminfo.swap_total, 524280);
EXPECT_EQ(meminfo.swap_free, 524200);
EXPECT_EQ(meminfo.dirty, 4);
+#if defined(OS_LINUX) || defined(OS_LINUX)
+ EXPECT_EQ(69936,
+ base::SysInfo::AmountOfAvailablePhysicalMemory(meminfo) / 1024);
+#endif
}
TEST_F(SystemMetricsTest, ParseVmstat) {
@@ -341,7 +359,7 @@ TEST_F(SystemMetricsTest, TestNoNegativeCpuUsage) {
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
-#if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) || \
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) || \
danakj 2017/03/10 17:13:48 Doesn't OS_MACOSX include OS_IOS so you could just
Michael K. (Yandex Team) 2017/03/10 18:22:37 You are right: IOS is MACOSX. This should be exclu
defined(OS_LINUX) || defined(OS_ANDROID)
TEST(SystemMetrics2Test, GetSystemMemoryInfo) {
SystemMemoryInfoKB info;
@@ -349,7 +367,11 @@ TEST(SystemMetrics2Test, GetSystemMemoryInfo) {
// Ensure each field received a value.
EXPECT_GT(info.total, 0);
+#if defined(OS_WIN)
+ EXPECT_GT(info.available, 0);
danakj 2017/03/10 17:13:48 linux and android have an available field too
Michael K. (Yandex Team) 2017/03/10 18:22:37 Not always. We discussed it with primiano@. When t
+#else
EXPECT_GT(info.free, 0);
+#endif
#if defined(OS_LINUX) || defined(OS_ANDROID)
EXPECT_GT(info.buffers, 0);
EXPECT_GT(info.cached, 0);
@@ -360,7 +382,9 @@ TEST(SystemMetrics2Test, GetSystemMemoryInfo) {
#endif // defined(OS_LINUX) || defined(OS_ANDROID)
// All the values should be less than the total amount of memory.
+#if !defined(OS_WIN)
EXPECT_LT(info.free, info.total);
+#endif
#if defined(OS_LINUX) || defined(OS_ANDROID)
EXPECT_LT(info.buffers, info.total);
EXPECT_LT(info.cached, info.total);
@@ -370,6 +394,10 @@ TEST(SystemMetrics2Test, GetSystemMemoryInfo) {
EXPECT_LT(info.inactive_file, info.total);
#endif // defined(OS_LINUX) || defined(OS_ANDROID)
+#if defined(OS_MACOSX) || defined(OS_IOS)
+ EXPECT_GT(info.file_backed, 0);
+#endif
+
#if defined(OS_CHROMEOS)
// Chrome OS exposes shmem.
EXPECT_GT(info.shmem, 0);
@@ -378,7 +406,7 @@ TEST(SystemMetrics2Test, GetSystemMemoryInfo) {
// and gem_size cannot be tested here.
#endif
}
-#endif // defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) ||
+#endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) ||
// defined(OS_LINUX) || defined(OS_ANDROID)
#if defined(OS_LINUX) || defined(OS_ANDROID)

Powered by Google App Engine
This is Rietveld 408576698