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

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

Issue 55983002: Make gtest always use simple internal regex engine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 unified diff | Download patch
« no previous file with comments | « base/message_loop/message_pump_libevent_unittest.cc ('k') | base/tools_sanity_unittest.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 <limits> 9 #include <limits>
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // does not call through malloc_error_break(). See the comment at 114 // does not call through malloc_error_break(). See the comment at
115 // EnableTerminationOnOutOfMemory() for more information. 115 // EnableTerminationOnOutOfMemory() for more information.
116 void* buf = NULL; 116 void* buf = NULL;
117 ASSERT_EXIT( 117 ASSERT_EXIT(
118 { 118 {
119 base::EnableTerminationOnOutOfMemory(); 119 base::EnableTerminationOnOutOfMemory();
120 120
121 buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1); 121 buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1);
122 }, 122 },
123 testing::KilledBySignal(SIGTRAP), 123 testing::KilledBySignal(SIGTRAP),
124 "\\*\\*\\* error: can't allocate region.*" 124 "\\*\\*\\* error: can't allocate region.*\\n?.*");
125 "(Terminating process due to a potential for future heap "
126 "corruption){0}");
127 125
128 base::debug::Alias(buf); 126 base::debug::Alias(buf);
129 } 127 }
130 #endif // !defined(ADDRESS_SANITIZER) 128 #endif // !defined(ADDRESS_SANITIZER)
131 129
132 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { 130 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
133 // Assert that freeing an unallocated pointer will crash the process. 131 // Assert that freeing an unallocated pointer will crash the process.
134 char buf[9]; 132 char buf[9];
135 asm("" : "=r" (buf)); // Prevent clang from being too smart. 133 asm("" : "=r" (buf)); // Prevent clang from being too smart.
136 #if ARCH_CPU_64_BITS 134 #if ARCH_CPU_64_BITS
137 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption 135 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption
138 // but does not output anything. 136 // but does not output anything.
139 ASSERT_DEATH(free(buf), ""); 137 ASSERT_DEATH(free(buf), "");
140 #elif defined(ADDRESS_SANITIZER) 138 #elif defined(ADDRESS_SANITIZER)
141 // AddressSanitizer replaces malloc() and prints a different error message on 139 // AddressSanitizer replaces malloc() and prints a different error message on
142 // heap corruption. 140 // heap corruption.
143 ASSERT_DEATH(free(buf), "attempting free on address which " 141 ASSERT_DEATH(free(buf), "attempting free on address which "
144 "was not malloc\\(\\)-ed"); 142 "was not malloc\\(\\)-ed");
145 #else 143 #else
146 ASSERT_DEATH(free(buf), "being freed.*" 144 ASSERT_DEATH(free(buf), "being freed.*\\n?\\.*"
147 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*" 145 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*\\n?.*"
148 "Terminating process due to a potential for future heap corruption"); 146 "Terminating process due to a potential for future heap corruption");
149 #endif // ARCH_CPU_64_BITS || defined(ADDRESS_SANITIZER) 147 #endif // ARCH_CPU_64_BITS || defined(ADDRESS_SANITIZER)
150 } 148 }
151 149
152 #endif // defined(OS_MACOSX) 150 #endif // defined(OS_MACOSX)
153 151
154 // Android doesn't implement set_new_handler, so we can't use the 152 // Android doesn't implement set_new_handler, so we can't use the
155 // OutOfMemoryTest cases. 153 // OutOfMemoryTest cases.
156 // OpenBSD does not support these tests either. 154 // OpenBSD does not support these tests either.
157 // AddressSanitizer and ThreadSanitizer define the malloc()/free()/etc. 155 // AddressSanitizer and ThreadSanitizer define the malloc()/free()/etc.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 SetUpInDeathAssert(); 367 SetUpInDeathAssert();
370 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} 368 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {}
371 }, ""); 369 }, "");
372 } 370 }
373 371
374 #endif // !ARCH_CPU_64_BITS 372 #endif // !ARCH_CPU_64_BITS
375 #endif // OS_MACOSX 373 #endif // OS_MACOSX
376 374
377 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && 375 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) &&
378 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) 376 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_libevent_unittest.cc ('k') | base/tools_sanity_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698