OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/process/process_metrics.h" |
9 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
10 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
15 | 16 |
16 typedef PlatformTest SysInfoTest; | 17 typedef PlatformTest SysInfoTest; |
17 using base::FilePath; | 18 using base::FilePath; |
18 | 19 |
19 TEST_F(SysInfoTest, NumProcs) { | 20 TEST_F(SysInfoTest, NumProcs) { |
20 // We aren't actually testing that it's correct, just that it's sane. | 21 // We aren't actually testing that it's correct, just that it's sane. |
21 EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1); | 22 EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1); |
22 } | 23 } |
23 | 24 |
24 TEST_F(SysInfoTest, AmountOfMem) { | 25 TEST_F(SysInfoTest, AmountOfMem) { |
25 // We aren't actually testing that it's correct, just that it's sane. | 26 // We aren't actually testing that it's correct, just that it's sane. |
26 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0); | 27 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0); |
27 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0); | 28 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0); |
28 // The maxmimal amount of virtual memory can be zero which means unlimited. | 29 // The maxmimal amount of virtual memory can be zero which means unlimited. |
29 EXPECT_GE(base::SysInfo::AmountOfVirtualMemory(), 0); | 30 EXPECT_GE(base::SysInfo::AmountOfVirtualMemory(), 0); |
30 } | 31 } |
31 | 32 |
| 33 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 34 TEST_F(SysInfoTest, AmountOfAvailablePhysicalMemory) { |
| 35 // Note: info is in _K_bytes. |
| 36 base::SystemMemoryInfoKB info; |
| 37 ASSERT_TRUE(base::GetSystemMemoryInfo(&info)); |
| 38 EXPECT_GT(info.free, 0); |
| 39 |
| 40 if (info.available != 0) { |
| 41 // If there is MemAvailable from kernel. |
| 42 EXPECT_LT(info.available, info.total); |
| 43 const int64_t amount = base::SysInfo::AmountOfAvailablePhysicalMemory(info); |
| 44 // We aren't actually testing that it's correct, just that it's sane. |
| 45 EXPECT_GT(amount, info.free * 1024); |
| 46 EXPECT_LT(amount, info.available * 1024); |
| 47 // Simulate as if there is no MemAvailable. |
| 48 info.available = 0; |
| 49 } |
| 50 |
| 51 // There is no MemAvailable. Check the fallback logic. |
| 52 const int64_t amount = base::SysInfo::AmountOfAvailablePhysicalMemory(info); |
| 53 // We aren't actually testing that it's correct, just that it's sane. |
| 54 EXPECT_GT(amount, info.free * 1024); |
| 55 EXPECT_LT(amount, info.total * 1024); |
| 56 } |
| 57 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 58 |
32 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { | 59 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { |
33 // We aren't actually testing that it's correct, just that it's sane. | 60 // We aren't actually testing that it's correct, just that it's sane. |
34 FilePath tmp_path; | 61 FilePath tmp_path; |
35 ASSERT_TRUE(base::GetTempDir(&tmp_path)); | 62 ASSERT_TRUE(base::GetTempDir(&tmp_path)); |
36 EXPECT_GE(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) | 63 EXPECT_GE(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) |
37 << tmp_path.value(); | 64 << tmp_path.value(); |
38 } | 65 } |
39 | 66 |
40 TEST_F(SysInfoTest, AmountOfTotalDiskSpace) { | 67 TEST_F(SysInfoTest, AmountOfTotalDiskSpace) { |
41 // We aren't actually testing that it's correct, just that it's sane. | 68 // We aren't actually testing that it's correct, just that it's sane. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 const char* kLsbRelease1 = "CHROMEOS_RELEASE_BOARD=Glimmer\n"; | 187 const char* kLsbRelease1 = "CHROMEOS_RELEASE_BOARD=Glimmer\n"; |
161 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, base::Time()); | 188 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, base::Time()); |
162 EXPECT_EQ("glimmer", base::SysInfo::GetStrippedReleaseBoard()); | 189 EXPECT_EQ("glimmer", base::SysInfo::GetStrippedReleaseBoard()); |
163 | 190 |
164 const char* kLsbRelease2 = "CHROMEOS_RELEASE_BOARD=glimmer-signed-mp-v4keys"; | 191 const char* kLsbRelease2 = "CHROMEOS_RELEASE_BOARD=glimmer-signed-mp-v4keys"; |
165 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, base::Time()); | 192 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, base::Time()); |
166 EXPECT_EQ("glimmer", base::SysInfo::GetStrippedReleaseBoard()); | 193 EXPECT_EQ("glimmer", base::SysInfo::GetStrippedReleaseBoard()); |
167 } | 194 } |
168 | 195 |
169 #endif // OS_CHROMEOS | 196 #endif // OS_CHROMEOS |
OLD | NEW |