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

Unified Diff: base/allocator/partition_allocator/partition_alloc_unittest.cc

Issue 2589813002: base/allocator/partition_alloc: make unittests lowmem friendly (Closed)
Patch Set: fix asan Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/allocator/partition_allocator/partition_alloc_unittest.cc
diff --git a/base/allocator/partition_allocator/partition_alloc_unittest.cc b/base/allocator/partition_allocator/partition_alloc_unittest.cc
index dbc8ed21018a193ff3b2ad26cd71771cd90862b5..7bc754fcdd857f2bc374e13c536064cd56768d1a 100644
--- a/base/allocator/partition_allocator/partition_alloc_unittest.cc
+++ b/base/allocator/partition_allocator/partition_alloc_unittest.cc
@@ -11,6 +11,7 @@
#include <vector>
#include "base/bits.h"
+#include "base/sys_info.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -184,6 +185,10 @@ void CheckPageInCore(void* ptr, bool inCore) {
#endif
}
+bool IsLargeMemoryDevice() {
+ return base::SysInfo::AmountOfPhysicalMemory() >= 2LL * 1024 * 1024 * 1024;
+}
+
class MockPartitionStatsDumper : public PartitionStatsDumper {
public:
MockPartitionStatsDumper()
@@ -669,9 +674,13 @@ TEST(PartitionAllocTest, GenericAllocSizes) {
// Can we allocate a massive (512MB) size?
// Allocate 512MB, but +1, to test for cookie writing alignment issues.
- ptr = partitionAllocGeneric(genericAllocator.root(), 512 * 1024 * 1024 + 1,
- typeName);
- partitionFreeGeneric(genericAllocator.root(), ptr);
+ // Test this only if the device has enough memory or it might fail due
+ // to OOM.
+ if (IsLargeMemoryDevice()) {
+ ptr = partitionAllocGeneric(genericAllocator.root(), 512 * 1024 * 1024 + 1,
+ typeName);
+ partitionFreeGeneric(genericAllocator.root(), ptr);
+ }
// Check a more reasonable, but still direct mapped, size.
// Chop a system page and a byte off to test for rounding errors.
@@ -742,15 +751,18 @@ TEST(PartitionAllocTest, GenericAllocGetSize) {
partitionFreeGeneric(genericAllocator.root(), ptr);
// Allocate something very large, and uneven.
- requestedSize = 512 * 1024 * 1024 - 1;
- predictedSize =
- partitionAllocActualSize(genericAllocator.root(), requestedSize);
- ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName);
- EXPECT_TRUE(ptr);
- actualSize = partitionAllocGetSize(ptr);
- EXPECT_EQ(predictedSize, actualSize);
- EXPECT_LT(requestedSize, actualSize);
- partitionFreeGeneric(genericAllocator.root(), ptr);
+ if (IsLargeMemoryDevice()) {
+ requestedSize = 512 * 1024 * 1024 - 1;
+ predictedSize =
+ partitionAllocActualSize(genericAllocator.root(), requestedSize);
+ ptr =
+ partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName);
+ EXPECT_TRUE(ptr);
+ actualSize = partitionAllocGetSize(ptr);
+ EXPECT_EQ(predictedSize, actualSize);
+ EXPECT_LT(requestedSize, actualSize);
+ partitionFreeGeneric(genericAllocator.root(), ptr);
+ }
// Too large allocation.
requestedSize = INT_MAX;
@@ -1325,7 +1337,7 @@ TEST(PartitionAllocTest, MAYBE_RepeatedReturnNull) {
#endif
TEST(PartitionAllocTest, MAYBE_RepeatedReturnNullDirect) {
// A direct-mapped allocation size.
- DoReturnNullTest(256 * 1024 * 1024);
+ DoReturnNullTest(32 * 1024 * 1024);
}
#endif // !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX)
« 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