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 #include <stddef.h> |
4 #include <stdio.h> | 5 #include <stdio.h> |
5 #include "base/allocator/allocator_shim.h" | |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 // TCMalloc header files | 9 // TCMalloc header files. |
10 #include "common.h" // For TCMalloc constants like page size, etc. | 10 #include "common.h" // For TCMalloc constants like page size, etc. |
11 | 11 |
12 using base::allocator::TCMallocDoMallocForTest; | 12 // TCMalloc implementation. |
13 using base::allocator::TCMallocDoFreeForTest; | 13 #include "debugallocation_shim.cc" |
14 using base::allocator::ExcludeSpaceForMarkForTest; | 14 |
| 15 namespace { |
| 16 |
| 17 void* TCMallocDoMallocForTest(size_t size) { |
| 18 return do_malloc(size); |
| 19 } |
| 20 |
| 21 void TCMallocDoFreeForTest(void* ptr) { |
| 22 do_free(ptr); |
| 23 } |
| 24 |
| 25 size_t ExcludeSpaceForMarkForTest(size_t size) { |
| 26 return ExcludeSpaceForMark(size); |
| 27 } |
| 28 |
| 29 } // namespace |
15 | 30 |
16 TEST(TCMallocFreeCheck, BadPointerInFirstPageOfTheLargeObject) { | 31 TEST(TCMallocFreeCheck, BadPointerInFirstPageOfTheLargeObject) { |
17 char* p = reinterpret_cast<char*>( | 32 char* p = reinterpret_cast<char*>( |
18 TCMallocDoMallocForTest(ExcludeSpaceForMarkForTest(kMaxSize + 1))); | 33 TCMallocDoMallocForTest(ExcludeSpaceForMarkForTest(kMaxSize + 1))); |
19 for (int offset = 1; offset < kPageSize ; offset <<= 1) { | 34 for (int offset = 1; offset < kPageSize ; offset <<= 1) { |
20 ASSERT_DEATH(TCMallocDoFreeForTest(p + offset), | 35 ASSERT_DEATH(TCMallocDoFreeForTest(p + offset), |
21 "Pointer is not pointing to the start of a span"); | 36 "Pointer is not pointing to the start of a span"); |
22 } | 37 } |
23 } | 38 } |
24 | 39 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 ASSERT_DEATH(TCMallocDoFreeForTest(p); TCMallocDoFreeForTest(p), | 87 ASSERT_DEATH(TCMallocDoFreeForTest(p); TCMallocDoFreeForTest(p), |
73 "Attempt to double free"); | 88 "Attempt to double free"); |
74 } | 89 } |
75 } | 90 } |
76 #endif | 91 #endif |
77 | 92 |
78 int main(int argc, char **argv) { | 93 int main(int argc, char **argv) { |
79 testing::InitGoogleTest(&argc, argv); | 94 testing::InitGoogleTest(&argc, argv); |
80 return RUN_ALL_TESTS(); | 95 return RUN_ALL_TESTS(); |
81 } | 96 } |
OLD | NEW |