OLD | NEW |
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/debug/alias.h" |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 536 |
537 // For the following Mac tests: | 537 // For the following Mac tests: |
538 // Note that base::EnableTerminationOnHeapCorruption() is called as part of | 538 // Note that base::EnableTerminationOnHeapCorruption() is called as part of |
539 // test suite setup and does not need to be done again, else mach_override | 539 // test suite setup and does not need to be done again, else mach_override |
540 // will fail. | 540 // will fail. |
541 | 541 |
542 #if !defined(ADDRESS_SANITIZER) | 542 #if !defined(ADDRESS_SANITIZER) |
543 // The following code tests the system implementation of malloc() thus no need | 543 // The following code tests the system implementation of malloc() thus no need |
544 // to test it under AddressSanitizer. | 544 // to test it under AddressSanitizer. |
545 TEST_F(ProcessUtilTest, MacMallocFailureDoesNotTerminate) { | 545 TEST_F(ProcessUtilTest, MacMallocFailureDoesNotTerminate) { |
546 // Install the OOM killer. | |
547 base::EnableTerminationOnOutOfMemory(); | |
548 | |
549 // Test that ENOMEM doesn't crash via CrMallocErrorBreak two ways: the exit | 546 // Test that ENOMEM doesn't crash via CrMallocErrorBreak two ways: the exit |
550 // code and lack of the error string. The number of bytes is one less than | 547 // code and lack of the error string. The number of bytes is one less than |
551 // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns NULL and | 548 // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns NULL and |
552 // does not call through malloc_error_break(). See the comment at | 549 // does not call through malloc_error_break(). See the comment at |
553 // EnableTerminationOnOutOfMemory() for more information. | 550 // EnableTerminationOnOutOfMemory() for more information. |
554 void* buf = NULL; | 551 void* buf = NULL; |
555 ASSERT_EXIT( | 552 ASSERT_EXIT( |
556 buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1), | 553 { |
| 554 base::EnableTerminationOnOutOfMemory(); |
| 555 |
| 556 buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1); |
| 557 }, |
557 testing::KilledBySignal(SIGTRAP), | 558 testing::KilledBySignal(SIGTRAP), |
558 "\\*\\*\\* error: can't allocate region.*" | 559 "\\*\\*\\* error: can't allocate region.*" |
559 "(Terminating process due to a potential for future heap " | 560 "(Terminating process due to a potential for future heap " |
560 "corruption){0}"); | 561 "corruption){0}"); |
561 | 562 |
562 base::debug::Alias(buf); | 563 base::debug::Alias(buf); |
563 } | 564 } |
564 #endif // !defined(ADDRESS_SANITIZER) | 565 #endif // !defined(ADDRESS_SANITIZER) |
565 | 566 |
566 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { | 567 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 SetUpInDeathAssert(); | 1283 SetUpInDeathAssert(); |
1283 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1284 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
1284 }, ""); | 1285 }, ""); |
1285 } | 1286 } |
1286 | 1287 |
1287 #endif // !ARCH_CPU_64_BITS | 1288 #endif // !ARCH_CPU_64_BITS |
1288 #endif // OS_MACOSX | 1289 #endif // OS_MACOSX |
1289 | 1290 |
1290 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1291 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
1291 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1292 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
OLD | NEW |