| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "base/trace_event/heap_profiler_allocation_register.h" | 5 #include "base/trace_event/heap_profiler_allocation_register.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/process/process_metrics.h" | 10 #include "base/process/process_metrics.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Lookup should not find any garbage after removal. | 238 // Lookup should not find any garbage after removal. |
| 239 EXPECT_FALSE(reg.Get(reinterpret_cast<void*>(23), &a)); | 239 EXPECT_FALSE(reg.Get(reinterpret_cast<void*>(23), &a)); |
| 240 | 240 |
| 241 reg.Remove(reinterpret_cast<void*>(17)); | 241 reg.Remove(reinterpret_cast<void*>(17)); |
| 242 reg.Remove(reinterpret_cast<void*>(19)); | 242 reg.Remove(reinterpret_cast<void*>(19)); |
| 243 | 243 |
| 244 EXPECT_FALSE(reg.Get(reinterpret_cast<void*>(17), &a)); | 244 EXPECT_FALSE(reg.Get(reinterpret_cast<void*>(17), &a)); |
| 245 EXPECT_FALSE(reg.Get(reinterpret_cast<void*>(19), &a)); | 245 EXPECT_FALSE(reg.Get(reinterpret_cast<void*>(19), &a)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // Check that the process aborts due to hitting the guard page when inserting | 248 // Check that the table handles overflows gracefully. |
| 249 // too many elements. | 249 TEST_F(AllocationRegisterTest, OverflowTest) { |
| 250 #if GTEST_HAS_DEATH_TEST | |
| 251 TEST_F(AllocationRegisterTest, OverflowDeathTest) { | |
| 252 const size_t allocation_capacity = GetAllocationCapacityPerPage(); | 250 const size_t allocation_capacity = GetAllocationCapacityPerPage(); |
| 253 AllocationRegister reg(allocation_capacity, kBacktraceCapacity); | 251 AllocationRegister reg(allocation_capacity, kBacktraceCapacity); |
| 254 AllocationContext ctx; | 252 AllocationContext ctx; |
| 255 size_t i; | 253 size_t i; |
| 256 | 254 |
| 257 // Fill up all of the memory allocated for the register's allocation map. | 255 // Fill up all of the memory allocated for the register's allocation map. |
| 258 for (i = 0; i < allocation_capacity; i++) { | 256 for (i = 0; i < allocation_capacity; i++) { |
| 259 reg.Insert(reinterpret_cast<void*>(i + 1), 1, ctx); | 257 reg.Insert(reinterpret_cast<void*>(i + 1), 1, ctx); |
| 260 } | 258 } |
| 261 | 259 |
| 262 // Adding just one extra element should cause overflow. | 260 // Adding just one extra element should cause overflow. |
| 263 ASSERT_DEATH(reg.Insert(reinterpret_cast<void*>(i + 1), 1, ctx), ""); | 261 ASSERT_FALSE(reg.Insert(reinterpret_cast<void*>(i + 1), 1, ctx)); |
| 264 } | 262 } |
| 265 #endif | |
| 266 | 263 |
| 267 } // namespace trace_event | 264 } // namespace trace_event |
| 268 } // namespace base | 265 } // namespace base |
| OLD | NEW |