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

Side by Side Diff: third_party/tcmalloc/chromium/src/tests/malloc_extension_c_test.c

Issue 9666033: Experiment for updating the tcmalloc chromium branch to r144 (gperftools 2.0). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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) 2009, Google Inc. 1 /* Copyright (c) 2009, 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 22 matching lines...) Expand all
33 * This tests the c shims: malloc_extension_c.h and malloc_hook_c.h. 33 * This tests the c shims: malloc_extension_c.h and malloc_hook_c.h.
34 * Mostly, we'll just care that these shims compile under gcc 34 * Mostly, we'll just care that these shims compile under gcc
35 * (*not* g++!) 35 * (*not* g++!)
36 * 36 *
37 * NOTE: this is C code, not C++ code! 37 * NOTE: this is C code, not C++ code!
38 */ 38 */
39 39
40 #include <stdio.h> 40 #include <stdio.h>
41 #include <stdlib.h> 41 #include <stdlib.h>
42 #include <stddef.h> /* for size_t */ 42 #include <stddef.h> /* for size_t */
43 #include <google/malloc_extension_c.h> 43 #include <gperftools/malloc_extension_c.h>
44 #include <google/malloc_hook_c.h> 44 #include <gperftools/malloc_hook_c.h>
45 45
46 #define FAIL(msg) do { \ 46 #define FAIL(msg) do { \
47 fprintf(stderr, "FATAL ERROR: %s\n", msg); \ 47 fprintf(stderr, "FATAL ERROR: %s\n", msg); \
48 exit(1); \ 48 exit(1); \
49 } while (0) 49 } while (0)
50 50
51 static int g_new_hook_calls = 0; 51 static int g_new_hook_calls = 0;
52 static int g_delete_hook_calls = 0; 52 static int g_delete_hook_calls = 0;
53 53
54 void TestNewHook(const void* ptr, size_t size) { 54 void TestNewHook(const void* ptr, size_t size) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 MallocExtension_MarkThreadIdle(); 119 MallocExtension_MarkThreadIdle();
120 MallocExtension_MarkThreadBusy(); 120 MallocExtension_MarkThreadBusy();
121 MallocExtension_ReleaseToSystem(1); 121 MallocExtension_ReleaseToSystem(1);
122 MallocExtension_ReleaseFreeMemory(); 122 MallocExtension_ReleaseFreeMemory();
123 if (MallocExtension_GetEstimatedAllocatedSize(10) < 10) { 123 if (MallocExtension_GetEstimatedAllocatedSize(10) < 10) {
124 FAIL("GetEstimatedAllocatedSize returned a bad value (too small)"); 124 FAIL("GetEstimatedAllocatedSize returned a bad value (too small)");
125 } 125 }
126 if (MallocExtension_GetAllocatedSize(x) < 10) { 126 if (MallocExtension_GetAllocatedSize(x) < 10) {
127 FAIL("GetEstimatedAllocatedSize returned a bad value (too small)"); 127 FAIL("GetEstimatedAllocatedSize returned a bad value (too small)");
128 } 128 }
129 if (MallocExtension_GetOwnership(x) != MallocExtension_kOwned) {
130 FAIL("DidAllocatePtr returned a bad value (kNotOwned)");
131 }
132 /* TODO(csilvers): this relies on undocumented behavior that
133 GetOwnership works on stack-allocated variables. Use a better test. */
134 if (MallocExtension_GetOwnership(hist) != MallocExtension_kNotOwned) {
135 FAIL("DidAllocatePtr returned a bad value (kOwned)");
136 }
129 137
130 free(x); 138 free(x);
131 } 139 }
132 140
133 int main(int argc, char** argv) { 141 int main(int argc, char** argv) {
134 TestMallocHook(); 142 TestMallocHook();
135 TestMallocExtension(); 143 TestMallocExtension();
136 144
137 printf("PASS\n"); 145 printf("PASS\n");
138 return 0; 146 return 0;
139 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698