OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 ASSERT_DEATH({ | 1085 ASSERT_DEATH({ |
1086 SetUpInDeathAssert(); | 1086 SetUpInDeathAssert(); |
1087 value_ = g_try_malloc(test_size_); | 1087 value_ = g_try_malloc(test_size_); |
1088 }, ""); | 1088 }, ""); |
1089 } | 1089 } |
1090 #endif // OS_LINUX | 1090 #endif // OS_LINUX |
1091 | 1091 |
1092 // Android doesn't implement posix_memalign(). | 1092 // Android doesn't implement posix_memalign(). |
1093 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 1093 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
1094 TEST_F(OutOfMemoryDeathTest, Posix_memalign) { | 1094 TEST_F(OutOfMemoryDeathTest, Posix_memalign) { |
1095 typedef int (*memalign_t)(void **, size_t, size_t); | 1095 // Grab the return value of posix_memalign to silence a compiler warning |
1096 #if defined(OS_MACOSX) | 1096 // about unused return values. We don't actually care about the return |
1097 // posix_memalign only exists on >= 10.6. Use dlsym to grab it at runtime | 1097 // value, since we're asserting death. |
1098 // because it may not be present in the SDK used for compilation. | 1098 ASSERT_DEATH({ |
1099 memalign_t memalign = | 1099 SetUpInDeathAssert(); |
1100 reinterpret_cast<memalign_t>(dlsym(RTLD_DEFAULT, "posix_memalign")); | 1100 EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)); |
1101 #else | 1101 }, ""); |
1102 memalign_t memalign = posix_memalign; | |
1103 #endif // defined(OS_MACOSX) | |
1104 if (memalign) { | |
1105 // Grab the return value of posix_memalign to silence a compiler warning | |
1106 // about unused return values. We don't actually care about the return | |
1107 // value, since we're asserting death. | |
1108 ASSERT_DEATH({ | |
1109 SetUpInDeathAssert(); | |
1110 EXPECT_EQ(ENOMEM, memalign(&value_, 8, test_size_)); | |
1111 }, ""); | |
1112 } | |
1113 } | 1102 } |
1114 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 1103 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
1115 | 1104 |
1116 #if defined(OS_MACOSX) | 1105 #if defined(OS_MACOSX) |
1117 | 1106 |
1118 // Purgeable zone tests (if it exists) | 1107 // Purgeable zone tests |
1119 | 1108 |
1120 TEST_F(OutOfMemoryDeathTest, MallocPurgeable) { | 1109 TEST_F(OutOfMemoryDeathTest, MallocPurgeable) { |
1121 malloc_zone_t* zone = base::GetPurgeableZone(); | 1110 malloc_zone_t* zone = malloc_default_purgeable_zone(); |
1122 if (zone) | 1111 ASSERT_DEATH({ |
1123 ASSERT_DEATH({ | 1112 SetUpInDeathAssert(); |
1124 SetUpInDeathAssert(); | 1113 value_ = malloc_zone_malloc(zone, test_size_); |
1125 value_ = malloc_zone_malloc(zone, test_size_); | 1114 }, ""); |
1126 }, ""); | |
1127 } | 1115 } |
1128 | 1116 |
1129 TEST_F(OutOfMemoryDeathTest, ReallocPurgeable) { | 1117 TEST_F(OutOfMemoryDeathTest, ReallocPurgeable) { |
1130 malloc_zone_t* zone = base::GetPurgeableZone(); | 1118 malloc_zone_t* zone = malloc_default_purgeable_zone(); |
1131 if (zone) | 1119 ASSERT_DEATH({ |
1132 ASSERT_DEATH({ | 1120 SetUpInDeathAssert(); |
1133 SetUpInDeathAssert(); | 1121 value_ = malloc_zone_realloc(zone, NULL, test_size_); |
1134 value_ = malloc_zone_realloc(zone, NULL, test_size_); | 1122 }, ""); |
1135 }, ""); | |
1136 } | 1123 } |
1137 | 1124 |
1138 TEST_F(OutOfMemoryDeathTest, CallocPurgeable) { | 1125 TEST_F(OutOfMemoryDeathTest, CallocPurgeable) { |
1139 malloc_zone_t* zone = base::GetPurgeableZone(); | 1126 malloc_zone_t* zone = malloc_default_purgeable_zone(); |
1140 if (zone) | 1127 ASSERT_DEATH({ |
1141 ASSERT_DEATH({ | 1128 SetUpInDeathAssert(); |
1142 SetUpInDeathAssert(); | 1129 value_ = malloc_zone_calloc(zone, 1024, test_size_ / 1024L); |
1143 value_ = malloc_zone_calloc(zone, 1024, test_size_ / 1024L); | 1130 }, ""); |
1144 }, ""); | |
1145 } | 1131 } |
1146 | 1132 |
1147 TEST_F(OutOfMemoryDeathTest, VallocPurgeable) { | 1133 TEST_F(OutOfMemoryDeathTest, VallocPurgeable) { |
1148 malloc_zone_t* zone = base::GetPurgeableZone(); | 1134 malloc_zone_t* zone = malloc_default_purgeable_zone(); |
1149 if (zone) | 1135 ASSERT_DEATH({ |
1150 ASSERT_DEATH({ | 1136 SetUpInDeathAssert(); |
1151 SetUpInDeathAssert(); | 1137 value_ = malloc_zone_valloc(zone, test_size_); |
1152 value_ = malloc_zone_valloc(zone, test_size_); | 1138 }, ""); |
1153 }, ""); | |
1154 } | 1139 } |
1155 | 1140 |
1156 TEST_F(OutOfMemoryDeathTest, PosixMemalignPurgeable) { | 1141 TEST_F(OutOfMemoryDeathTest, PosixMemalignPurgeable) { |
1157 malloc_zone_t* zone = base::GetPurgeableZone(); | 1142 malloc_zone_t* zone = malloc_default_purgeable_zone(); |
1158 | 1143 ASSERT_DEATH({ |
1159 typedef void* (*zone_memalign_t)(malloc_zone_t*, size_t, size_t); | 1144 SetUpInDeathAssert(); |
1160 // malloc_zone_memalign only exists on >= 10.6. Use dlsym to grab it at | 1145 value_ = malloc_zone_memalign(zone, 8, test_size_); |
1161 // runtime because it may not be present in the SDK used for compilation. | 1146 }, ""); |
1162 zone_memalign_t zone_memalign = | |
1163 reinterpret_cast<zone_memalign_t>( | |
1164 dlsym(RTLD_DEFAULT, "malloc_zone_memalign")); | |
1165 | |
1166 if (zone && zone_memalign) { | |
1167 ASSERT_DEATH({ | |
1168 SetUpInDeathAssert(); | |
1169 value_ = zone_memalign(zone, 8, test_size_); | |
1170 }, ""); | |
1171 } | |
1172 } | 1147 } |
1173 | 1148 |
1174 // Since these allocation functions take a signed size, it's possible that | 1149 // Since these allocation functions take a signed size, it's possible that |
1175 // calling them just once won't be enough to exhaust memory. In the 32-bit | 1150 // calling them just once won't be enough to exhaust memory. In the 32-bit |
1176 // environment, it's likely that these allocation attempts will fail because | 1151 // environment, it's likely that these allocation attempts will fail because |
1177 // not enough contiguous address space is available. In the 64-bit environment, | 1152 // not enough contiguous address space is available. In the 64-bit environment, |
1178 // it's likely that they'll fail because they would require a preposterous | 1153 // it's likely that they'll fail because they would require a preposterous |
1179 // amount of (virtual) memory. | 1154 // amount of (virtual) memory. |
1180 | 1155 |
1181 TEST_F(OutOfMemoryDeathTest, CFAllocatorSystemDefault) { | 1156 TEST_F(OutOfMemoryDeathTest, CFAllocatorSystemDefault) { |
(...skipping 30 matching lines...) Expand all Loading... |
1212 SetUpInDeathAssert(); | 1187 SetUpInDeathAssert(); |
1213 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1188 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
1214 }, ""); | 1189 }, ""); |
1215 } | 1190 } |
1216 | 1191 |
1217 #endif // !ARCH_CPU_64_BITS | 1192 #endif // !ARCH_CPU_64_BITS |
1218 #endif // OS_MACOSX | 1193 #endif // OS_MACOSX |
1219 | 1194 |
1220 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1195 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
1221 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1196 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
OLD | NEW |