Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / third_party / tcmalloc / chromium / src / tests / page_heap_test.cc
blob9f5f3c87f8097023b98a8a0fd7299e68edec92f9
1 // Copyright 2009 Google Inc. All Rights Reserved.
2 // Author: fikes@google.com (Andrew Fikes)
4 #include "config_for_unittests.h"
5 #include "page_heap.h"
6 #include <stdio.h>
7 #include "base/logging.h"
8 #include "common.h"
10 namespace {
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);
22 static void TestPageHeap_Stats() {
23 tcmalloc::PageHeap* ph = new tcmalloc::PageHeap();
25 // Empty page heap
26 CheckStats(ph, 0, 0, 0);
28 // Allocate a span 's1'
29 tcmalloc::Span* s1 = ph->New(256);
30 CheckStats(ph, 256, 0, 0);
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);
38 // Unmap deleted span 's2'
39 EXPECT_EQ(s2_len, ph->ReleaseAtLeastNPages(1));
40 CheckStats(ph, 256, 0, 128);
42 // Delete span 's1'
43 ph->Delete(s1);
44 CheckStats(ph, 256, 128, 128);
46 delete ph;
49 } // namespace
51 int main(int argc, char **argv) {
52 TestPageHeap_Stats();
53 printf("PASS\n");
54 return 0;