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

Side by Side Diff: net/quic/quic_buffer_pool_test.cc

Issue 1577473002: relnote: QUIC streamable frames can now use a freelist for their packet buffers, Guarded by gfe2_fe… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@19_CL_111440524
Patch Set: cast to size_t Created 4 years, 11 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 | « net/quic/quic_buffer_pool.h ('k') | net/quic/quic_chromium_connection_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 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 "net/quic/quic_buffer_pool.h"
6
7 #include "net/test/gtest_util.h"
8
9 namespace net {
10
11 class QuicBufferPoolTest : public ::testing::Test {
12 public:
13 template <typename BufferPool>
14 static int GetMaxRegion(const BufferPool& pool) {
15 return pool.max_region_;
16 }
17 };
18
19 TEST_F(QuicBufferPoolTest, NewDelete) {
20 QuicBufferPool<1024, 1> l;
21
22 char* b1 = l.New(1024);
23 char* b2 = l.New(1024);
24 char* b3 = l.New(1024);
25
26 ASSERT_NE(nullptr, b1);
27 ASSERT_NE(nullptr, b2);
28 ASSERT_NE(nullptr, b3);
29
30 l.Delete(b3);
31
32 char* b4 = l.New(1024);
33 // Should reuse b3.
34 EXPECT_EQ(b4, b3);
35
36 l.Delete(b1);
37 l.Delete(b2);
38
39 char* b5 = l.New(1024);
40 // Should reuse b2.
41 EXPECT_EQ(b5, b2);
42
43 char* b6 = l.New(1024);
44 // Should reuse b1.
45 EXPECT_EQ(b6, b1);
46
47 l.Delete(b4);
48 l.Delete(b5);
49 l.Delete(b6);
50
51 EXPECT_EQ(1, GetMaxRegion(l));
52 }
53
54 TEST_F(QuicBufferPoolTest, OutstandingAllocations) {
55 scoped_ptr<QuicBufferPool<1024, 1>> l(new QuicBufferPool<1024, 1>());
56 l->New(1024);
57 EXPECT_DFATAL(l.reset(), "unfreed allocations");
58 }
59
60 TEST_F(QuicBufferPoolTest, HugeBuffer) {
61 QuicBufferPool<1024 * 1024, 1> l;
62 char* b1 = l.New(1024 * 1024);
63 char* b2 = l.New(1024 * 1024);
64 char* b3 = l.New(1024 * 1024);
65
66 ASSERT_NE(nullptr, b1);
67 ASSERT_NE(nullptr, b2);
68 ASSERT_NE(nullptr, b3);
69
70 l.Delete(b3);
71 l.Delete(b2);
72 l.Delete(b1);
73
74 char* b4 = l.New(1024 * 1024);
75 // Should reuse b1.
76 EXPECT_EQ(b4, b1);
77
78 l.Delete(b4);
79 EXPECT_EQ(1, GetMaxRegion(l));
80 }
81
82 TEST_F(QuicBufferPoolTest, DeleteNull) {
83 QuicBufferPool<1024, 1> l;
84 l.Delete(nullptr);
85 EXPECT_EQ(0, GetMaxRegion(l));
86 }
87
88 TEST_F(QuicBufferPoolTest, Saturate) {
89 QuicBufferPool<1024 * 1024, 3, 2 * 1024 * 1024> l;
90 std::vector<char*> buffers;
91 for (int i = 0; i < 3; ++i) {
92 buffers.push_back(l.New(1024 * 1024));
93 ASSERT_NE(nullptr, buffers.back());
94 }
95 for (int i = 0; i < 2; ++i) {
96 EXPECT_DFATAL(buffers.push_back(l.New(1024 * 1024)),
97 "Ran out of room in QuicBufferPool");
98 }
99 for (char* buffer : buffers) {
100 l.Delete(buffer);
101 }
102 EXPECT_EQ(1, GetMaxRegion(l));
103 }
104
105 TEST_F(QuicBufferPoolTest, Flaggable) {
106 QuicBufferPool<1024, 1> l;
107 char* b1 = l.New(1024);
108 ASSERT_NE(nullptr, b1);
109 l.Delete(b1);
110
111 // Flagged on should return b1.
112 ASSERT_EQ(b1, l.New(1024, true));
113 l.Delete(b1);
114
115 // Flagged off should not return b1.
116 char* b2 = l.New(1024, false);
117 ASSERT_NE(b2, b1);
118 l.Delete(b2);
119 EXPECT_EQ(1, GetMaxRegion(l));
120 }
121
122 TEST_F(QuicBufferPoolTest, OverSized) {
123 QuicBufferPool<1024, 1> l;
124 char* b1 = nullptr;
125 EXPECT_DFATAL(b1 = l.New(2 * 1024 * 1024), "greater than pool buffer size");
126 ASSERT_NE(nullptr, b1);
127 l.Delete(b1);
128 EXPECT_EQ(0, GetMaxRegion(l));
129 }
130
131 TEST_F(QuicBufferPoolTest, ReleaseReuse) {
132 QuicBufferPool<1024, 1> l;
133 char* b1 = l.New(1024);
134 ASSERT_NE(nullptr, b1);
135
136 // This should have no effect.
137 l.MarkAllocatorIdle();
138 EXPECT_EQ(1, GetMaxRegion(l));
139
140 l.Delete(b1);
141
142 // There should still be one region left.
143 EXPECT_EQ(1, GetMaxRegion(l));
144
145 l.MarkAllocatorIdle();
146 // After the allocator is marked as idle, with no allocations pending, the
147 // allocator should not take up any space.
148 EXPECT_EQ(0, GetMaxRegion(l));
149
150 // The allocator should still work after though.
151 char* b2 = l.New(1024);
152 ASSERT_NE(nullptr, b2);
153 l.Delete(b2);
154
155 EXPECT_EQ(1, GetMaxRegion(l));
156 }
157
158 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_buffer_pool.h ('k') | net/quic/quic_chromium_connection_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698