diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 13:51:52 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 13:51:52 +0000 |
commit | 73a964f0facc033d3ff6d08616f06d16850b37c2 (patch) | |
tree | 68eed96fda585e9d603f6c27351dad9767ed64ac /base/process_util_unittest.cc | |
parent | 25f1cae9d3c9e2fb29ea0546ca8adda710818bd3 (diff) | |
download | chromium_src-73a964f0facc033d3ff6d08616f06d16850b37c2.zip chromium_src-73a964f0facc033d3ff6d08616f06d16850b37c2.tar.gz chromium_src-73a964f0facc033d3ff6d08616f06d16850b37c2.tar.bz2 |
Die on an OOM situation in many more cases.
BUG=http://crbug.com/12673
TEST=run out of memory and die
Review URL: http://codereview.chromium.org/875004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41834 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 7b9a7af..296aaa9 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -29,6 +29,9 @@ #if defined(OS_WIN) #include <windows.h> #endif +#if defined(OS_MACOSX) +#include "base/process_util_unittest_mac.h" +#endif namespace base { @@ -506,8 +509,8 @@ TEST_F(ProcessUtilTest, ParseProcStatCPU) { #endif // defined(OS_POSIX) -// TODO(vandebo) make this work on Windows and Mac too. -#if defined(OS_LINUX) +// TODO(vandebo) make this work on Windows too. +#if !defined(OS_WIN) #if defined(USE_TCMALLOC) extern "C" { @@ -521,7 +524,8 @@ class OutOfMemoryTest : public testing::Test { : value_(NULL), // Make test size as large as possible minus a few pages so // that alignment or other rounding doesn't make it wrap. - test_size_(std::numeric_limits<std::size_t>::max() - 8192) { + test_size_(std::numeric_limits<std::size_t>::max() - 12 * 1024), + signed_test_size_(std::numeric_limits<ssize_t>::max()) { } virtual void SetUp() { @@ -539,9 +543,14 @@ class OutOfMemoryTest : public testing::Test { void* value_; size_t test_size_; + ssize_t signed_test_size_; }; TEST_F(OutOfMemoryTest, New) { + ASSERT_DEATH(value_ = operator new(test_size_), ""); +} + +TEST_F(OutOfMemoryTest, NewArray) { ASSERT_DEATH(value_ = new char[test_size_], ""); } @@ -561,6 +570,7 @@ TEST_F(OutOfMemoryTest, Valloc) { ASSERT_DEATH(value_ = valloc(test_size_), ""); } +#if defined(OS_LINUX) TEST_F(OutOfMemoryTest, Pvalloc) { ASSERT_DEATH(value_ = pvalloc(test_size_), ""); } @@ -585,7 +595,35 @@ TEST_F(OutOfMemoryTest, Posix_memalign) { // value, since we're asserting death. ASSERT_DEATH(EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)), ""); } +#endif // OS_LINUX + +#if defined(OS_MACOSX) + +// Since these allocation functions take a signed size, it's possible that +// calling them just once won't be enough to exhaust memory. + +TEST_F(OutOfMemoryTest, CFAllocatorSystemDefault) { + ASSERT_DEATH(while ((value_ = + AllocateViaCFAllocatorSystemDefault(signed_test_size_))) {}, ""); +} + +TEST_F(OutOfMemoryTest, CFAllocatorMalloc) { + ASSERT_DEATH(while ((value_ = + AllocateViaCFAllocatorMalloc(signed_test_size_))) {}, ""); +} + +TEST_F(OutOfMemoryTest, CFAllocatorMallocZone) { + ASSERT_DEATH(while ((value_ = + AllocateViaCFAllocatorMallocZone(signed_test_size_))) {}, ""); +} + +TEST_F(OutOfMemoryTest, PsychoticallyBigObjCObject) { + ASSERT_DEATH(while ((value_ = + AllocatePsychoticallyBigObjCObject())) {}, ""); +} + +#endif // OS_MACOSX -#endif // defined(OS_LINUX) +#endif // !defined(OS_WIN) } // namespace base |