Chromium Code Reviews| Index: base/process/memory_unittest.cc |
| diff --git a/base/process/memory_unittest.cc b/base/process/memory_unittest.cc |
| index 5a1bcdfb1ba4d1bb195092b5d9889128dad06a1c..9a1c38c51168070eae41747c505fd0d3657e7738 100644 |
| --- a/base/process/memory_unittest.cc |
| +++ b/base/process/memory_unittest.cc |
| @@ -149,17 +149,6 @@ TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { |
| #endif // defined(OS_MACOSX) |
| -// Android doesn't implement set_new_handler, so we can't use the |
| -// OutOfMemoryTest cases. |
| -// OpenBSD does not support these tests either. |
| -// AddressSanitizer and ThreadSanitizer define the malloc()/free()/etc. |
| -// functions so that they don't crash if the program is out of memory, so the |
| -// OOM tests aren't supposed to work. |
| -// TODO(vandebo) make this work on Windows too. |
| -#if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && \ |
| - !defined(OS_WIN) && \ |
| - !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) |
| - |
| #if defined(USE_TCMALLOC) |
| extern "C" { |
| int tc_set_new_mode(int mode); |
| @@ -200,6 +189,17 @@ class OutOfMemoryDeathTest : public testing::Test { |
| ssize_t signed_test_size_; |
| }; |
| +// Android doesn't implement set_new_handler, so we can't use the |
| +// OutOfMemoryTest cases. |
| +// OpenBSD does not support these tests either. |
| +// AddressSanitizer and ThreadSanitizer define the malloc()/free()/etc. |
| +// functions so that they don't crash if the program is out of memory, so the |
| +// OOM tests aren't supposed to work. |
| +// TODO(vandebo) make this work on Windows too. |
| +#if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && \ |
| + !defined(OS_WIN) && \ |
| + !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) |
| + |
| TEST_F(OutOfMemoryDeathTest, New) { |
| ASSERT_DEATH({ |
| SetUpInDeathAssert(); |
| @@ -377,3 +377,29 @@ TEST_F(OutOfMemoryDeathTest, PsychoticallyBigObjCObject) { |
| #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
| // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
| + |
| +// TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work |
| +// well on Windows. |
| +#if defined(USE_TCMALLOC) || defined(LIBC_GLIBC) |
| + |
| +TEST_F(OutOfMemoryDeathTest, UncheckedMalloc) { |
| + SetUpInDeathAssert(); |
|
Scott Hess - ex-Googler
2014/03/13 22:30:33
This shouldn't be a death test, right?
kbalazs
2014/03/13 23:07:00
No I just tried to reuse the class because I need
Scott Hess - ex-Googler
2014/03/13 23:18:45
Yeah, I think "death test" has meaning that you do
kbalazs
2014/03/18 20:03:54
I factored the common code into a base class.
|
| + EXPECT_TRUE(base::UncheckedMalloc(512, &value_)); |
| + EXPECT_TRUE(value_ != NULL); |
|
Scott Hess - ex-Googler
2014/03/13 22:30:33
When these succeed, you'll need to free value_.
kbalazs
2014/03/18 20:03:54
Done.
|
| + EXPECT_FALSE(base::UncheckedMalloc(test_size_, &value_)); |
| + EXPECT_TRUE(value_ == NULL); |
| +} |
| + |
| +TEST_F(OutOfMemoryDeathTest, UncheckedCalloc) { |
| + SetUpInDeathAssert(); |
|
Scott Hess - ex-Googler
2014/03/13 22:30:33
Also not a death test?
|
| + EXPECT_TRUE(base::UncheckedCalloc(1, 512, &value_)); |
| + EXPECT_TRUE(value_ != NULL); |
| + char zero[512]; |
| + memset(zero, 0, 512); |
| + EXPECT_EQ(memcmp(value_, zero, 512), 0); |
|
Scott Hess - ex-Googler
2014/03/13 22:30:33
I think prefer a kConstant to copies of 512.
I th
kbalazs
2014/03/18 20:03:54
Done.
|
| + |
| + EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); |
| + EXPECT_TRUE(value_ == NULL); |
| +} |
| + |
| +#endif |