OLD | NEW |
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 Loading... |
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 <gperftools/malloc_extension_c.h> | 43 #include <google/malloc_extension_c.h> |
44 #include <gperftools/malloc_hook_c.h> | 44 #include <google/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 Loading... |
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 } | |
137 | 129 |
138 free(x); | 130 free(x); |
139 } | 131 } |
140 | 132 |
141 int main(int argc, char** argv) { | 133 int main(int argc, char** argv) { |
142 TestMallocHook(); | 134 TestMallocHook(); |
143 TestMallocExtension(); | 135 TestMallocExtension(); |
144 | 136 |
145 printf("PASS\n"); | 137 printf("PASS\n"); |
146 return 0; | 138 return 0; |
147 } | 139 } |
OLD | NEW |