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

Side by Side Diff: base/sys_info_unittest.cc

Issue 2765793002: Fix integer overflow in unittest. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698