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

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

Issue 1064793002: Fix OutOfMemoryDeathTest.ViaSharedLibraries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed CL to avoid target enumeration on unsupported OS Created 5 years, 8 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/base_unittests.isolate ('k') | base/test/BUILD.gn » ('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
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include <windows.h> 17 #include <windows.h>
18 #endif 18 #endif
19 #if defined(OS_POSIX) 19 #if defined(OS_POSIX)
20 #include <errno.h> 20 #include <errno.h>
21 #endif 21 #endif
22 #if defined(OS_MACOSX) 22 #if defined(OS_MACOSX)
23 #include <malloc/malloc.h> 23 #include <malloc/malloc.h>
24 #include "base/mac/mac_util.h" 24 #include "base/mac/mac_util.h"
25 #include "base/process/memory_unittest_mac.h" 25 #include "base/process/memory_unittest_mac.h"
26 #endif 26 #endif
27 #if defined(OS_LINUX) 27 #if defined(OS_LINUX)
28 #include <malloc.h> 28 #include <malloc.h>
29 #include "base/test/malloc_wrapper.h"
29 #endif 30 #endif
30 31
31 #if defined(OS_WIN) 32 #if defined(OS_WIN)
32 // HeapQueryInformation function pointer. 33 // HeapQueryInformation function pointer.
33 typedef BOOL (WINAPI* HeapQueryFn) \ 34 typedef BOOL (WINAPI* HeapQueryFn) \
34 (HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T); 35 (HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T);
35 36
36 const int kConstantInModule = 42; 37 const int kConstantInModule = 42;
37 38
38 TEST(ProcessMemoryTest, GetModuleFromAddress) { 39 TEST(ProcessMemoryTest, GetModuleFromAddress) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 228
228 TEST_F(OutOfMemoryDeathTest, Memalign) { 229 TEST_F(OutOfMemoryDeathTest, Memalign) {
229 ASSERT_DEATH({ 230 ASSERT_DEATH({
230 SetUpInDeathAssert(); 231 SetUpInDeathAssert();
231 value_ = memalign(4, test_size_); 232 value_ = memalign(4, test_size_);
232 }, ""); 233 }, "");
233 } 234 }
234 235
235 TEST_F(OutOfMemoryDeathTest, ViaSharedLibraries) { 236 TEST_F(OutOfMemoryDeathTest, ViaSharedLibraries) {
236 // This tests that the run-time symbol resolution is overriding malloc for 237 // This tests that the run-time symbol resolution is overriding malloc for
237 // shared libraries (including libc itself) as well as for our code. 238 // shared libraries as well as for our code.
238 std::string format = base::StringPrintf("%%%zud", test_size_);
239 char *value = NULL;
240 ASSERT_DEATH({ 239 ASSERT_DEATH({
241 SetUpInDeathAssert(); 240 SetUpInDeathAssert();
242 EXPECT_EQ(-1, asprintf(&value, format.c_str(), 0)); 241 value_ = MallocWrapper(test_size_);
243 }, ""); 242 }, "");
244 } 243 }
245 #endif // OS_LINUX 244 #endif // OS_LINUX
246 245
247 // Android doesn't implement posix_memalign(). 246 // Android doesn't implement posix_memalign().
248 #if defined(OS_POSIX) && !defined(OS_ANDROID) 247 #if defined(OS_POSIX) && !defined(OS_ANDROID)
249 TEST_F(OutOfMemoryDeathTest, Posix_memalign) { 248 TEST_F(OutOfMemoryDeathTest, Posix_memalign) {
250 // Grab the return value of posix_memalign to silence a compiler warning 249 // Grab the return value of posix_memalign to silence a compiler warning
251 // about unused return values. We don't actually care about the return 250 // about unused return values. We don't actually care about the return
252 // value, since we're asserting death. 251 // value, since we're asserting death.
253 ASSERT_DEATH({ 252 ASSERT_DEATH({
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 bytes = static_cast<const char*>(value_); 404 bytes = static_cast<const char*>(value_);
406 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) 405 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i)
407 EXPECT_EQ(0, bytes[i]); 406 EXPECT_EQ(0, bytes[i]);
408 free(value_); 407 free(value_);
409 408
410 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); 409 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_));
411 EXPECT_TRUE(value_ == NULL); 410 EXPECT_TRUE(value_ == NULL);
412 } 411 }
413 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 412 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
414 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) 413 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN)
OLDNEW
« no previous file with comments | « base/base_unittests.isolate ('k') | base/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698