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

Side by Side Diff: base/process/memory_unittest.cc

Issue 2902043007: allocator: rename use_experimental_allocator_shim to use_allocator_shim (Closed)
Patch Set: Created 3 years, 7 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/process/memory_mac.mm ('k') | base/trace_event/malloc_dump_provider.cc » ('j') | 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 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include "base/process/memory.h" 7 #include "base/process/memory.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #endif // defined(OS_WIN) 54 #endif // defined(OS_WIN)
55 55
56 #if defined(OS_MACOSX) 56 #if defined(OS_MACOSX)
57 57
58 // For the following Mac tests: 58 // For the following Mac tests:
59 // Note that base::EnableTerminationOnHeapCorruption() is called as part of 59 // Note that base::EnableTerminationOnHeapCorruption() is called as part of
60 // test suite setup and does not need to be done again, else mach_override 60 // test suite setup and does not need to be done again, else mach_override
61 // will fail. 61 // will fail.
62 62
63 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { 63 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
64 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 64 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
65 base::allocator::InitializeAllocatorShim(); 65 base::allocator::InitializeAllocatorShim();
66 #endif 66 #endif
67 // Assert that freeing an unallocated pointer will crash the process. 67 // Assert that freeing an unallocated pointer will crash the process.
68 char buf[9]; 68 char buf[9];
69 asm("" : "=r" (buf)); // Prevent clang from being too smart. 69 asm("" : "=r" (buf)); // Prevent clang from being too smart.
70 #if ARCH_CPU_64_BITS 70 #if ARCH_CPU_64_BITS
71 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption 71 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption
72 // but does not output anything. 72 // but does not output anything.
73 ASSERT_DEATH(free(buf), ""); 73 ASSERT_DEATH(free(buf), "");
74 #elif defined(ADDRESS_SANITIZER) 74 #elif defined(ADDRESS_SANITIZER)
75 // AddressSanitizer replaces malloc() and prints a different error message on 75 // AddressSanitizer replaces malloc() and prints a different error message on
76 // heap corruption. 76 // heap corruption.
77 ASSERT_DEATH(free(buf), "attempting free on address which " 77 ASSERT_DEATH(free(buf), "attempting free on address which "
78 "was not malloc\\(\\)-ed"); 78 "was not malloc\\(\\)-ed");
79 #else 79 #else
80 ADD_FAILURE() << "This test is not supported in this build configuration."; 80 ADD_FAILURE() << "This test is not supported in this build configuration.";
81 #endif 81 #endif
82 82
83 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 83 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
84 base::allocator::UninterceptMallocZonesForTesting(); 84 base::allocator::UninterceptMallocZonesForTesting();
85 #endif 85 #endif
86 } 86 }
87 87
88 #endif // defined(OS_MACOSX) 88 #endif // defined(OS_MACOSX)
89 89
90 TEST(MemoryTest, AllocatorShimWorking) { 90 TEST(MemoryTest, AllocatorShimWorking) {
91 #if defined(OS_MACOSX) 91 #if defined(OS_MACOSX)
92 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 92 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
93 base::allocator::InitializeAllocatorShim(); 93 base::allocator::InitializeAllocatorShim();
94 #endif 94 #endif
95 base::allocator::InterceptAllocationsMac(); 95 base::allocator::InterceptAllocationsMac();
96 #endif 96 #endif
97 ASSERT_TRUE(base::allocator::IsAllocatorInitialized()); 97 ASSERT_TRUE(base::allocator::IsAllocatorInitialized());
98 98
99 #if defined(OS_MACOSX) 99 #if defined(OS_MACOSX)
100 base::allocator::UninterceptMallocZonesForTesting(); 100 base::allocator::UninterceptMallocZonesForTesting();
101 #endif 101 #endif
102 } 102 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 protected: 136 protected:
137 void* value_; 137 void* value_;
138 size_t test_size_; 138 size_t test_size_;
139 size_t insecure_test_size_; 139 size_t insecure_test_size_;
140 ssize_t signed_test_size_; 140 ssize_t signed_test_size_;
141 }; 141 };
142 142
143 class OutOfMemoryDeathTest : public OutOfMemoryTest { 143 class OutOfMemoryDeathTest : public OutOfMemoryTest {
144 public: 144 public:
145 void SetUpInDeathAssert() { 145 void SetUpInDeathAssert() {
146 #if defined(OS_MACOSX) && BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 146 #if defined(OS_MACOSX) && BUILDFLAG(USE_ALLOCATOR_SHIM)
147 base::allocator::InitializeAllocatorShim(); 147 base::allocator::InitializeAllocatorShim();
148 #endif 148 #endif
149 149
150 // Must call EnableTerminationOnOutOfMemory() because that is called from 150 // Must call EnableTerminationOnOutOfMemory() because that is called from
151 // chrome's main function and therefore hasn't been called yet. 151 // chrome's main function and therefore hasn't been called yet.
152 // Since this call may result in another thread being created and death 152 // Since this call may result in another thread being created and death
153 // tests shouldn't be started in a multithread environment, this call 153 // tests shouldn't be started in a multithread environment, this call
154 // should be done inside of the ASSERT_DEATH. 154 // should be done inside of the ASSERT_DEATH.
155 base::EnableTerminationOnOutOfMemory(); 155 base::EnableTerminationOnOutOfMemory();
156 } 156 }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 bytes = static_cast<const char*>(value_); 503 bytes = static_cast<const char*>(value_);
504 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) 504 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i)
505 EXPECT_EQ(0, bytes[i]); 505 EXPECT_EQ(0, bytes[i]);
506 free(value_); 506 free(value_);
507 507
508 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); 508 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_));
509 EXPECT_TRUE(value_ == NULL); 509 EXPECT_TRUE(value_ == NULL);
510 } 510 }
511 #endif // !defined(OS_OPENBSD) && BUILDFLAG(ENABLE_WIN_ALLOCATOR_SHIM_TESTS) && 511 #endif // !defined(OS_OPENBSD) && BUILDFLAG(ENABLE_WIN_ALLOCATOR_SHIM_TESTS) &&
512 // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 512 // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW
« no previous file with comments | « base/process/memory_mac.mm ('k') | base/trace_event/malloc_dump_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698