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

Side by Side Diff: src/common/memory_unittest.cc

Issue 1688743002: Switch the Linux minidump writer to use MDCVInfoELF for CV data. (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: Rework to handle arbitrary size build ids Created 4 years, 8 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
« no previous file with comments | « src/common/memory.h ('k') | src/processor/minidump_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 #include "common/memory.h" 31 #include "common/memory.h"
32 32
33 using namespace google_breakpad; 33 using namespace google_breakpad;
34 34
35 namespace { 35 namespace {
36 typedef testing::Test PageAllocatorTest; 36 typedef testing::Test PageAllocatorTest;
37 } 37 }
38 38
39 TEST(PageAllocatorTest, Setup) { 39 TEST(PageAllocatorTest, Setup) {
40 PageAllocator allocator; 40 PageAllocator allocator;
41 EXPECT_EQ(0, allocator.pages_allocated());
41 } 42 }
42 43
43 TEST(PageAllocatorTest, SmallObjects) { 44 TEST(PageAllocatorTest, SmallObjects) {
44 PageAllocator allocator; 45 PageAllocator allocator;
45 46
47 EXPECT_EQ(0, allocator.pages_allocated());
46 for (unsigned i = 1; i < 1024; ++i) { 48 for (unsigned i = 1; i < 1024; ++i) {
47 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i)); 49 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i));
48 ASSERT_FALSE(p == NULL); 50 ASSERT_FALSE(p == NULL);
49 memset(p, 0, i); 51 memset(p, 0, i);
50 } 52 }
51 } 53 }
52 54
53 TEST(PageAllocatorTest, LargeObject) { 55 TEST(PageAllocatorTest, LargeObject) {
54 PageAllocator allocator; 56 PageAllocator allocator;
55 57
58 EXPECT_EQ(0, allocator.pages_allocated());
56 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(10000)); 59 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(10000));
57 ASSERT_FALSE(p == NULL); 60 ASSERT_FALSE(p == NULL);
61 EXPECT_EQ(3, allocator.pages_allocated());
58 for (unsigned i = 1; i < 10; ++i) { 62 for (unsigned i = 1; i < 10; ++i) {
59 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i)); 63 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i));
60 ASSERT_FALSE(p == NULL); 64 ASSERT_FALSE(p == NULL);
61 memset(p, 0, i); 65 memset(p, 0, i);
62 } 66 }
63 } 67 }
64 68
65 namespace { 69 namespace {
66 typedef testing::Test WastefulVectorTest; 70 typedef testing::Test WastefulVectorTest;
67 } 71 }
68 72
69 TEST(WastefulVectorTest, Setup) { 73 TEST(WastefulVectorTest, Setup) {
70 PageAllocator allocator_; 74 PageAllocator allocator_;
71 wasteful_vector<int> v(&allocator_); 75 wasteful_vector<int> v(&allocator_);
72 ASSERT_TRUE(v.empty()); 76 ASSERT_TRUE(v.empty());
73 ASSERT_EQ(v.size(), 0u); 77 ASSERT_EQ(v.size(), 0u);
74 } 78 }
75 79
76 TEST(WastefulVectorTest, Simple) { 80 TEST(WastefulVectorTest, Simple) {
77 PageAllocator allocator_; 81 PageAllocator allocator_;
82 EXPECT_EQ(0, allocator_.pages_allocated());
78 wasteful_vector<unsigned> v(&allocator_); 83 wasteful_vector<unsigned> v(&allocator_);
79 84
80 for (unsigned i = 0; i < 256; ++i) { 85 for (unsigned i = 0; i < 256; ++i) {
81 v.push_back(i); 86 v.push_back(i);
82 ASSERT_EQ(i, v.back()); 87 ASSERT_EQ(i, v.back());
83 ASSERT_EQ(&v.back(), &v[i]); 88 ASSERT_EQ(&v.back(), &v[i]);
84 } 89 }
85 ASSERT_FALSE(v.empty()); 90 ASSERT_FALSE(v.empty());
86 ASSERT_EQ(v.size(), 256u); 91 ASSERT_EQ(v.size(), 256u);
92 EXPECT_EQ(1, allocator_.pages_allocated());
87 for (unsigned i = 0; i < 256; ++i) 93 for (unsigned i = 0; i < 256; ++i)
88 ASSERT_EQ(v[i], i); 94 ASSERT_EQ(v[i], i);
89 } 95 }
90 96
91 TEST(WastefulVectorTest, UsesPageAllocator) { 97 TEST(WastefulVectorTest, UsesPageAllocator) {
92 PageAllocator allocator_; 98 PageAllocator allocator_;
93 wasteful_vector<unsigned> v(&allocator_); 99 wasteful_vector<unsigned> v(&allocator_);
100 EXPECT_EQ(1, allocator_.pages_allocated());
94 101
95 v.push_back(1); 102 v.push_back(1);
96 ASSERT_TRUE(allocator_.OwnsPointer(&v[0])); 103 ASSERT_TRUE(allocator_.OwnsPointer(&v[0]));
97 } 104 }
105
106 TEST(WastefulVectorTest, AutoWastefulVector) {
107 PageAllocator allocator_;
108 EXPECT_EQ(0, allocator_.pages_allocated());
109
110 auto_wasteful_vector<unsigned, 4> v(&allocator_);
111 EXPECT_EQ(0, allocator_.pages_allocated());
112
113 v.push_back(1);
114 EXPECT_EQ(0, allocator_.pages_allocated());
115 EXPECT_FALSE(allocator_.OwnsPointer(&v[0]));
116
117 v.resize(4);
118 EXPECT_EQ(0, allocator_.pages_allocated());
119 EXPECT_FALSE(allocator_.OwnsPointer(&v[0]));
120
121 v.resize(10);
122 EXPECT_EQ(1, allocator_.pages_allocated());
123 EXPECT_TRUE(allocator_.OwnsPointer(&v[0]));
124 }
OLDNEW
« no previous file with comments | « src/common/memory.h ('k') | src/processor/minidump_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698