OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/multiprocess_test.h" | 12 #include "base/multiprocess_test.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/platform_thread.h" | 14 #include "base/platform_thread.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 #if defined(OS_LINUX) | 19 #if defined(OS_LINUX) |
20 #include <dlfcn.h> | |
21 #include <errno.h> | 20 #include <errno.h> |
22 #include <malloc.h> | 21 #include <malloc.h> |
23 #include <glib.h> | 22 #include <glib.h> |
24 #endif | 23 #endif |
25 #if defined(OS_POSIX) | 24 #if defined(OS_POSIX) |
| 25 #include <dlfcn.h> |
26 #include <fcntl.h> | 26 #include <fcntl.h> |
27 #include <sys/resource.h> | 27 #include <sys/resource.h> |
28 #include <sys/socket.h> | 28 #include <sys/socket.h> |
29 #endif | 29 #endif |
30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
31 #include <windows.h> | 31 #include <windows.h> |
32 #endif | 32 #endif |
33 #if defined(OS_MACOSX) | 33 #if defined(OS_MACOSX) |
34 #include "base/process_util_unittest_mac.h" | 34 #include "base/process_util_unittest_mac.h" |
35 #endif | 35 #endif |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 } | 610 } |
611 | 611 |
612 TEST_F(OutOfMemoryTest, ViaSharedLibraries) { | 612 TEST_F(OutOfMemoryTest, ViaSharedLibraries) { |
613 // g_try_malloc is documented to return NULL on failure. (g_malloc is the | 613 // g_try_malloc is documented to return NULL on failure. (g_malloc is the |
614 // 'safe' default that crashes if allocation fails). However, since we have | 614 // 'safe' default that crashes if allocation fails). However, since we have |
615 // hopefully overridden malloc, even g_try_malloc should fail. This tests | 615 // hopefully overridden malloc, even g_try_malloc should fail. This tests |
616 // that the run-time symbol resolution is overriding malloc for shared | 616 // that the run-time symbol resolution is overriding malloc for shared |
617 // libraries as well as for our code. | 617 // libraries as well as for our code. |
618 ASSERT_DEATH(value_ = g_try_malloc(test_size_), ""); | 618 ASSERT_DEATH(value_ = g_try_malloc(test_size_), ""); |
619 } | 619 } |
| 620 #endif // OS_LINUX |
620 | 621 |
621 | 622 #if defined(OS_POSIX) |
622 TEST_F(OutOfMemoryTest, Posix_memalign) { | 623 TEST_F(OutOfMemoryTest, Posix_memalign) { |
623 // Grab the return value of posix_memalign to silence a compiler warning | 624 typedef int (*memalign_t)(void **, size_t, size_t); |
624 // about unused return values. We don't actually care about the return | 625 #if defined(OS_MACOSX) |
625 // value, since we're asserting death. | 626 // posix_memalign only exists on >= 10.6. Use dlsym to grab it at runtime |
626 ASSERT_DEATH(EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)), ""); | 627 // because it may not be present in the SDK used for compilation. |
| 628 memalign_t memalign = |
| 629 reinterpret_cast<memalign_t>(dlsym(RTLD_DEFAULT, "posix_memalign")); |
| 630 #else |
| 631 memalign_t memalign = posix_memalign; |
| 632 #endif // OS_* |
| 633 if (memalign) { |
| 634 // Grab the return value of posix_memalign to silence a compiler warning |
| 635 // about unused return values. We don't actually care about the return |
| 636 // value, since we're asserting death. |
| 637 ASSERT_DEATH(EXPECT_EQ(ENOMEM, memalign(&value_, 8, test_size_)), ""); |
| 638 } |
627 } | 639 } |
628 #endif // OS_LINUX | 640 #endif // OS_POSIX |
629 | 641 |
630 #if defined(OS_MACOSX) | 642 #if defined(OS_MACOSX) |
631 | 643 |
632 // Since these allocation functions take a signed size, it's possible that | 644 // Since these allocation functions take a signed size, it's possible that |
633 // calling them just once won't be enough to exhaust memory. In the 32-bit | 645 // calling them just once won't be enough to exhaust memory. In the 32-bit |
634 // environment, it's likely that these allocation attempts will fail because | 646 // environment, it's likely that these allocation attempts will fail because |
635 // not enough contiguous address space is availble. In the 64-bit environment, | 647 // not enough contiguous address space is availble. In the 64-bit environment, |
636 // it's likely that they'll fail because they would require a preposterous | 648 // it's likely that they'll fail because they would require a preposterous |
637 // amount of (virtual) memory. | 649 // amount of (virtual) memory. |
638 | 650 |
(...skipping 19 matching lines...) Expand all Loading... |
658 | 670 |
659 TEST_F(OutOfMemoryTest, PsychoticallyBigObjCObject) { | 671 TEST_F(OutOfMemoryTest, PsychoticallyBigObjCObject) { |
660 ASSERT_DEATH(while ((value_ = | 672 ASSERT_DEATH(while ((value_ = |
661 base::AllocatePsychoticallyBigObjCObject())) {}, ""); | 673 base::AllocatePsychoticallyBigObjCObject())) {}, ""); |
662 } | 674 } |
663 | 675 |
664 #endif // !ARCH_CPU_64_BITS | 676 #endif // !ARCH_CPU_64_BITS |
665 #endif // OS_MACOSX | 677 #endif // OS_MACOSX |
666 | 678 |
667 #endif // !defined(OS_WIN) | 679 #endif // !defined(OS_WIN) |
OLD | NEW |