Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: base/allocator/tcmalloc_unittest.cc

Issue 774683003: Remove tcmalloc when not being used. Restore shim on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add realloc death test. nits. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/allocator/prep_libc.py ('k') | base/allocator/win_allocator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « base/allocator/prep_libc.py ('k') | base/allocator/win_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698