OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 Google Inc. All Rights Reserved. | |
2 // Author: kaiwang@google.com (Kai Wang) | |
3 | |
4 #include <stdio.h> | |
5 #include "base/allocator/allocator_shim.h" | |
6 #include "testing/gtest/include/gtest/gtest.h" | |
7 | |
8 // TCMalloc header files | |
9 #include "common.h" // For TCMalloc constants like page size, etc. | |
10 | |
11 using base::allocator::TCMallocDoMallocForTest; | |
12 using base::allocator::TCMallocDoFreeForTest; | |
13 | |
14 TEST(TCMallocFreeCheck, BadPointerInFirstPageOfTheLargeObject) { | |
15 volatile int* p = | |
16 reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize + 1)); | |
jar (doing other things)
2012/05/17 01:36:41
nit: No need for volatile here.
kaiwang
2012/05/19 00:12:27
Done.
| |
17 ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p + kAlignment)), | |
jar (doing other things)
2012/05/17 01:36:41
Perhaps try adding small powers of two: 1, 2, 4, 8
kaiwang
2012/05/19 00:12:27
Done.
| |
18 "Pointer not pointed to the start of a span"); | |
19 } | |
20 | |
21 TEST(TCMallocFreeCheck, BadPointerInSubsequentPagesOfTheLargeObject) { | |
jar (doing other things)
2012/05/17 01:36:41
nit: suggest better name:
BadPageAlignedPointerIns
kaiwang
2012/05/19 00:12:27
Done.
| |
22 volatile int* p = | |
23 reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize + 1)); | |
24 ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p + kPageSize)), | |
jar (doing other things)
2012/05/17 01:36:41
perhaps iterate at page boundaries (but stay insid
| |
25 "Attempt to free invalid pointer"); | |
26 } | |
27 /* | |
28 #ifndef NDEBUG | |
29 TEST(TCMallocFreeCheck, DoubleFreeLargeObject) { | |
30 volatile int* p = | |
31 reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize + 1)); | |
32 TCMallocDoFreeForTest(const_cast<int*>(p)); | |
33 ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p)), | |
34 "Attempt to double free"); | |
35 } | |
36 | |
37 TEST(TCMallocFreeCheck, DoubleFreeSmallObject) { | |
38 volatile int* p = | |
39 reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize)); | |
40 TCMallocDoFreeForTest(const_cast<int*>(p)); | |
41 ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p)), | |
42 "Attempt to double free"); | |
43 } | |
44 #endif | |
45 */ | |
46 int main(int argc, char **argv) { | |
47 testing::InitGoogleTest(&argc, argv); | |
48 return RUN_ALL_TESTS(); | |
49 } | |
OLD | NEW |