summaryrefslogtreecommitdiff
path: root/base/sys_info_unittest.cc
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2017-03-14 10:55:53 -0700
committerJakub Pawlowski <jpawlowski@google.com>2017-12-22 03:06:26 -0800
commit319afc59a539d6261307aadbdab4d4ee93eaf1ff (patch)
tree0f21b95ba579352a9829d3868c7365d4f9dde210 /base/sys_info_unittest.cc
parent8abac493f652a1835c61e538919820aa77658a39 (diff)
downloadlibchrome-319afc59a539d6261307aadbdab4d4ee93eaf1ff.tar.gz
Uprev the library to r462023 from Chromium, 3rd attempt
This merge was done against r462023 which corresponds to git commit 32eb7c31af9cab6231f0d3d05206072079177605 from Apr 05, 2017 First attempt, in commit bf8c17f71511c1e90cd8cccfe71f0852c566bd3b was badly squashed, causing automated test failure in system/bt. Next one broke mac build. Test: manually ran all test from system/bt that failed on previous attempt, plus libchrome_unittest Change-Id: I60003263418de3078c7be2da9fb1eeaeb786f3d0
Diffstat (limited to 'base/sys_info_unittest.cc')
-rw-r--r--base/sys_info_unittest.cc122
1 files changed, 75 insertions, 47 deletions
diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc
index c3b8507707..94b5a84971 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"
@@ -13,46 +14,71 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-typedef PlatformTest SysInfoTest;
-using base::FilePath;
+namespace base {
+
+using SysInfoTest = PlatformTest;
TEST_F(SysInfoTest, NumProcs) {
// We aren't actually testing that it's correct, just that it's sane.
- EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1);
+ EXPECT_GE(SysInfo::NumberOfProcessors(), 1);
}
TEST_F(SysInfoTest, AmountOfMem) {
// We aren't actually testing that it's correct, just that it's sane.
- EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0);
- EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0);
+ EXPECT_GT(SysInfo::AmountOfPhysicalMemory(), 0);
+ EXPECT_GT(SysInfo::AmountOfPhysicalMemoryMB(), 0);
// The maxmimal amount of virtual memory can be zero which means unlimited.
- EXPECT_GE(base::SysInfo::AmountOfVirtualMemory(), 0);
+ EXPECT_GE(SysInfo::AmountOfVirtualMemory(), 0);
}
+#if defined(OS_LINUX) || defined(OS_ANDROID)
+TEST_F(SysInfoTest, AmountOfAvailablePhysicalMemory) {
+ // Note: info is in _K_bytes.
+ SystemMemoryInfoKB info;
+ ASSERT_TRUE(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 = SysInfo::AmountOfAvailablePhysicalMemory(info);
+ // We aren't actually testing that it's correct, just that it's sane.
+ EXPECT_GT(amount, static_cast<int64_t>(info.free) * 1024);
+ EXPECT_LT(amount / 1024, info.available);
+ // Simulate as if there is no MemAvailable.
+ info.available = 0;
+ }
+
+ // There is no MemAvailable. Check the fallback logic.
+ const int64_t amount = SysInfo::AmountOfAvailablePhysicalMemory(info);
+ // We aren't actually testing that it's correct, just that it's sane.
+ EXPECT_GT(amount, static_cast<int64_t>(info.free) * 1024);
+ EXPECT_LT(amount / 1024, info.total);
+}
+#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;
- ASSERT_TRUE(base::GetTempDir(&tmp_path));
- EXPECT_GE(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0)
- << tmp_path.value();
+ ASSERT_TRUE(GetTempDir(&tmp_path));
+ EXPECT_GE(SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) << tmp_path.value();
}
TEST_F(SysInfoTest, AmountOfTotalDiskSpace) {
// We aren't actually testing that it's correct, just that it's sane.
FilePath tmp_path;
- ASSERT_TRUE(base::GetTempDir(&tmp_path));
- EXPECT_GT(base::SysInfo::AmountOfTotalDiskSpace(tmp_path), 0)
- << tmp_path.value();
+ ASSERT_TRUE(GetTempDir(&tmp_path));
+ EXPECT_GT(SysInfo::AmountOfTotalDiskSpace(tmp_path), 0) << tmp_path.value();
}
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
int32_t os_major_version = -1;
int32_t os_minor_version = -1;
int32_t os_bugfix_version = -1;
- base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
- &os_minor_version,
- &os_bugfix_version);
+ SysInfo::OperatingSystemVersionNumbers(&os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
EXPECT_GT(os_major_version, -1);
EXPECT_GT(os_minor_version, -1);
EXPECT_GT(os_bugfix_version, -1);
@@ -60,18 +86,18 @@ TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
#endif
TEST_F(SysInfoTest, Uptime) {
- base::TimeDelta up_time_1 = base::SysInfo::Uptime();
+ TimeDelta up_time_1 = SysInfo::Uptime();
// UpTime() is implemented internally using TimeTicks::Now(), which documents
// system resolution as being 1-15ms. Sleep a little longer than that.
- base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
- base::TimeDelta up_time_2 = base::SysInfo::Uptime();
+ PlatformThread::Sleep(TimeDelta::FromMilliseconds(20));
+ TimeDelta up_time_2 = SysInfo::Uptime();
EXPECT_GT(up_time_1.InMicroseconds(), 0);
EXPECT_GT(up_time_2.InMicroseconds(), up_time_1.InMicroseconds());
}
#if defined(OS_MACOSX) && !defined(OS_IOS)
TEST_F(SysInfoTest, HardwareModelName) {
- std::string hardware_model = base::SysInfo::HardwareModelName();
+ std::string hardware_model = SysInfo::HardwareModelName();
EXPECT_FALSE(hardware_model.empty());
}
#endif
@@ -85,10 +111,10 @@ TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) {
const char kLsbRelease[] =
"FOO=1234123.34.5\n"
"CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
- base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
- &os_minor_version,
- &os_bugfix_version);
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, Time());
+ SysInfo::OperatingSystemVersionNumbers(&os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
EXPECT_EQ(1, os_major_version);
EXPECT_EQ(2, os_minor_version);
EXPECT_EQ(3, os_bugfix_version);
@@ -101,10 +127,10 @@ TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) {
const char kLsbRelease[] =
"CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
"FOO=1234123.34.5\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
- base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
- &os_minor_version,
- &os_bugfix_version);
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, Time());
+ SysInfo::OperatingSystemVersionNumbers(&os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
EXPECT_EQ(1, os_major_version);
EXPECT_EQ(2, os_minor_version);
EXPECT_EQ(3, os_bugfix_version);
@@ -115,10 +141,10 @@ TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) {
int32_t os_minor_version = -1;
int32_t os_bugfix_version = -1;
const char kLsbRelease[] = "FOO=1234123.34.5\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
- base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
- &os_minor_version,
- &os_bugfix_version);
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, Time());
+ SysInfo::OperatingSystemVersionNumbers(&os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
EXPECT_EQ(0, os_major_version);
EXPECT_EQ(0, os_minor_version);
EXPECT_EQ(0, os_bugfix_version);
@@ -127,43 +153,45 @@ TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) {
TEST_F(SysInfoTest, GoogleChromeOSLsbReleaseTime) {
const char kLsbRelease[] = "CHROMEOS_RELEASE_VERSION=1.2.3.4";
// Use a fake time that can be safely displayed as a string.
- const base::Time lsb_release_time(base::Time::FromDoubleT(12345.6));
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, lsb_release_time);
- base::Time parsed_lsb_release_time = base::SysInfo::GetLsbReleaseTime();
+ const Time lsb_release_time(Time::FromDoubleT(12345.6));
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, lsb_release_time);
+ Time parsed_lsb_release_time = SysInfo::GetLsbReleaseTime();
EXPECT_DOUBLE_EQ(lsb_release_time.ToDoubleT(),
parsed_lsb_release_time.ToDoubleT());
}
TEST_F(SysInfoTest, IsRunningOnChromeOS) {
- base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time());
- EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS());
+ SysInfo::SetChromeOSVersionInfoForTest("", Time());
+ EXPECT_FALSE(SysInfo::IsRunningOnChromeOS());
const char kLsbRelease1[] =
"CHROMEOS_RELEASE_NAME=Non Chrome OS\n"
"CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, base::Time());
- EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS());
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, Time());
+ EXPECT_FALSE(SysInfo::IsRunningOnChromeOS());
const char kLsbRelease2[] =
"CHROMEOS_RELEASE_NAME=Chrome OS\n"
"CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, base::Time());
- EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS());
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time());
+ EXPECT_TRUE(SysInfo::IsRunningOnChromeOS());
const char kLsbRelease3[] =
"CHROMEOS_RELEASE_NAME=Chromium OS\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease3, base::Time());
- EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS());
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease3, Time());
+ EXPECT_TRUE(SysInfo::IsRunningOnChromeOS());
}
TEST_F(SysInfoTest, GetStrippedReleaseBoard) {
const char* kLsbRelease1 = "CHROMEOS_RELEASE_BOARD=Glimmer\n";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, base::Time());
- EXPECT_EQ("glimmer", base::SysInfo::GetStrippedReleaseBoard());
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, Time());
+ EXPECT_EQ("glimmer", SysInfo::GetStrippedReleaseBoard());
const char* kLsbRelease2 = "CHROMEOS_RELEASE_BOARD=glimmer-signed-mp-v4keys";
- base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, base::Time());
- EXPECT_EQ("glimmer", base::SysInfo::GetStrippedReleaseBoard());
+ SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time());
+ EXPECT_EQ("glimmer", SysInfo::GetStrippedReleaseBoard());
}
#endif // OS_CHROMEOS
+
+} // namespace base