OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <stdint.h> | |
6 #include <string.h> | |
7 #include <map> | |
8 | |
9 #include "base/compiler_specific.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 #include "tools/android/heap_profiler/heap_profiler.h" | |
12 | |
13 | |
14 namespace { | |
15 | |
16 class HeapProfilerTest : public testing::Test { | |
17 public: | |
18 virtual void SetUp() OVERRIDE { | |
19 heap_profiler_init(&stats_); | |
20 } | |
21 | |
22 virtual void TearDown() OVERRIDE { | |
23 CheckVMAvsStacktaceConsistency(); | |
24 heap_profiler_cleanup(); | |
25 } | |
26 | |
27 protected: | |
28 struct StackTrace { | |
29 uintptr_t frames[HEAP_PROFILER_MAX_DEPTH]; | |
30 size_t depth; | |
31 }; | |
32 | |
33 StackTrace GenStackTrace(size_t depth, uintptr_t base) { | |
34 assert(depth <= HEAP_PROFILER_MAX_DEPTH); | |
35 StackTrace st; | |
36 for (size_t i = 0; i < depth; ++i) | |
37 st.frames[i] = base + i * 0x10UL; | |
38 st.depth = depth; | |
39 return st; | |
40 } | |
41 | |
42 void ExpectVMA( | |
43 uintptr_t start, uintptr_t end, const StackTrace& st, uint32_t flags) { | |
44 for (uint32_t i = 0; i < stats_.max_allocs; ++i) { | |
45 const VMA& vma = stats_.allocs[i]; | |
46 if (vma.start != start || vma.end != end) | |
47 continue; | |
48 // Check that the stack trace match. | |
49 for (uint32_t j = 0; j < st.depth; ++j) { | |
50 EXPECT_EQ(st.frames[j], vma.st->frames[j]) << | |
51 "Stacktrace not matching @ depth " << j; | |
52 } | |
53 EXPECT_EQ(flags, vma.flags); | |
54 return; | |
55 } | |
56 | |
57 FAIL() << "Could not find VMA [" << std::hex << start << "," << end << "]"; | |
58 } | |
59 | |
60 void CheckVMAvsStacktaceConsistency() { | |
61 uint32_t allocs_seen = 0; | |
62 uint32_t stack_traces_seen = 0; | |
63 std::map<StacktraceEntry*, uintptr_t> stacktrace_bytes_seen_by_vma; | |
64 | |
65 for (uint32_t i = 0; i < stats_.max_allocs; ++i) { | |
66 VMA* vma = &stats_.allocs[i]; | |
67 if (vma->start == 0 && vma->end == 0) | |
68 continue; | |
69 ++allocs_seen; | |
70 stacktrace_bytes_seen_by_vma[vma->st] += vma->end - vma->start + 1; | |
71 } | |
72 | |
73 for (uint32_t i = 0; i < stats_.max_stack_traces; ++i) { | |
74 StacktraceEntry* st = &stats_.stack_traces[i]; | |
75 if (st->alloc_bytes == 0) | |
76 continue; | |
77 ++stack_traces_seen; | |
78 EXPECT_EQ(1, stacktrace_bytes_seen_by_vma.count(st)); | |
79 EXPECT_EQ(stacktrace_bytes_seen_by_vma[st], st->alloc_bytes); | |
80 } | |
81 | |
82 EXPECT_EQ(allocs_seen, stats_.num_allocs); | |
83 EXPECT_EQ(stack_traces_seen, stats_.num_stack_traces); | |
84 } | |
85 | |
86 HeapStats stats_; | |
87 }; | |
88 | |
89 | |
90 TEST_F(HeapProfilerTest, SimpleAlloc) { | |
91 StackTrace st1 = GenStackTrace(8, 0x0); | |
92 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
93 heap_profiler_alloc((void*) 0x2000, 2048, st1.frames, st1.depth, 0); | |
94 | |
95 EXPECT_EQ(2, stats_.num_allocs); | |
96 EXPECT_EQ(1, stats_.num_stack_traces); | |
97 EXPECT_EQ(1024 + 2048, stats_.total_alloc_bytes); | |
98 ExpectVMA(0x1000, 0x13ff, st1, 0); | |
99 ExpectVMA(0x2000, 0x27ff, st1, 0); | |
100 } | |
101 | |
102 TEST_F(HeapProfilerTest, AllocMultipleStacks) { | |
103 StackTrace st1 = GenStackTrace(8, 0x0); | |
104 StackTrace st2 = GenStackTrace(4, 0x1000); | |
105 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
106 heap_profiler_alloc((void*) 0x2000, 2048, st2.frames, st2.depth, 0); | |
107 heap_profiler_alloc((void*) 0x3000, 32, st1.frames, st1.depth, 0); | |
108 | |
109 EXPECT_EQ(3, stats_.num_allocs); | |
110 EXPECT_EQ(2, stats_.num_stack_traces); | |
111 EXPECT_EQ(1024 + 2048 + 32, stats_.total_alloc_bytes); | |
112 ExpectVMA(0x1000, 0x13ff, st1, 0); | |
113 ExpectVMA(0x2000, 0x27ff, st2, 0); | |
114 ExpectVMA(0x3000, 0x301f, st1, 0); | |
115 } | |
116 | |
117 TEST_F(HeapProfilerTest, SimpleAllocAndFree) { | |
118 StackTrace st1 = GenStackTrace(8, 0x0); | |
119 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
120 heap_profiler_free((void*) 0x1000, 1024, NULL); | |
121 | |
122 EXPECT_EQ(0, stats_.num_allocs); | |
123 EXPECT_EQ(0, stats_.num_stack_traces); | |
124 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
125 } | |
126 | |
127 TEST_F(HeapProfilerTest, Realloc) { | |
128 StackTrace st1 = GenStackTrace(8, 0); | |
129 heap_profiler_alloc((void*) 0, 32, st1.frames, st1.depth, 0); | |
130 heap_profiler_alloc((void*) 0, 32, st1.frames, st1.depth, 0); | |
131 } | |
132 | |
133 TEST_F(HeapProfilerTest, AllocAndFreeMultipleStacks) { | |
134 StackTrace st1 = GenStackTrace(8, 0x0); | |
135 StackTrace st2 = GenStackTrace(6, 0x1000); | |
136 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
137 heap_profiler_alloc((void*) 0x2000, 2048, st1.frames, st1.depth, 0); | |
138 heap_profiler_alloc((void*) 0x3000, 32, st2.frames, st2.depth, 0); | |
139 heap_profiler_alloc((void*) 0x4000, 64, st2.frames, st2.depth, 0); | |
140 | |
141 heap_profiler_free((void*) 0x1000, 1024, NULL); | |
142 heap_profiler_free((void*) 0x3000, 32, NULL); | |
143 | |
144 EXPECT_EQ(2, stats_.num_allocs); | |
145 EXPECT_EQ(2, stats_.num_stack_traces); | |
146 EXPECT_EQ(2048 + 64, stats_.total_alloc_bytes); | |
147 ExpectVMA(0x2000, 0x27ff, st1, 0); | |
148 ExpectVMA(0x4000, 0x403f, st2, 0); | |
149 } | |
150 | |
151 TEST_F(HeapProfilerTest, AllocAndFreeAll) { | |
152 StackTrace st1 = GenStackTrace(8, 0x0); | |
153 StackTrace st2 = GenStackTrace(6, 0x1000); | |
154 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
155 heap_profiler_alloc((void*) 0x2000, 2048, st1.frames, st1.depth, 0); | |
156 heap_profiler_alloc((void*) 0x3000, 32, st2.frames, st2.depth, 0); | |
157 heap_profiler_alloc((void*) 0x4000, 64, st2.frames, st2.depth, 0); | |
158 | |
159 heap_profiler_free((void*) 0x1000, 1024, NULL); | |
160 heap_profiler_free((void*) 0x2000, 2048, NULL); | |
161 heap_profiler_free((void*) 0x3000, 32, NULL); | |
162 heap_profiler_free((void*) 0x4000, 64, NULL); | |
163 | |
164 EXPECT_EQ(0, stats_.num_allocs); | |
165 EXPECT_EQ(0, stats_.num_stack_traces); | |
166 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
167 } | |
168 | |
169 TEST_F(HeapProfilerTest, AllocAndFreeWithZeroSize) { | |
170 StackTrace st1 = GenStackTrace(8, 0x0); | |
171 StackTrace st2 = GenStackTrace(6, 0x1000); | |
172 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
173 heap_profiler_alloc((void*) 0x2000, 2048, st2.frames, st2.depth, 0); | |
174 | |
175 heap_profiler_free((void*) 0x1000, 0, NULL); | |
176 | |
177 EXPECT_EQ(1, stats_.num_allocs); | |
178 EXPECT_EQ(1, stats_.num_stack_traces); | |
179 EXPECT_EQ(2048, stats_.total_alloc_bytes); | |
180 } | |
181 | |
182 TEST_F(HeapProfilerTest, AllocAndFreeContiguous) { | |
183 StackTrace st1 = GenStackTrace(8, 0x0); | |
184 StackTrace st2 = GenStackTrace(6, 0x1000); | |
185 heap_profiler_alloc((void*) 0x1000, 4096, st1.frames, st1.depth, 0); | |
186 heap_profiler_alloc((void*) 0x2000, 4096, st2.frames, st2.depth, 0); | |
187 | |
188 heap_profiler_free((void*) 0x1000, 8192, NULL); | |
189 | |
190 EXPECT_EQ(0, stats_.num_allocs); | |
191 EXPECT_EQ(0, stats_.num_stack_traces); | |
192 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
193 } | |
194 | |
195 TEST_F(HeapProfilerTest, SparseAllocsOneLargeOuterFree) { | |
196 StackTrace st1 = GenStackTrace(8, 0x0); | |
197 StackTrace st2 = GenStackTrace(6, 0x1000); | |
198 | |
199 heap_profiler_alloc((void*) 0x1010, 1, st1.frames, st1.depth, 0); | |
200 heap_profiler_alloc((void*) 0x1400, 2, st2.frames, st2.depth, 0); | |
201 heap_profiler_alloc((void*) 0x1600, 5, st1.frames, st1.depth, 0); | |
202 heap_profiler_alloc((void*) 0x9000, 4096, st2.frames, st2.depth, 0); | |
203 | |
204 heap_profiler_free((void*) 0x0800, 8192, NULL); | |
205 EXPECT_EQ(1, stats_.num_allocs); | |
206 EXPECT_EQ(1, stats_.num_stack_traces); | |
207 EXPECT_EQ(4096, stats_.total_alloc_bytes); | |
208 ExpectVMA(0x9000, 0x9fff, st2, 0); | |
209 } | |
210 | |
211 TEST_F(HeapProfilerTest, SparseAllocsOneLargePartiallyOverlappingFree) { | |
212 StackTrace st1 = GenStackTrace(8, 0x0); | |
213 StackTrace st2 = GenStackTrace(6, 0x1000); | |
214 StackTrace st3 = GenStackTrace(4, 0x2000); | |
215 | |
216 // This will be untouched. | |
217 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
218 | |
219 // These will be partially freed in one shot (% 64 a bytes "margin"). | |
220 heap_profiler_alloc((void*) 0x2000, 128, st2.frames, st2.depth, 0); | |
221 heap_profiler_alloc((void*) 0x2400, 128, st2.frames, st2.depth, 0); | |
222 heap_profiler_alloc((void*) 0x2f80, 128, st2.frames, st2.depth, 0); | |
223 | |
224 // This will be untouched. | |
225 heap_profiler_alloc((void*) 0x3000, 1024, st3.frames, st3.depth, 0); | |
226 | |
227 heap_profiler_free((void*) 0x2040, 4096 - 64 - 64, NULL); | |
228 EXPECT_EQ(4, stats_.num_allocs); | |
229 EXPECT_EQ(3, stats_.num_stack_traces); | |
230 EXPECT_EQ(1024 + 64 + 64 + 1024, stats_.total_alloc_bytes); | |
231 | |
232 ExpectVMA(0x1000, 0x13ff, st1, 0); | |
233 ExpectVMA(0x2000, 0x203f, st2, 0); | |
234 ExpectVMA(0x2fc0, 0x2fff, st2, 0); | |
235 ExpectVMA(0x3000, 0x33ff, st3, 0); | |
236 } | |
237 | |
238 TEST_F(HeapProfilerTest, AllocAndFreeScattered) { | |
239 StackTrace st1 = GenStackTrace(8, 0x0); | |
240 heap_profiler_alloc((void*) 0x1000, 4096, st1.frames, st1.depth, 0); | |
241 heap_profiler_alloc((void*) 0x2000, 4096, st1.frames, st1.depth, 0); | |
242 heap_profiler_alloc((void*) 0x3000, 4096, st1.frames, st1.depth, 0); | |
243 heap_profiler_alloc((void*) 0x4000, 4096, st1.frames, st1.depth, 0); | |
244 | |
245 heap_profiler_free((void*) 0x800, 4096, NULL); | |
246 EXPECT_EQ(4, stats_.num_allocs); | |
247 EXPECT_EQ(2048 + 4096 + 4096 + 4096, stats_.total_alloc_bytes); | |
248 | |
249 heap_profiler_free((void*) 0x1800, 4096, NULL); | |
250 EXPECT_EQ(3, stats_.num_allocs); | |
251 EXPECT_EQ(2048 + 4096 + 4096, stats_.total_alloc_bytes); | |
252 | |
253 heap_profiler_free((void*) 0x2800, 4096, NULL); | |
254 EXPECT_EQ(2, stats_.num_allocs); | |
255 EXPECT_EQ(2048 + 4096, stats_.total_alloc_bytes); | |
256 | |
257 heap_profiler_free((void*) 0x3800, 4096, NULL); | |
258 EXPECT_EQ(1, stats_.num_allocs); | |
259 EXPECT_EQ(2048, stats_.total_alloc_bytes); | |
260 | |
261 heap_profiler_free((void*) 0x4800, 4096, NULL); | |
262 EXPECT_EQ(0, stats_.num_allocs); | |
263 EXPECT_EQ(0, stats_.num_stack_traces); | |
264 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
265 } | |
266 | |
267 TEST_F(HeapProfilerTest, AllocAndOverFreeContiguous) { | |
268 StackTrace st1 = GenStackTrace(8, 0x0); | |
269 StackTrace st2 = GenStackTrace(6, 0x1000); | |
270 heap_profiler_alloc((void*) 0x1000, 4096, st1.frames, st1.depth, 0); | |
271 heap_profiler_alloc((void*) 0x2000, 4096, st2.frames, st2.depth, 0); | |
272 | |
273 heap_profiler_free((void*) 0, 16834, NULL); | |
274 | |
275 EXPECT_EQ(0, stats_.num_allocs); | |
276 EXPECT_EQ(0, stats_.num_stack_traces); | |
277 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
278 } | |
279 | |
280 TEST_F(HeapProfilerTest, AllocContiguousAndPunchHole) { | |
281 StackTrace st1 = GenStackTrace(8, 0x0); | |
282 StackTrace st2 = GenStackTrace(6, 0x1000); | |
283 heap_profiler_alloc((void*) 0x1000, 4096, st1.frames, st1.depth, 0); | |
284 heap_profiler_alloc((void*) 0x2000, 4096, st2.frames, st2.depth, 0); | |
285 | |
286 // Punch a 4k hole in the middle of the two contiguous 4k allocs. | |
287 heap_profiler_free((void*) 0x1800, 4096, NULL); | |
288 | |
289 EXPECT_EQ(2, stats_.num_allocs); | |
290 EXPECT_EQ(2, stats_.num_stack_traces); | |
291 EXPECT_EQ(4096, stats_.total_alloc_bytes); | |
292 } | |
293 | |
294 TEST_F(HeapProfilerTest, AllocAndPartialFree) { | |
295 StackTrace st1 = GenStackTrace(8, 0x0); | |
296 StackTrace st2 = GenStackTrace(6, 0x1000); | |
297 StackTrace st3 = GenStackTrace(7, 0x2000); | |
298 StackTrace st4 = GenStackTrace(9, 0x3000); | |
299 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
300 heap_profiler_alloc((void*) 0x2000, 1024, st2.frames, st2.depth, 0); | |
301 heap_profiler_alloc((void*) 0x3000, 1024, st3.frames, st3.depth, 0); | |
302 heap_profiler_alloc((void*) 0x4000, 1024, st4.frames, st4.depth, 0); | |
303 | |
304 heap_profiler_free((void*) 0x1000, 128, NULL); // Shrink left by 128B. | |
305 heap_profiler_free((void*) 0x2380, 128, NULL); // Shrink right by 128B. | |
306 heap_profiler_free((void*) 0x3100, 512, NULL); // 512B hole in the middle. | |
307 heap_profiler_free((void*) 0x4000, 512, NULL); // Free up the 4th vma... | |
308 heap_profiler_free((void*) 0x4200, 512, NULL); // ...but do it in two halves. | |
309 | |
310 EXPECT_EQ(4, stats_.num_allocs); // 1 + 2 + two sides around the hole 3. | |
311 EXPECT_EQ(3, stats_.num_stack_traces); // st4 should be gone. | |
312 EXPECT_EQ(896 + 896 + 512, stats_.total_alloc_bytes); | |
313 } | |
314 | |
315 TEST_F(HeapProfilerTest, RandomIndividualAllocAndFrees) { | |
316 static const size_t NUM_ST = 128; | |
317 static const size_t NUM_OPS = 1000; | |
318 | |
319 StackTrace st[NUM_ST]; | |
320 for (uint32_t i = 0; i < NUM_ST; ++i) | |
321 st[i] = GenStackTrace((i % 10) + 2, i * 128); | |
322 | |
323 for (size_t i = 0; i < NUM_OPS; ++i) { | |
324 uintptr_t start = ((i + 7) << 8) & (0xffffff); | |
325 size_t size = (start >> 16) & 0x0fff; | |
326 if (i & 1) { | |
327 StackTrace* s = &st[start % NUM_ST]; | |
328 heap_profiler_alloc((void*) start, size, s->frames, s->depth, 0); | |
329 } else { | |
330 heap_profiler_free((void*) start, size, NULL); | |
331 } | |
332 CheckVMAvsStacktaceConsistency(); | |
333 } | |
334 } | |
335 | |
336 TEST_F(HeapProfilerTest, RandomAllocAndFreesBatches) { | |
337 static const size_t NUM_ST = 128; | |
338 static const size_t NUM_ALLOCS = 100; | |
339 | |
340 StackTrace st[NUM_ST]; | |
341 for (size_t i = 0; i < NUM_ST; ++i) | |
342 st[i] = GenStackTrace((i % 10) + 2, i * NUM_ST); | |
343 | |
344 for (int repeat = 0; repeat < 5; ++repeat) { | |
345 for (size_t i = 0; i < NUM_ALLOCS; ++i) { | |
346 StackTrace* s = &st[i % NUM_ST]; | |
347 heap_profiler_alloc( | |
348 (void*) (i * 4096), ((i + 1) * 32) % 4097, s->frames, s->depth, 0); | |
349 CheckVMAvsStacktaceConsistency(); | |
350 } | |
351 | |
352 for (size_t i = 0; i < NUM_ALLOCS; ++i) { | |
353 heap_profiler_free((void*) (i * 1024), ((i + 1) * 64) % 16000, NULL); | |
354 CheckVMAvsStacktaceConsistency(); | |
355 } | |
356 } | |
357 } | |
358 | |
359 TEST_F(HeapProfilerTest, UnwindStackTooLargeShouldSaturate) { | |
360 StackTrace st1 = GenStackTrace(HEAP_PROFILER_MAX_DEPTH, 0x0); | |
361 uintptr_t many_frames[100] = {}; | |
362 memcpy(many_frames, st1.frames, sizeof(uintptr_t) * st1.depth); | |
363 heap_profiler_alloc((void*) 0x1000, 1024, many_frames, 100, 0); | |
364 ExpectVMA(0x1000, 0x13ff, st1, 0); | |
365 } | |
366 | |
367 TEST_F(HeapProfilerTest, NoUnwindShouldNotCrashButNoop) { | |
368 heap_profiler_alloc((void*) 0x1000, 1024, NULL, 0, 0); | |
369 EXPECT_EQ(0, stats_.num_allocs); | |
370 EXPECT_EQ(0, stats_.num_stack_traces); | |
371 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
372 } | |
373 | |
374 TEST_F(HeapProfilerTest, FreeNonExisting) { | |
375 StackTrace st1 = GenStackTrace(5, 0x0); | |
376 heap_profiler_free((void*) 0x1000, 1024, NULL); | |
377 heap_profiler_free((void*) 0x1400, 1024, NULL); | |
378 EXPECT_EQ(0, stats_.num_allocs); | |
379 EXPECT_EQ(0, stats_.num_stack_traces); | |
380 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
381 heap_profiler_alloc((void*) 0x1000, 1024, st1.frames, st1.depth, 0); | |
382 EXPECT_EQ(1, stats_.num_allocs); | |
383 EXPECT_EQ(1024, stats_.total_alloc_bytes); | |
384 } | |
385 | |
386 TEST_F(HeapProfilerTest, FlagsConsistency) { | |
387 StackTrace st1 = GenStackTrace(8, 0x0); | |
388 uint32_t flags = 0; | |
389 heap_profiler_alloc((void*) 0x1000, 4096, st1.frames, st1.depth, 42); | |
390 heap_profiler_alloc((void*) 0x2000, 4096, st1.frames, st1.depth, 142); | |
391 | |
392 ExpectVMA(0x1000, 0x1fff, st1, 42); | |
393 ExpectVMA(0x2000, 0x2fff, st1, 142); | |
394 | |
395 // Punch a 4k hole in the middle of the two contiguous 4k allocs. | |
396 heap_profiler_free((void*) 0x1800, 4096, NULL); | |
397 | |
398 ExpectVMA(0x1000, 0x17ff, st1, 42); | |
399 heap_profiler_free((void*) 0x1000, 2048, &flags); | |
400 EXPECT_EQ(42, flags); | |
401 | |
402 ExpectVMA(0x2800, 0x2fff, st1, 142); | |
403 heap_profiler_free((void*) 0x2800, 2048, &flags); | |
404 EXPECT_EQ(142, flags); | |
405 } | |
406 | |
407 TEST_F(HeapProfilerTest, BeConsistentOnOOM) { | |
408 static const size_t NUM_ALLOCS = 512 * 1024; | |
409 uintptr_t frames[1]; | |
410 | |
411 for (uintptr_t i = 0; i < NUM_ALLOCS; ++i) { | |
412 frames[0] = i; | |
413 heap_profiler_alloc((void*) (i * 32), 32, frames, 1, 0); | |
414 } | |
415 | |
416 CheckVMAvsStacktaceConsistency(); | |
417 // Check that we're saturating, otherwise this entire test is pointless. | |
418 EXPECT_LT(stats_.num_allocs, NUM_ALLOCS); | |
419 EXPECT_LT(stats_.num_stack_traces, NUM_ALLOCS); | |
420 | |
421 for (uintptr_t i = 0; i < NUM_ALLOCS; ++i) | |
422 heap_profiler_free((void*) (i * 32), 32, NULL); | |
423 | |
424 EXPECT_EQ(0, stats_.num_allocs); | |
425 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
426 EXPECT_EQ(0, stats_.num_stack_traces); | |
427 } | |
428 | |
429 #ifdef __LP64__ | |
430 TEST_F(HeapProfilerTest, Test64Bit) { | |
431 StackTrace st1 = GenStackTrace(8, 0x0); | |
432 StackTrace st2 = GenStackTrace(10, 0x7fffffff70000000LL); | |
433 StackTrace st3 = GenStackTrace(10, 0xffffffff70000000LL); | |
434 heap_profiler_alloc((void*) 0x1000, 4096, st1.frames, st1.depth, 0); | |
435 heap_profiler_alloc( | |
436 (void*) 0x7ffffffffffff000LL, 4096, st2.frames, st2.depth); | |
437 heap_profiler_alloc( | |
438 (void*) 0xfffffffffffff000LL, 4096, st3.frames, st3.depth); | |
439 EXPECT_EQ(3, stats_.num_allocs); | |
440 EXPECT_EQ(3, stats_.num_stack_traces); | |
441 EXPECT_EQ(4096 + 4096 + 4096, stats_.total_alloc_bytes); | |
442 | |
443 heap_profiler_free((void*) 0x1000, 4096, NULL); | |
444 EXPECT_EQ(2, stats_.num_allocs); | |
445 EXPECT_EQ(2, stats_.num_stack_traces); | |
446 EXPECT_EQ(4096 + 4096, stats_.total_alloc_bytes); | |
447 | |
448 heap_profiler_free((void*) 0x7ffffffffffff000LL, 4096, NULL); | |
449 EXPECT_EQ(1, stats_.num_allocs); | |
450 EXPECT_EQ(1, stats_.num_stack_traces); | |
451 EXPECT_EQ(4096, stats_.total_alloc_bytes); | |
452 | |
453 heap_profiler_free((void*) 0xfffffffffffff000LL, 4096, NULL); | |
454 EXPECT_EQ(0, stats_.num_allocs); | |
455 EXPECT_EQ(0, stats_.num_stack_traces); | |
456 EXPECT_EQ(0, stats_.total_alloc_bytes); | |
457 } | |
458 #endif | |
459 | |
460 } // namespace | |
461 | |
462 int main(int argc, char** argv) { | |
bulach
2014/06/25 11:19:33
nit: the main() for _unittest is normally on a sep
Primiano Tucci (use gerrit)
2014/06/26 09:00:54
Oh nice, I didn't know about the existence of that
| |
463 testing::InitGoogleTest(&argc, argv); | |
464 return RUN_ALL_TESTS(); | |
465 } | |
OLD | NEW |