- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / tcmalloc / chromium / src / tests / page_heap_test.cc
1 // Copyright 2009 Google Inc. All Rights Reserved.
2 // Author: fikes@google.com (Andrew Fikes)
3
4 #include "config_for_unittests.h"
5 #include "page_heap.h"
6 #include <stdio.h>
7 #include "base/logging.h"
8 #include "common.h"
9
10 namespace {
11
12 static void CheckStats(const tcmalloc::PageHeap* ph,
13                        uint64_t system_pages,
14                        uint64_t free_pages,
15                        uint64_t unmapped_pages) {
16   tcmalloc::PageHeap::Stats stats = ph->stats();
17   EXPECT_EQ(system_pages, stats.system_bytes >> kPageShift);
18   EXPECT_EQ(free_pages, stats.free_bytes >> kPageShift);
19   EXPECT_EQ(unmapped_pages, stats.unmapped_bytes >> kPageShift);
20 }
21
22 static void TestPageHeap_Stats() {
23   tcmalloc::PageHeap* ph = new tcmalloc::PageHeap();
24
25   // Empty page heap
26   CheckStats(ph, 0, 0, 0);
27
28   // Allocate a span 's1'
29   tcmalloc::Span* s1 = ph->New(256);
30   CheckStats(ph, 256, 0, 0);
31
32   // Split span 's1' into 's1', 's2'.  Delete 's2'
33   tcmalloc::Span* s2 = ph->Split(s1, 128);
34   Length s2_len = s2->length;
35   ph->Delete(s2);
36   CheckStats(ph, 256, 128, 0);
37
38   // Unmap deleted span 's2'
39   EXPECT_EQ(s2_len, ph->ReleaseAtLeastNPages(1));
40   CheckStats(ph, 256, 0, 128);
41
42   // Delete span 's1'
43   ph->Delete(s1);
44   CheckStats(ph, 256, 128, 128);
45
46   delete ph;
47 }
48
49 }  // namespace
50
51 int main(int argc, char **argv) {
52   TestPageHeap_Stats();
53   printf("PASS\n");
54   return 0;
55 }