summaryrefslogtreecommitdiffstats
path: root/base/process_util_unittest.cc
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 20:11:43 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 20:11:43 +0000
commit6cfa339931cfe22522d911f0b88603c8350a2135 (patch)
treece500004d9ddd42ca9a2bfef5f90ec25045d6169 /base/process_util_unittest.cc
parent1336223c987ab8e0730ed2283e6788e6c4d252ed (diff)
downloadchromium_src-6cfa339931cfe22522d911f0b88603c8350a2135.zip
chromium_src-6cfa339931cfe22522d911f0b88603c8350a2135.tar.gz
chromium_src-6cfa339931cfe22522d911f0b88603c8350a2135.tar.bz2
Catch OOMs in purgeable memory.
Recommit of r51371, this time not crashy. BUG=http://crbug.com/47980 TEST=unit tested Review URL: http://codereview.chromium.org/2817048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r--base/process_util_unittest.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 4a42342..481c759 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -31,6 +31,7 @@
#include <windows.h>
#endif
#if defined(OS_MACOSX)
+#include <malloc/malloc.h>
#include "base/process_util_unittest_mac.h"
#endif
@@ -647,6 +648,48 @@ TEST_F(OutOfMemoryTest, Posix_memalign) {
#if defined(OS_MACOSX)
+// Purgeable zone tests (if it exists)
+
+TEST_F(OutOfMemoryTest, MallocPurgeable) {
+ malloc_zone_t* zone = base::GetPurgeableZone();
+ if (zone)
+ ASSERT_DEATH(value_ = malloc_zone_malloc(zone, test_size_), "");
+}
+
+TEST_F(OutOfMemoryTest, ReallocPurgeable) {
+ malloc_zone_t* zone = base::GetPurgeableZone();
+ if (zone)
+ ASSERT_DEATH(value_ = malloc_zone_realloc(zone, NULL, test_size_), "");
+}
+
+TEST_F(OutOfMemoryTest, CallocPurgeable) {
+ malloc_zone_t* zone = base::GetPurgeableZone();
+ if (zone)
+ ASSERT_DEATH(value_ = malloc_zone_calloc(zone, 1024, test_size_ / 1024L),
+ "");
+}
+
+TEST_F(OutOfMemoryTest, VallocPurgeable) {
+ malloc_zone_t* zone = base::GetPurgeableZone();
+ if (zone)
+ ASSERT_DEATH(value_ = malloc_zone_valloc(zone, test_size_), "");
+}
+
+TEST_F(OutOfMemoryTest, PosixMemalignPurgeable) {
+ malloc_zone_t* zone = base::GetPurgeableZone();
+
+ typedef void* (*zone_memalign_t)(malloc_zone_t*, size_t, size_t);
+ // malloc_zone_memalign only exists on >= 10.6. Use dlsym to grab it at
+ // runtime because it may not be present in the SDK used for compilation.
+ zone_memalign_t zone_memalign =
+ reinterpret_cast<zone_memalign_t>(
+ dlsym(RTLD_DEFAULT, "malloc_zone_memalign"));
+
+ if (zone && zone_memalign) {
+ ASSERT_DEATH(value_ = zone_memalign(zone, 8, test_size_), "");
+ }
+}
+
// Since these allocation functions take a signed size, it's possible that
// calling them just once won't be enough to exhaust memory. In the 32-bit
// environment, it's likely that these allocation attempts will fail because