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

Side by Side Diff: third_party/tcmalloc/vendor/src/tests/tcmalloc_unittest.cc

Issue 9316021: Update the tcmalloc vendor branch to r144 (gperftools 2.0). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reuploading Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #ifdef HAVE_MALLOC_H 81 #ifdef HAVE_MALLOC_H
82 #include <malloc.h> // defines pvalloc/etc on cygwin 82 #include <malloc.h> // defines pvalloc/etc on cygwin
83 #endif 83 #endif
84 #include <assert.h> 84 #include <assert.h>
85 #include <vector> 85 #include <vector>
86 #include <algorithm> 86 #include <algorithm>
87 #include <string> 87 #include <string>
88 #include <new> 88 #include <new>
89 #include "base/logging.h" 89 #include "base/logging.h"
90 #include "base/simple_mutex.h" 90 #include "base/simple_mutex.h"
91 #include "google/malloc_hook.h" 91 #include "gperftools/malloc_hook.h"
92 #include "google/malloc_extension.h" 92 #include "gperftools/malloc_extension.h"
93 #include "google/tcmalloc.h" 93 #include "gperftools/tcmalloc.h"
94 #include "thread_cache.h" 94 #include "thread_cache.h"
95 #include "tests/testutil.h" 95 #include "tests/testutil.h"
96 96
97 // Windows doesn't define pvalloc and a few other obsolete unix 97 // Windows doesn't define pvalloc and a few other obsolete unix
98 // functions; nor does it define posix_memalign (which is not obsolete). 98 // functions; nor does it define posix_memalign (which is not obsolete).
99 #if defined(_WIN32) 99 #if defined(_WIN32)
100 # define cfree free // don't bother to try to test these obsolete fns 100 # define cfree free // don't bother to try to test these obsolete fns
101 # define valloc malloc 101 # define valloc malloc
102 # define pvalloc malloc 102 # define pvalloc malloc
103 // I'd like to map posix_memalign to _aligned_malloc, but _aligned_malloc 103 // I'd like to map posix_memalign to _aligned_malloc, but _aligned_malloc
104 // must be paired with _aligned_free (not normal free), which is too 104 // must be paired with _aligned_free (not normal free), which is too
105 // invasive a change to how we allocate memory here. So just bail 105 // invasive a change to how we allocate memory here. So just bail
106 static bool kOSSupportsMemalign = false; 106 static bool kOSSupportsMemalign = false;
107 static inline void* Memalign(size_t align, size_t size) { 107 static inline void* Memalign(size_t align, size_t size) {
108 //LOG(FATAL) << "memalign not supported on windows"; 108 //LOG(FATAL) << "memalign not supported on windows";
109 exit(1); 109 exit(1);
110 return NULL;
110 } 111 }
111 static inline int PosixMemalign(void** ptr, size_t align, size_t size) { 112 static inline int PosixMemalign(void** ptr, size_t align, size_t size) {
112 //LOG(FATAL) << "posix_memalign not supported on windows"; 113 //LOG(FATAL) << "posix_memalign not supported on windows";
113 exit(1); 114 exit(1);
115 return -1;
114 } 116 }
115 117
116 // OS X defines posix_memalign in some OS versions but not others; 118 // OS X defines posix_memalign in some OS versions but not others;
117 // it's confusing enough to check that it's easiest to just not to test. 119 // it's confusing enough to check that it's easiest to just not to test.
118 #elif defined(__APPLE__) 120 #elif defined(__APPLE__)
119 static bool kOSSupportsMemalign = false; 121 static bool kOSSupportsMemalign = false;
120 static inline void* Memalign(size_t align, size_t size) { 122 static inline void* Memalign(size_t align, size_t size) {
121 //LOG(FATAL) << "memalign not supported on OS X"; 123 //LOG(FATAL) << "memalign not supported on OS X";
122 exit(1); 124 exit(1);
125 return NULL;
123 } 126 }
124 static inline int PosixMemalign(void** ptr, size_t align, size_t size) { 127 static inline int PosixMemalign(void** ptr, size_t align, size_t size) {
125 //LOG(FATAL) << "posix_memalign not supported on OS X"; 128 //LOG(FATAL) << "posix_memalign not supported on OS X";
126 exit(1); 129 exit(1);
130 return -1;
127 } 131 }
128 132
129 #else 133 #else
130 static bool kOSSupportsMemalign = true; 134 static bool kOSSupportsMemalign = true;
131 static inline void* Memalign(size_t align, size_t size) { 135 static inline void* Memalign(size_t align, size_t size) {
132 return memalign(align, size); 136 return memalign(align, size);
133 } 137 }
134 static inline int PosixMemalign(void** ptr, size_t align, size_t size) { 138 static inline int PosixMemalign(void** ptr, size_t align, size_t size) {
135 return posix_memalign(ptr, align, size); 139 return posix_memalign(ptr, align, size);
136 } 140 }
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 p1 = Memalign(sizeof(p1) * 2, 50); 1080 p1 = Memalign(sizeof(p1) * 2, 50);
1077 CHECK(p1 != NULL); 1081 CHECK(p1 != NULL);
1078 VerifyNewHookWasCalled(); 1082 VerifyNewHookWasCalled();
1079 free(p1); 1083 free(p1);
1080 VerifyDeleteHookWasCalled(); 1084 VerifyDeleteHookWasCalled();
1081 } 1085 }
1082 1086
1083 // Windows has _aligned_malloc. Let's test that that's captured too. 1087 // Windows has _aligned_malloc. Let's test that that's captured too.
1084 #if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(PERFTOOLS_NO_ALIGNED _MALLOC) 1088 #if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(PERFTOOLS_NO_ALIGNED _MALLOC)
1085 p1 = _aligned_malloc(sizeof(p1) * 2, 64); 1089 p1 = _aligned_malloc(sizeof(p1) * 2, 64);
1090 CHECK(p1 != NULL);
1086 VerifyNewHookWasCalled(); 1091 VerifyNewHookWasCalled();
1087 _aligned_free(p1); 1092 _aligned_free(p1);
1088 VerifyDeleteHookWasCalled(); 1093 VerifyDeleteHookWasCalled();
1089 #endif 1094 #endif
1090 1095
1091 p1 = valloc(60); 1096 p1 = valloc(60);
1092 CHECK(p1 != NULL); 1097 CHECK(p1 != NULL);
1093 VerifyNewHookWasCalled(); 1098 VerifyNewHookWasCalled();
1094 free(p1); 1099 free(p1);
1095 VerifyDeleteHookWasCalled(); 1100 VerifyDeleteHookWasCalled();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 int minor; 1318 int minor;
1314 const char* patch; 1319 const char* patch;
1315 char mmp[64]; 1320 char mmp[64];
1316 const char* human_version = tc_version(&major, &minor, &patch); 1321 const char* human_version = tc_version(&major, &minor, &patch);
1317 snprintf(mmp, sizeof(mmp), "%d.%d%s", major, minor, patch); 1322 snprintf(mmp, sizeof(mmp), "%d.%d%s", major, minor, patch);
1318 CHECK(!strcmp(PACKAGE_STRING, human_version)); 1323 CHECK(!strcmp(PACKAGE_STRING, human_version));
1319 CHECK(!strcmp(PACKAGE_VERSION, mmp)); 1324 CHECK(!strcmp(PACKAGE_VERSION, mmp));
1320 1325
1321 fprintf(LOGSTREAM, "PASS\n"); 1326 fprintf(LOGSTREAM, "PASS\n");
1322 } 1327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698