Index: base/memory/discardable_memory_unittest.cc |
diff --git a/base/memory/discardable_memory_unittest.cc b/base/memory/discardable_memory_unittest.cc |
index eb730f19f18e8482fde972598c99378f2c30447a..96f5a89e0e747f92757619540702487550c5870c 100644 |
--- a/base/memory/discardable_memory_unittest.cc |
+++ b/base/memory/discardable_memory_unittest.cc |
@@ -3,12 +3,32 @@ |
// found in the LICENSE file. |
#include "base/memory/discardable_memory.h" |
+ |
+#include <limits> |
reveman
2013/12/10 16:25:46
#if defined(OS_ANDROID) to only include what you n
|
+ |
#include "testing/gtest/include/gtest/gtest.h" |
namespace base { |
const size_t kSize = 1024; |
+#if defined(OS_ANDROID) |
+// TODO(pliard): enable this on all platforms. This currently fails when |
Philippe
2013/12/10 15:18:38
FYI, I'm not proud of doing this but I want to get
reveman
2013/12/10 15:56:32
I don't think we should have a test that pass a hu
Philippe
2013/12/10 16:00:28
Yeah, agreed. I need to keep it here ideally on An
Philippe
2013/12/10 16:15:07
I would be ok with moving it to the allocator unit
reveman
2013/12/10 16:25:46
I'm fine with an ANDROID ifdef for now.
I think t
Philippe
2013/12/10 16:38:43
Done, thanks.
|
+// malloc() is used (by discardable memory emulation) with ASAN due to ASAN |
+// asserting that malloc() doesn't return NULL. |
+TEST(DiscardableMemoryTest, TooLargeAllocationFails) { |
+ const size_t kPageSize = 4096; |
+ const size_t max_allowed_allocation_size = |
+ std::numeric_limits<size_t>::max() - kPageSize + 1; |
+ scoped_ptr<DiscardableMemory> memory( |
+ DiscardableMemory::CreateLockedMemory(max_allowed_allocation_size + 1)); |
+ // On certain platforms (e.g. Android), page-alignment would have caused an |
+ // overflow resulting in a small allocation if the input size wasn't checked |
+ // correctly. |
+ ASSERT_FALSE(memory); |
+} |
+#endif |
+ |
TEST(DiscardableMemoryTest, SupportedNatively) { |
#if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) |
ASSERT_TRUE(DiscardableMemory::SupportedNatively()); |