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

Unified Diff: base/sys_info_unittest.cc

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix unittest compilation under Linuxes. 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
« no previous file with comments | « base/sys_info_openbsd.cc ('k') | base/sys_info_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_unittest.cc
diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc
index c3b85077071a8ead6a263947fc109e374516a761..f5ef3974b640b4c79f9643327c7353c8de2ce167 100644
--- a/base/sys_info_unittest.cc
+++ b/base/sys_info_unittest.cc
@@ -6,6 +6,7 @@
#include "base/environment.h"
#include "base/files/file_util.h"
+#include "base/process/process_metrics.h"
#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
@@ -29,6 +30,32 @@ TEST_F(SysInfoTest, AmountOfMem) {
EXPECT_GE(base::SysInfo::AmountOfVirtualMemory(), 0);
}
+#if defined(OS_LINUX) || defined(OS_ANDROID)
+TEST_F(SysInfoTest, AmountOfAvailablePhysicalMemory) {
+ // Note: info is in _K_bytes.
+ base::SystemMemoryInfoKB info;
+ ASSERT_TRUE(base::GetSystemMemoryInfo(&info));
+ EXPECT_GT(info.free, 0);
+
+ if (info.available != 0) {
+ // If there is MemAvailable from kernel.
+ EXPECT_LT(info.available, info.total);
+ const int64_t amount = base::SysInfo::AmountOfAvailablePhysicalMemory(info);
+ // We aren't actually testing that it's correct, just that it's sane.
+ EXPECT_GT(amount, info.free * 1024);
+ EXPECT_LT(amount, info.available * 1024);
+ // Simulate as if there is no MemAvailable.
+ info.available = 0;
Michael K. (Yandex Team) 2017/03/09 10:40:56 The answer on yours:
+ }
+
+ // There is no MemAvailable. Check the fallback logic.
+ const int64_t amount = base::SysInfo::AmountOfAvailablePhysicalMemory(info);
+ // We aren't actually testing that it's correct, just that it's sane.
+ EXPECT_GT(amount, info.free * 1024);
+ EXPECT_LT(amount, info.total * 1024);
+}
+#endif // defined(OS_LINUX) || defined(OS_ANDROID)
+
TEST_F(SysInfoTest, AmountOfFreeDiskSpace) {
// We aren't actually testing that it's correct, just that it's sane.
FilePath tmp_path;
« no previous file with comments | « base/sys_info_openbsd.cc ('k') | base/sys_info_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698