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/process/process_metrics.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 // Note: info is in _K_bytes. | 36 // Note: info is in _K_bytes. |
37 SystemMemoryInfoKB info; | 37 SystemMemoryInfoKB info; |
38 ASSERT_TRUE(GetSystemMemoryInfo(&info)); | 38 ASSERT_TRUE(GetSystemMemoryInfo(&info)); |
39 EXPECT_GT(info.free, 0); | 39 EXPECT_GT(info.free, 0); |
40 | 40 |
41 if (info.available != 0) { | 41 if (info.available != 0) { |
42 // If there is MemAvailable from kernel. | 42 // If there is MemAvailable from kernel. |
43 EXPECT_LT(info.available, info.total); | 43 EXPECT_LT(info.available, info.total); |
44 const int64_t amount = SysInfo::AmountOfAvailablePhysicalMemory(info); | 44 const int64_t amount = SysInfo::AmountOfAvailablePhysicalMemory(info); |
45 // We aren't actually testing that it's correct, just that it's sane. | 45 // We aren't actually testing that it's correct, just that it's sane. |
46 EXPECT_GT(amount, info.free * 1024); | 46 EXPECT_GT(amount, static_cast<int64_t>(info.free) * 1024); |
47 EXPECT_LT(amount, info.available * 1024); | 47 EXPECT_LT(amount / 1024, info.available); |
48 // Simulate as if there is no MemAvailable. | 48 // Simulate as if there is no MemAvailable. |
49 info.available = 0; | 49 info.available = 0; |
50 } | 50 } |
51 | 51 |
52 // There is no MemAvailable. Check the fallback logic. | 52 // There is no MemAvailable. Check the fallback logic. |
53 const int64_t amount = SysInfo::AmountOfAvailablePhysicalMemory(info); | 53 const int64_t amount = SysInfo::AmountOfAvailablePhysicalMemory(info); |
54 // We aren't actually testing that it's correct, just that it's sane. | 54 // We aren't actually testing that it's correct, just that it's sane. |
55 EXPECT_GT(amount, info.free * 1024); | 55 EXPECT_GT(amount, static_cast<int64_t>(info.free) * 1024); |
56 EXPECT_LT(amount, info.total * 1024); | 56 EXPECT_LT(amount / 1024, info.total); |
57 } | 57 } |
58 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 58 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
59 | 59 |
60 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { | 60 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { |
61 // We aren't actually testing that it's correct, just that it's sane. | 61 // We aren't actually testing that it's correct, just that it's sane. |
62 FilePath tmp_path; | 62 FilePath tmp_path; |
63 ASSERT_TRUE(GetTempDir(&tmp_path)); | 63 ASSERT_TRUE(GetTempDir(&tmp_path)); |
64 EXPECT_GE(SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) << tmp_path.value(); | 64 EXPECT_GE(SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) << tmp_path.value(); |
65 } | 65 } |
66 | 66 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 EXPECT_EQ("glimmer", SysInfo::GetStrippedReleaseBoard()); | 188 EXPECT_EQ("glimmer", SysInfo::GetStrippedReleaseBoard()); |
189 | 189 |
190 const char* kLsbRelease2 = "CHROMEOS_RELEASE_BOARD=glimmer-signed-mp-v4keys"; | 190 const char* kLsbRelease2 = "CHROMEOS_RELEASE_BOARD=glimmer-signed-mp-v4keys"; |
191 SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time()); | 191 SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, Time()); |
192 EXPECT_EQ("glimmer", SysInfo::GetStrippedReleaseBoard()); | 192 EXPECT_EQ("glimmer", SysInfo::GetStrippedReleaseBoard()); |
193 } | 193 } |
194 | 194 |
195 #endif // OS_CHROMEOS | 195 #endif // OS_CHROMEOS |
196 | 196 |
197 } // namespace base | 197 } // namespace base |
OLD | NEW |