OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
| 11 #include <memory> |
| 12 |
11 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 #include "webrtc/base/scoped_ptr.h" | |
15 #include "webrtc/call.h" | 16 #include "webrtc/call.h" |
16 #include "webrtc/system_wrappers/include/clock.h" | 17 #include "webrtc/system_wrappers/include/clock.h" |
17 #include "webrtc/test/fake_network_pipe.h" | 18 #include "webrtc/test/fake_network_pipe.h" |
18 | 19 |
19 using ::testing::_; | 20 using ::testing::_; |
20 using ::testing::AnyNumber; | 21 using ::testing::AnyNumber; |
21 using ::testing::Return; | 22 using ::testing::Return; |
22 using ::testing::Invoke; | 23 using ::testing::Invoke; |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 receiver_.reset(new TestReceiver()); | 65 receiver_.reset(new TestReceiver()); |
65 ON_CALL(*receiver_, DeliverPacket(_, _, _, _)) | 66 ON_CALL(*receiver_, DeliverPacket(_, _, _, _)) |
66 .WillByDefault(Return(PacketReceiver::DELIVERY_OK)); | 67 .WillByDefault(Return(PacketReceiver::DELIVERY_OK)); |
67 } | 68 } |
68 | 69 |
69 virtual void TearDown() { | 70 virtual void TearDown() { |
70 } | 71 } |
71 | 72 |
72 void SendPackets(FakeNetworkPipe* pipe, int number_packets, int packet_size) { | 73 void SendPackets(FakeNetworkPipe* pipe, int number_packets, int packet_size) { |
73 RTC_DCHECK_GE(packet_size, static_cast<int>(sizeof(int))); | 74 RTC_DCHECK_GE(packet_size, static_cast<int>(sizeof(int))); |
74 rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[packet_size]); | 75 std::unique_ptr<uint8_t[]> packet(new uint8_t[packet_size]); |
75 for (int i = 0; i < number_packets; ++i) { | 76 for (int i = 0; i < number_packets; ++i) { |
76 // Set a sequence number for the packets by | 77 // Set a sequence number for the packets by |
77 // using the first bytes in the packet. | 78 // using the first bytes in the packet. |
78 memcpy(packet.get(), &i, sizeof(int)); | 79 memcpy(packet.get(), &i, sizeof(int)); |
79 pipe->SendPacket(packet.get(), packet_size); | 80 pipe->SendPacket(packet.get(), packet_size); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 int PacketTimeMs(int capacity_kbps, int packet_size) const { | 84 int PacketTimeMs(int capacity_kbps, int packet_size) const { |
84 return 8 * packet_size / capacity_kbps; | 85 return 8 * packet_size / capacity_kbps; |
85 } | 86 } |
86 | 87 |
87 SimulatedClock fake_clock_; | 88 SimulatedClock fake_clock_; |
88 rtc::scoped_ptr<TestReceiver> receiver_; | 89 std::unique_ptr<TestReceiver> receiver_; |
89 }; | 90 }; |
90 | 91 |
91 void DeleteMemory(uint8_t* data, int length) { delete [] data; } | 92 void DeleteMemory(uint8_t* data, int length) { delete [] data; } |
92 | 93 |
93 // Test the capacity link and verify we get as many packets as we expect. | 94 // Test the capacity link and verify we get as many packets as we expect. |
94 TEST_F(FakeNetworkPipeTest, CapacityTest) { | 95 TEST_F(FakeNetworkPipeTest, CapacityTest) { |
95 FakeNetworkPipe::Config config; | 96 FakeNetworkPipe::Config config; |
96 config.queue_length_packets = 20; | 97 config.queue_length_packets = 20; |
97 config.link_capacity_kbps = 80; | 98 config.link_capacity_kbps = 80; |
98 rtc::scoped_ptr<FakeNetworkPipe> pipe( | 99 std::unique_ptr<FakeNetworkPipe> pipe( |
99 new FakeNetworkPipe(&fake_clock_, config)); | 100 new FakeNetworkPipe(&fake_clock_, config)); |
100 pipe->SetReceiver(receiver_.get()); | 101 pipe->SetReceiver(receiver_.get()); |
101 | 102 |
102 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to | 103 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
103 // get through the pipe. | 104 // get through the pipe. |
104 const int kNumPackets = 10; | 105 const int kNumPackets = 10; |
105 const int kPacketSize = 1000; | 106 const int kPacketSize = 1000; |
106 SendPackets(pipe.get(), kNumPackets , kPacketSize); | 107 SendPackets(pipe.get(), kNumPackets , kPacketSize); |
107 | 108 |
108 // Time to get one packet through the link. | 109 // Time to get one packet through the link. |
(...skipping 19 matching lines...) Expand all Loading... |
128 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); | 129 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
129 pipe->Process(); | 130 pipe->Process(); |
130 } | 131 } |
131 | 132 |
132 // Test the extra network delay. | 133 // Test the extra network delay. |
133 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { | 134 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { |
134 FakeNetworkPipe::Config config; | 135 FakeNetworkPipe::Config config; |
135 config.queue_length_packets = 20; | 136 config.queue_length_packets = 20; |
136 config.queue_delay_ms = 100; | 137 config.queue_delay_ms = 100; |
137 config.link_capacity_kbps = 80; | 138 config.link_capacity_kbps = 80; |
138 rtc::scoped_ptr<FakeNetworkPipe> pipe( | 139 std::unique_ptr<FakeNetworkPipe> pipe( |
139 new FakeNetworkPipe(&fake_clock_, config)); | 140 new FakeNetworkPipe(&fake_clock_, config)); |
140 pipe->SetReceiver(receiver_.get()); | 141 pipe->SetReceiver(receiver_.get()); |
141 | 142 |
142 const int kNumPackets = 2; | 143 const int kNumPackets = 2; |
143 const int kPacketSize = 1000; | 144 const int kPacketSize = 1000; |
144 SendPackets(pipe.get(), kNumPackets , kPacketSize); | 145 SendPackets(pipe.get(), kNumPackets , kPacketSize); |
145 | 146 |
146 // Time to get one packet through the link. | 147 // Time to get one packet through the link. |
147 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 148 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
148 kPacketSize); | 149 kPacketSize); |
(...skipping 13 matching lines...) Expand all Loading... |
162 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); | 163 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); |
163 pipe->Process(); | 164 pipe->Process(); |
164 } | 165 } |
165 | 166 |
166 // Test the number of buffers and packets are dropped when sending too many | 167 // Test the number of buffers and packets are dropped when sending too many |
167 // packets too quickly. | 168 // packets too quickly. |
168 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { | 169 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { |
169 FakeNetworkPipe::Config config; | 170 FakeNetworkPipe::Config config; |
170 config.queue_length_packets = 2; | 171 config.queue_length_packets = 2; |
171 config.link_capacity_kbps = 80; | 172 config.link_capacity_kbps = 80; |
172 rtc::scoped_ptr<FakeNetworkPipe> pipe( | 173 std::unique_ptr<FakeNetworkPipe> pipe( |
173 new FakeNetworkPipe(&fake_clock_, config)); | 174 new FakeNetworkPipe(&fake_clock_, config)); |
174 pipe->SetReceiver(receiver_.get()); | 175 pipe->SetReceiver(receiver_.get()); |
175 | 176 |
176 const int kPacketSize = 1000; | 177 const int kPacketSize = 1000; |
177 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 178 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
178 kPacketSize); | 179 kPacketSize); |
179 | 180 |
180 // Send three packets and verify only 2 are delivered. | 181 // Send three packets and verify only 2 are delivered. |
181 SendPackets(pipe.get(), 3, kPacketSize); | 182 SendPackets(pipe.get(), 3, kPacketSize); |
182 | 183 |
183 // Increase time enough to deliver all three packets, verify only two are | 184 // Increase time enough to deliver all three packets, verify only two are |
184 // delivered. | 185 // delivered. |
185 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs); | 186 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs); |
186 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); | 187 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); |
187 pipe->Process(); | 188 pipe->Process(); |
188 } | 189 } |
189 | 190 |
190 // Test we get statistics as expected. | 191 // Test we get statistics as expected. |
191 TEST_F(FakeNetworkPipeTest, StatisticsTest) { | 192 TEST_F(FakeNetworkPipeTest, StatisticsTest) { |
192 FakeNetworkPipe::Config config; | 193 FakeNetworkPipe::Config config; |
193 config.queue_length_packets = 2; | 194 config.queue_length_packets = 2; |
194 config.queue_delay_ms = 20; | 195 config.queue_delay_ms = 20; |
195 config.link_capacity_kbps = 80; | 196 config.link_capacity_kbps = 80; |
196 rtc::scoped_ptr<FakeNetworkPipe> pipe( | 197 std::unique_ptr<FakeNetworkPipe> pipe( |
197 new FakeNetworkPipe(&fake_clock_, config)); | 198 new FakeNetworkPipe(&fake_clock_, config)); |
198 pipe->SetReceiver(receiver_.get()); | 199 pipe->SetReceiver(receiver_.get()); |
199 | 200 |
200 const int kPacketSize = 1000; | 201 const int kPacketSize = 1000; |
201 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, | 202 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
202 kPacketSize); | 203 kPacketSize); |
203 | 204 |
204 // Send three packets and verify only 2 are delivered. | 205 // Send three packets and verify only 2 are delivered. |
205 SendPackets(pipe.get(), 3, kPacketSize); | 206 SendPackets(pipe.get(), 3, kPacketSize); |
206 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs + | 207 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs + |
207 config.queue_delay_ms); | 208 config.queue_delay_ms); |
208 | 209 |
209 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); | 210 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); |
210 pipe->Process(); | 211 pipe->Process(); |
211 | 212 |
212 // Packet 1: kPacketTimeMs + config.queue_delay_ms, | 213 // Packet 1: kPacketTimeMs + config.queue_delay_ms, |
213 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. | 214 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. |
214 EXPECT_EQ(pipe->AverageDelay(), 170); | 215 EXPECT_EQ(pipe->AverageDelay(), 170); |
215 EXPECT_EQ(pipe->sent_packets(), 2u); | 216 EXPECT_EQ(pipe->sent_packets(), 2u); |
216 EXPECT_EQ(pipe->dropped_packets(), 1u); | 217 EXPECT_EQ(pipe->dropped_packets(), 1u); |
217 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); | 218 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); |
218 } | 219 } |
219 | 220 |
220 // Change the link capacity half-way through the test and verify that the | 221 // Change the link capacity half-way through the test and verify that the |
221 // delivery times change accordingly. | 222 // delivery times change accordingly. |
222 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { | 223 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { |
223 FakeNetworkPipe::Config config; | 224 FakeNetworkPipe::Config config; |
224 config.queue_length_packets = 20; | 225 config.queue_length_packets = 20; |
225 config.link_capacity_kbps = 80; | 226 config.link_capacity_kbps = 80; |
226 rtc::scoped_ptr<FakeNetworkPipe> pipe( | 227 std::unique_ptr<FakeNetworkPipe> pipe( |
227 new FakeNetworkPipe(&fake_clock_, config)); | 228 new FakeNetworkPipe(&fake_clock_, config)); |
228 pipe->SetReceiver(receiver_.get()); | 229 pipe->SetReceiver(receiver_.get()); |
229 | 230 |
230 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to | 231 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
231 // get through the pipe. | 232 // get through the pipe. |
232 const int kNumPackets = 10; | 233 const int kNumPackets = 10; |
233 const int kPacketSize = 1000; | 234 const int kPacketSize = 1000; |
234 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 235 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
235 | 236 |
236 // Time to get one packet through the link. | 237 // Time to get one packet through the link. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); | 276 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); |
276 pipe->Process(); | 277 pipe->Process(); |
277 } | 278 } |
278 | 279 |
279 // Change the link capacity half-way through the test and verify that the | 280 // Change the link capacity half-way through the test and verify that the |
280 // delivery times change accordingly. | 281 // delivery times change accordingly. |
281 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { | 282 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { |
282 FakeNetworkPipe::Config config; | 283 FakeNetworkPipe::Config config; |
283 config.queue_length_packets = 20; | 284 config.queue_length_packets = 20; |
284 config.link_capacity_kbps = 80; | 285 config.link_capacity_kbps = 80; |
285 rtc::scoped_ptr<FakeNetworkPipe> pipe( | 286 std::unique_ptr<FakeNetworkPipe> pipe( |
286 new FakeNetworkPipe(&fake_clock_, config)); | 287 new FakeNetworkPipe(&fake_clock_, config)); |
287 pipe->SetReceiver(receiver_.get()); | 288 pipe->SetReceiver(receiver_.get()); |
288 | 289 |
289 // Add 10 packets of 1000 bytes, = 80 kb. | 290 // Add 10 packets of 1000 bytes, = 80 kb. |
290 const int kNumPackets = 10; | 291 const int kNumPackets = 10; |
291 const int kPacketSize = 1000; | 292 const int kPacketSize = 1000; |
292 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 293 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
293 | 294 |
294 // Time to get one packet through the link at the initial speed. | 295 // Time to get one packet through the link at the initial speed. |
295 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); | 296 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 pipe->Process(); | 331 pipe->Process(); |
331 } | 332 } |
332 | 333 |
333 // At first disallow reordering and then allow reordering. | 334 // At first disallow reordering and then allow reordering. |
334 TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { | 335 TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { |
335 FakeNetworkPipe::Config config; | 336 FakeNetworkPipe::Config config; |
336 config.queue_length_packets = 1000; | 337 config.queue_length_packets = 1000; |
337 config.link_capacity_kbps = 800; | 338 config.link_capacity_kbps = 800; |
338 config.queue_delay_ms = 100; | 339 config.queue_delay_ms = 100; |
339 config.delay_standard_deviation_ms = 10; | 340 config.delay_standard_deviation_ms = 10; |
340 rtc::scoped_ptr<FakeNetworkPipe> pipe( | 341 std::unique_ptr<FakeNetworkPipe> pipe( |
341 new FakeNetworkPipe(&fake_clock_, config)); | 342 new FakeNetworkPipe(&fake_clock_, config)); |
342 ReorderTestReceiver* receiver = new ReorderTestReceiver(); | 343 ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
343 receiver_.reset(receiver); | 344 receiver_.reset(receiver); |
344 pipe->SetReceiver(receiver_.get()); | 345 pipe->SetReceiver(receiver_.get()); |
345 | 346 |
346 const uint32_t kNumPackets = 100; | 347 const uint32_t kNumPackets = 100; |
347 const int kPacketSize = 10; | 348 const int kPacketSize = 10; |
348 SendPackets(pipe.get(), kNumPackets, kPacketSize); | 349 SendPackets(pipe.get(), kNumPackets, kPacketSize); |
349 fake_clock_.AdvanceTimeMilliseconds(1000); | 350 fake_clock_.AdvanceTimeMilliseconds(1000); |
350 pipe->Process(); | 351 pipe->Process(); |
(...skipping 21 matching lines...) Expand all Loading... |
372 for (int seq_num : receiver->delivered_sequence_numbers_) { | 373 for (int seq_num : receiver->delivered_sequence_numbers_) { |
373 if (last_seq_num > seq_num) { | 374 if (last_seq_num > seq_num) { |
374 reordering_has_occured = true; | 375 reordering_has_occured = true; |
375 break; | 376 break; |
376 } | 377 } |
377 last_seq_num = seq_num; | 378 last_seq_num = seq_num; |
378 } | 379 } |
379 EXPECT_TRUE(reordering_has_occured); | 380 EXPECT_TRUE(reordering_has_occured); |
380 } | 381 } |
381 } // namespace webrtc | 382 } // namespace webrtc |
OLD | NEW |