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

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

Issue 69953025: Support use_glib==0 on Linux in base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bring back EXPECT_EQ as it suppresses unused result warning Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/file_util_posix.cc ('k') | base/process/process_util_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
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 "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 #if defined(OS_WIN) 16 #if defined(OS_WIN)
16 #include <windows.h> 17 #include <windows.h>
17 #endif 18 #endif
18 #if defined(OS_POSIX) 19 #if defined(OS_POSIX)
19 #include <errno.h> 20 #include <errno.h>
20 #endif 21 #endif
21 #if defined(OS_MACOSX) 22 #if defined(OS_MACOSX)
22 #include <malloc/malloc.h> 23 #include <malloc/malloc.h>
23 #include "base/process/memory_unittest_mac.h" 24 #include "base/process/memory_unittest_mac.h"
24 #endif 25 #endif
25 #if defined(OS_LINUX) 26 #if defined(OS_LINUX)
26 #include <glib.h>
27 #include <malloc.h> 27 #include <malloc.h>
28 #endif 28 #endif
29 29
30 #if defined(OS_WIN) 30 #if defined(OS_WIN)
31 // HeapQueryInformation function pointer. 31 // HeapQueryInformation function pointer.
32 typedef BOOL (WINAPI* HeapQueryFn) \ 32 typedef BOOL (WINAPI* HeapQueryFn) \
33 (HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T); 33 (HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T);
34 34
35 const int kConstantInModule = 42; 35 const int kConstantInModule = 42;
36 36
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 253 }
254 254
255 TEST_F(OutOfMemoryDeathTest, Memalign) { 255 TEST_F(OutOfMemoryDeathTest, Memalign) {
256 ASSERT_DEATH({ 256 ASSERT_DEATH({
257 SetUpInDeathAssert(); 257 SetUpInDeathAssert();
258 value_ = memalign(4, test_size_); 258 value_ = memalign(4, test_size_);
259 }, ""); 259 }, "");
260 } 260 }
261 261
262 TEST_F(OutOfMemoryDeathTest, ViaSharedLibraries) { 262 TEST_F(OutOfMemoryDeathTest, ViaSharedLibraries) {
263 // g_try_malloc is documented to return NULL on failure. (g_malloc is the 263 // This tests that the run-time symbol resolution is overriding malloc for
264 // 'safe' default that crashes if allocation fails). However, since we have 264 // shared libraries (including libc itself) as well as for our code.
265 // hopefully overridden malloc, even g_try_malloc should fail. This tests 265 std::string format = base::StringPrintf("%%%zud", test_size_);
266 // that the run-time symbol resolution is overriding malloc for shared 266 char *value = NULL;
267 // libraries as well as for our code.
268 ASSERT_DEATH({ 267 ASSERT_DEATH({
269 SetUpInDeathAssert(); 268 SetUpInDeathAssert();
270 value_ = g_try_malloc(test_size_); 269 EXPECT_EQ(-1, asprintf(&value, format.c_str(), 0));
271 }, ""); 270 }, "");
272 } 271 }
273 #endif // OS_LINUX 272 #endif // OS_LINUX
274 273
275 // Android doesn't implement posix_memalign(). 274 // Android doesn't implement posix_memalign().
276 #if defined(OS_POSIX) && !defined(OS_ANDROID) 275 #if defined(OS_POSIX) && !defined(OS_ANDROID)
277 TEST_F(OutOfMemoryDeathTest, Posix_memalign) { 276 TEST_F(OutOfMemoryDeathTest, Posix_memalign) {
278 // Grab the return value of posix_memalign to silence a compiler warning 277 // Grab the return value of posix_memalign to silence a compiler warning
279 // about unused return values. We don't actually care about the return 278 // about unused return values. We don't actually care about the return
280 // value, since we're asserting death. 279 // value, since we're asserting death.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 SetUpInDeathAssert(); 369 SetUpInDeathAssert();
371 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} 370 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {}
372 }, ""); 371 }, "");
373 } 372 }
374 373
375 #endif // !ARCH_CPU_64_BITS 374 #endif // !ARCH_CPU_64_BITS
376 #endif // OS_MACOSX 375 #endif // OS_MACOSX
377 376
378 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && 377 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) &&
379 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) 378 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698