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

Side by Side Diff: base/process_util_unittest.cc

Issue 9597031: In CrMallocErrorBreak, do not kill the process if errno is ENOMEM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « base/process_util_mac.mm ('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) 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 <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h"
10 #include "base/eintr_wrapper.h" 11 #include "base/eintr_wrapper.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/process_util.h" 16 #include "base/process_util.h"
16 #include "base/test/multiprocess_test.h" 17 #include "base/test/multiprocess_test.h"
17 #include "base/test/test_timeouts.h" 18 #include "base/test/test_timeouts.h"
18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
19 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
20 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "testing/multiprocess_func_list.h" 23 #include "testing/multiprocess_func_list.h"
23 24
24 #if defined(OS_LINUX) 25 #if defined(OS_LINUX)
25 #include <errno.h>
26 #include <malloc.h> 26 #include <malloc.h>
27 #include <glib.h> 27 #include <glib.h>
28 #include <sched.h> 28 #include <sched.h>
29 #endif 29 #endif
30 #if defined(OS_POSIX) 30 #if defined(OS_POSIX)
31 #include <errno.h>
31 #include <dlfcn.h> 32 #include <dlfcn.h>
32 #include <fcntl.h> 33 #include <fcntl.h>
33 #include <signal.h> 34 #include <signal.h>
34 #include <sys/resource.h> 35 #include <sys/resource.h>
35 #include <sys/socket.h> 36 #include <sys/socket.h>
36 #include <sys/wait.h> 37 #include <sys/wait.h>
37 #endif 38 #endif
38 #if defined(OS_WIN) 39 #if defined(OS_WIN)
39 #include <windows.h> 40 #include <windows.h>
40 #endif 41 #endif
41 #if defined(OS_MACOSX) 42 #if defined(OS_MACOSX)
43 #include <mach/vm_param.h>
42 #include <malloc/malloc.h> 44 #include <malloc/malloc.h>
43 #include "base/process_util_unittest_mac.h" 45 #include "base/process_util_unittest_mac.h"
44 #endif 46 #endif
45 47
46 namespace { 48 namespace {
47 49
48 #if defined(OS_WIN) 50 #if defined(OS_WIN)
49 const wchar_t kProcessName[] = L"base_unittests.exe"; 51 const wchar_t kProcessName[] = L"base_unittests.exe";
50 #else 52 #else
51 const wchar_t kProcessName[] = L"base_unittests"; 53 const wchar_t kProcessName[] = L"base_unittests";
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 this->MakeCmdLine("SimpleChildProcess", false).GetCommandLineString(); 444 this->MakeCmdLine("SimpleChildProcess", false).GetCommandLineString();
443 base::LaunchOptions options; 445 base::LaunchOptions options;
444 options.as_user = token; 446 options.as_user = token;
445 EXPECT_TRUE(base::LaunchProcess(cmdline, options, NULL)); 447 EXPECT_TRUE(base::LaunchProcess(cmdline, options, NULL));
446 } 448 }
447 449
448 #endif // defined(OS_WIN) 450 #endif // defined(OS_WIN)
449 451
450 #if defined(OS_MACOSX) 452 #if defined(OS_MACOSX)
451 453
454 // For the following Mac tests:
455 // Note that base::EnableTerminationOnHeapCorruption() is called as part of
456 // test suite setup and does not need to be done again, else mach_override
457 // will fail.
458
459 TEST_F(ProcessUtilTest, MacMallocFailureDoesNotTerminate) {
460 // Test that ENOMEM doesn't crash. The number of bytes is one less than
461 // MALLOC_ABSOLUTE_MAX_SIZE, above which the system early-returns NULL and
462 // does not call through malloc_error_break(). See the comment at
463 // EnableTerminationOnOutOfMemory() for more information.
464 void* buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1);
465
466 // The optimizer can be too efficient in Release mode, so alias the value.
467 base::debug::Alias(buf);
468
469 EXPECT_FALSE(buf);
470 EXPECT_EQ(ENOMEM, errno);
471 }
472
452 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { 473 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) {
453 // Note that base::EnableTerminationOnHeapCorruption() is called as part of 474 // Assert that freeing an unallocated pointer will crash the process.
454 // test suite setup and does not need to be done again, else mach_override
455 // will fail.
456
457 char buf[3]; 475 char buf[3];
458 #ifndef ADDRESS_SANITIZER 476 #ifndef ADDRESS_SANITIZER
459 ASSERT_DEATH(free(buf), "being freed.*" 477 ASSERT_DEATH(free(buf), "being freed.*"
460 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*" 478 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*"
461 "Terminating process due to a potential for future heap corruption"); 479 "Terminating process due to a potential for future heap corruption");
462 #else 480 #else
463 // AddressSanitizer replaces malloc() and prints a different error message on 481 // AddressSanitizer replaces malloc() and prints a different error message on
464 // heap corruption. 482 // heap corruption.
465 ASSERT_DEATH(free(buf), "attempting free on address which " 483 ASSERT_DEATH(free(buf), "attempting free on address which "
466 "was not malloc\\(\\)-ed"); 484 "was not malloc\\(\\)-ed");
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 SetUpInDeathAssert(); 1175 SetUpInDeathAssert();
1158 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} 1176 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {}
1159 }, ""); 1177 }, "");
1160 } 1178 }
1161 1179
1162 #endif // !ARCH_CPU_64_BITS 1180 #endif // !ARCH_CPU_64_BITS
1163 #endif // OS_MACOSX 1181 #endif // OS_MACOSX
1164 1182
1165 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && 1183 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) &&
1166 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) 1184 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
OLDNEW
« no previous file with comments | « base/process_util_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698