Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / base / process / memory_unittest.cc
index f329fda..afbf5c6 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 #if defined(OS_MACOSX)
 #include <malloc/malloc.h>
+#include "base/mac/mac_util.h"
 #include "base/process/memory_unittest_mac.h"
 #endif
 #if defined(OS_LINUX)
@@ -108,6 +109,14 @@ TEST(ProcessMemoryTest, EnableLFH) {
 // The following code tests the system implementation of malloc() thus no need
 // to test it under AddressSanitizer.
 TEST(ProcessMemoryTest, MacMallocFailureDoesNotTerminate) {
+#if ARCH_CPU_32_BITS
+  // The Mavericks malloc library changed in a way which breaks the tricks used
+  // to implement EnableTerminationOnOutOfMemory() with UncheckedMalloc() under
+  // 32-bit.  Under 64-bit the oom_killer code handles this.
+  if (base::mac::IsOSMavericksOrLater())
+    return;
+#endif
+
   // Test that ENOMEM doesn't crash via CrMallocErrorBreak two ways: the exit
   // code and lack of the error string. The number of bytes is one less than
   // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns NULL and
@@ -152,13 +161,9 @@ TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
 // 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)
+    !defined(OS_WIN)
 
 #if defined(USE_TCMALLOC)
 extern "C" {
@@ -177,11 +182,11 @@ class OutOfMemoryTest : public testing::Test {
   }
 
 #if defined(USE_TCMALLOC)
-  virtual void SetUp() OVERRIDE {
+  virtual void SetUp() override {
     tc_set_new_mode(1);
   }
 
-  virtual void TearDown() OVERRIDE {
+  virtual void TearDown() override {
     tc_set_new_mode(0);
   }
 #endif  // defined(USE_TCMALLOC)
@@ -397,8 +402,17 @@ class OutOfMemoryHandledTest : public OutOfMemoryTest {
 
 // TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work
 // on Windows as well.
-
+// UncheckedMalloc() and UncheckedCalloc() work as regular malloc()/calloc()
+// under sanitizer tools.
+#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
 TEST_F(OutOfMemoryHandledTest, UncheckedMalloc) {
+#if defined(OS_MACOSX) && ARCH_CPU_32_BITS
+  // The Mavericks malloc library changed in a way which breaks the tricks used
+  // to implement EnableTerminationOnOutOfMemory() with UncheckedMalloc() under
+  // 32-bit.  The 64-bit malloc library works as desired without tricks.
+  if (base::mac::IsOSMavericksOrLater())
+    return;
+#endif
   EXPECT_TRUE(base::UncheckedMalloc(kSafeMallocSize, &value_));
   EXPECT_TRUE(value_ != NULL);
   free(value_);
@@ -408,6 +422,13 @@ TEST_F(OutOfMemoryHandledTest, UncheckedMalloc) {
 }
 
 TEST_F(OutOfMemoryHandledTest, UncheckedCalloc) {
+#if defined(OS_MACOSX) && ARCH_CPU_32_BITS
+  // The Mavericks malloc library changed in a way which breaks the tricks used
+  // to implement EnableTerminationOnOutOfMemory() with UncheckedCalloc() under
+  // 32-bit.  The 64-bit malloc library works as desired without tricks.
+  if (base::mac::IsOSMavericksOrLater())
+    return;
+#endif
   EXPECT_TRUE(base::UncheckedCalloc(1, kSafeMallocSize, &value_));
   EXPECT_TRUE(value_ != NULL);
   const char* bytes = static_cast<const char*>(value_);
@@ -426,6 +447,5 @@ TEST_F(OutOfMemoryHandledTest, UncheckedCalloc) {
   EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_));
   EXPECT_TRUE(value_ == NULL);
 }
-
-#endif  // !defined(OS_ANDROID) && !defined(OS_OPENBSD) &&
-        // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
+#endif  // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+#endif  // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN)