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

Side by Side Diff: base/allocator/partition_allocator/partition_alloc_unittest.cc

Issue 2689103002: Fix partition_alloc unit tests. (Closed)
Patch Set: Created 3 years, 10 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 | « base/allocator/partition_allocator/PartitionAlloc.md ('k') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/allocator/partition_allocator/partition_alloc.h" 5 #include "base/allocator/partition_allocator/partition_alloc.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #else 49 #else
50 const size_t kPointerOffset = kCookieSize; 50 const size_t kPointerOffset = kCookieSize;
51 const size_t kExtraAllocSize = kCookieSize * 2; 51 const size_t kExtraAllocSize = kCookieSize * 2;
52 #endif 52 #endif
53 const size_t kRealAllocSize = kTestAllocSize + kExtraAllocSize; 53 const size_t kRealAllocSize = kTestAllocSize + kExtraAllocSize;
54 const size_t kTestBucketIndex = kRealAllocSize >> kBucketShift; 54 const size_t kTestBucketIndex = kRealAllocSize >> kBucketShift;
55 55
56 const char* type_name = nullptr; 56 const char* type_name = nullptr;
57 57
58 void TestSetup() { 58 void TestSetup() {
59 // Zero the allocator structs to clear out traces
60 // from previous test.
61 memset(&allocator, 0, sizeof(allocator));
62 memset(&generic_allocator, 0, sizeof(generic_allocator));
Wez 2017/02/12 18:51:28 This looks highly suspect; why trash the instance'
sof 2017/02/12 20:07:04 The tests use a set of global allocators, which ea
Wez 2017/02/14 00:24:11 Presumably we're assuming that the tests themselve
Wez 2017/02/14 00:42:50 OK, looking through the PartitionRoot init code, i
63
59 allocator.init(); 64 allocator.init();
60 generic_allocator.init(); 65 generic_allocator.init();
61 } 66 }
62 67
63 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) 68 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX)
64 bool SetAddressSpaceLimit() { 69 bool SetAddressSpaceLimit() {
65 #if !defined(ARCH_CPU_64_BITS) 70 #if !defined(ARCH_CPU_64_BITS)
66 // 32 bits => address space is limited already. 71 // 32 bits => address space is limited already.
67 return true; 72 return true;
68 #elif defined(OS_POSIX) && !defined(OS_MACOSX) 73 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 type_name); 1284 type_name);
1280 EXPECT_TRUE(ptrs[i]); 1285 EXPECT_TRUE(ptrs[i]);
1281 PartitionFreeGeneric(generic_allocator.root(), ptrs[i]); 1286 PartitionFreeGeneric(generic_allocator.root(), ptrs[i]);
1282 } 1287 }
1283 1288
1284 PartitionFreeGeneric(generic_allocator.root(), ptrs); 1289 PartitionFreeGeneric(generic_allocator.root(), ptrs);
1285 1290
1286 EXPECT_TRUE(ClearAddressSpaceLimit()); 1291 EXPECT_TRUE(ClearAddressSpaceLimit());
1287 } 1292 }
1288 1293
1289 // Tests that if an allocation fails in "return null" mode, repeating it doesn't 1294 // Unit tests that check if an allocation fails in "return null" mode,
1290 // crash, and still returns null. The test tries to allocate 6 GB of memory in 1295 // repeating it doesn't crash, and still returns null. The tests need to
1291 // 512 kB blocks. On 64-bit POSIX systems, the address space is limited to 6 GB 1296 // stress memory subsystem limits to do so, hence they try to allocate
1292 // using setrlimit() first. 1297 // 6 GB of memory, each with a different per-allocation block sizes.
1293 // 1298 //
1299 // On 64-bit POSIX systems, the address space is limited to 6 GB using
1300 // setrlimit() first.
1301
1302 // Test "return null" for larger, direct-mapped allocations first. As a
Wez 2017/02/12 18:51:28 Tests normally get sharded across all cores, so th
1303 // direct-mapped allocation's pages are unmapped and freed on release, this
1304 // test is performd first for these "return null" tests in order to leave
Wez 2017/02/12 18:51:28 typo: performed
1305 // sufficient unreserved virtual memory around for the later one(s).
1306
1307 // Disable this test on Android because, due to its allocation-heavy behavior,
Wez 2017/02/12 18:51:28 Looks like it is also disabled on Mac - same reaso
sof 2017/02/12 19:52:37 I believe so; this was just reordering pre-existin
1308 // it tends to get OOM-killed rather than pass.
1309 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1310 #define MAYBE_RepeatedReturnNullDirect DISABLED_RepeatedReturnNullDirect
1311 #else
1312 #define MAYBE_RepeatedReturnNullDirect RepeatedReturnNullDirect
1313 #endif
1314 TEST(PartitionAllocTest, MAYBE_RepeatedReturnNullDirect) {
1315 // A direct-mapped allocation size.
1316 DoReturnNullTest(32 * 1024 * 1024);
1317 }
1318
1319 // Test "return null" with a 512 kB block size.
Wez 2017/02/12 18:51:28 nit: This comment describes what the test *does* n
1320
1294 // Disable this test on Android because, due to its allocation-heavy behavior, 1321 // Disable this test on Android because, due to its allocation-heavy behavior,
1295 // it tends to get OOM-killed rather than pass. 1322 // it tends to get OOM-killed rather than pass.
1296 #if defined(OS_MACOSX) || defined(OS_ANDROID) 1323 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1297 #define MAYBE_RepeatedReturnNull DISABLED_RepeatedReturnNull 1324 #define MAYBE_RepeatedReturnNull DISABLED_RepeatedReturnNull
1298 #else 1325 #else
1299 #define MAYBE_RepeatedReturnNull RepeatedReturnNull 1326 #define MAYBE_RepeatedReturnNull RepeatedReturnNull
1300 #endif 1327 #endif
1301 TEST(PartitionAllocTest, MAYBE_RepeatedReturnNull) { 1328 TEST(PartitionAllocTest, MAYBE_RepeatedReturnNull) {
1302 // A single-slot but non-direct-mapped allocation size. 1329 // A single-slot but non-direct-mapped allocation size.
1303 DoReturnNullTest(512 * 1024); 1330 DoReturnNullTest(512 * 1024);
1304 } 1331 }
1305 1332
1306 // Another "return null" test but for larger, direct-mapped allocations.
1307 //
1308 // Disable this test on Android because, due to its allocation-heavy behavior,
1309 // it tends to get OOM-killed rather than pass.
1310 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1311 #define MAYBE_RepeatedReturnNullDirect DISABLED_RepeatedReturnNullDirect
1312 #else
1313 #define MAYBE_RepeatedReturnNullDirect RepeatedReturnNullDirect
1314 #endif
1315 TEST(PartitionAllocTest, MAYBE_RepeatedReturnNullDirect) {
1316 // A direct-mapped allocation size.
1317 DoReturnNullTest(32 * 1024 * 1024);
1318 }
1319
1320 #endif // !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) 1333 #endif // !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX)
1321 1334
1322 // Death tests misbehave on Android, http://crbug.com/643760. 1335 // Death tests misbehave on Android, http://crbug.com/643760.
1323 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) 1336 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
1324 1337
1325 // Make sure that malloc(-1) dies. 1338 // Make sure that malloc(-1) dies.
1326 // In the past, we had an integer overflow that would alias malloc(-1) to 1339 // In the past, we had an integer overflow that would alias malloc(-1) to
1327 // malloc(0), which is not good. 1340 // malloc(0), which is not good.
1328 TEST(PartitionAllocDeathTest, LargeAllocs) { 1341 TEST(PartitionAllocDeathTest, LargeAllocs) {
1329 TestSetup(); 1342 TestSetup();
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 EXPECT_FALSE(page->freelist_head); 2084 EXPECT_FALSE(page->freelist_head);
2072 2085
2073 PartitionFreeGeneric(generic_allocator.root(), ptr1); 2086 PartitionFreeGeneric(generic_allocator.root(), ptr1);
2074 PartitionFreeGeneric(generic_allocator.root(), ptr2); 2087 PartitionFreeGeneric(generic_allocator.root(), ptr2);
2075 } 2088 }
2076 } 2089 }
2077 2090
2078 } // namespace base 2091 } // namespace base
2079 2092
2080 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 2093 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW
« no previous file with comments | « base/allocator/partition_allocator/PartitionAlloc.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698