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

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

Issue 2028183002: tcmalloc_unittest: Use malloc and free directly, instead of tc_malloc and tc_free. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | no next file » | 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 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 7
8 #include "base/compiler_specific.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/process/process_metrics.h" 10 #include "base/process/process_metrics.h"
10 #include "build/build_config.h" 11 #include "build/build_config.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 #if defined(USE_TCMALLOC) 14 #if defined(USE_TCMALLOC)
14 extern "C" {
15 void* tc_malloc(size_t size);
16 void tc_free(void*);
17 }
18
19 namespace { 15 namespace {
20 16
21 using std::min; 17 using std::min;
22 18
23 #ifdef NDEBUG 19 #ifdef NDEBUG
24 void* TCMallocDoMallocForTest(size_t size) { 20 // We wrap malloc and free in noinline functions to ensure that we test the real
25 return tc_malloc(size); 21 // implementation of the allocator. Otherwise, the compiler may specifically
22 // recognize the calls to malloc and free in our tests and optimize them away.
23 NOINLINE void* TCMallocDoMallocForTest(size_t size) {
Primiano Tucci (use gerrit) 2016/06/01 20:29:06 Oh, I would have never thought to this. right.
24 return malloc(size);
26 } 25 }
27 26
28 void TCMallocDoFreeForTest(void* ptr) { 27 NOINLINE void TCMallocDoFreeForTest(void* ptr) {
29 tc_free(ptr); 28 free(ptr);
30 } 29 }
31 #endif 30 #endif
32 31
33 // Fill a buffer of the specified size with a predetermined pattern 32 // Fill a buffer of the specified size with a predetermined pattern
34 static void Fill(unsigned char* buffer, int n) { 33 static void Fill(unsigned char* buffer, int n) {
35 for (int i = 0; i < n; i++) { 34 for (int i = 0; i < n; i++) {
36 buffer[i] = (i & 0xff); 35 buffer[i] = (i & 0xff);
37 } 36 }
38 } 37 }
39 38
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 const size_t kPageSize = base::GetPageSize(); 215 const size_t kPageSize = base::GetPageSize();
217 for (size_t size = 1; size <= kPageSize; size <<= 1) { 216 for (size_t size = 1; size <= kPageSize; size <<= 1) {
218 char* p = reinterpret_cast<char*>(TCMallocDoMallocForTest(size)); 217 char* p = reinterpret_cast<char*>(TCMallocDoMallocForTest(size));
219 ASSERT_DEATH(TCMallocDoFreeForTest(p); TCMallocDoFreeForTest(p), 218 ASSERT_DEATH(TCMallocDoFreeForTest(p); TCMallocDoFreeForTest(p),
220 "Circular loop in list detected"); 219 "Circular loop in list detected");
221 } 220 }
222 } 221 }
223 #endif // NDEBUG 222 #endif // NDEBUG
224 223
225 #endif 224 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698