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 "base/process/memory.h" | 7 #include "base/process/memory.h" |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 public: | 175 public: |
176 OutOfMemoryTest() | 176 OutOfMemoryTest() |
177 : value_(NULL), | 177 : value_(NULL), |
178 // Make test size as large as possible minus a few pages so | 178 // Make test size as large as possible minus a few pages so |
179 // that alignment or other rounding doesn't make it wrap. | 179 // that alignment or other rounding doesn't make it wrap. |
180 test_size_(std::numeric_limits<std::size_t>::max() - 12 * 1024), | 180 test_size_(std::numeric_limits<std::size_t>::max() - 12 * 1024), |
181 signed_test_size_(std::numeric_limits<ssize_t>::max()) { | 181 signed_test_size_(std::numeric_limits<ssize_t>::max()) { |
182 } | 182 } |
183 | 183 |
184 #if defined(USE_TCMALLOC) | 184 #if defined(USE_TCMALLOC) |
185 virtual void SetUp() OVERRIDE { | 185 void SetUp() override { tc_set_new_mode(1); } |
186 tc_set_new_mode(1); | |
187 } | |
188 | 186 |
189 virtual void TearDown() OVERRIDE { | 187 void TearDown() override { tc_set_new_mode(0); } |
190 tc_set_new_mode(0); | |
191 } | |
192 #endif // defined(USE_TCMALLOC) | 188 #endif // defined(USE_TCMALLOC) |
193 | 189 |
194 protected: | 190 protected: |
195 void* value_; | 191 void* value_; |
196 size_t test_size_; | 192 size_t test_size_; |
197 ssize_t signed_test_size_; | 193 ssize_t signed_test_size_; |
198 }; | 194 }; |
199 | 195 |
200 class OutOfMemoryDeathTest : public OutOfMemoryTest { | 196 class OutOfMemoryDeathTest : public OutOfMemoryTest { |
201 public: | 197 public: |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 bytes = static_cast<const char*>(value_); | 438 bytes = static_cast<const char*>(value_); |
443 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) | 439 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) |
444 EXPECT_EQ(0, bytes[i]); | 440 EXPECT_EQ(0, bytes[i]); |
445 free(value_); | 441 free(value_); |
446 | 442 |
447 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); | 443 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); |
448 EXPECT_TRUE(value_ == NULL); | 444 EXPECT_TRUE(value_ == NULL); |
449 } | 445 } |
450 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 446 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
451 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) | 447 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) |
OLD | NEW |