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; |