Index: webrtc/test/fake_network_pipe_unittest.cc |
diff --git a/webrtc/test/fake_network_pipe_unittest.cc b/webrtc/test/fake_network_pipe_unittest.cc |
index 0bd46df7fcfdd71b8fd34793a0b6124027d61c3d..98fb8de6ad9016721dc6903376c2caf7a9bbe95f 100644 |
--- a/webrtc/test/fake_network_pipe_unittest.cc |
+++ b/webrtc/test/fake_network_pipe_unittest.cc |
@@ -379,4 +379,47 @@ TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { |
} |
EXPECT_TRUE(reordering_has_occured); |
} |
+ |
+TEST_F(FakeNetworkPipeTest, BurstLoss) { |
+ const int kLossPercent = 5; |
+ const int kAvgBurstLength = 3; |
+ const int kNumPackets = 10000; |
+ const int kPacketSize = 10; |
+ |
+ FakeNetworkPipe::Config config; |
+ config.queue_length_packets = kNumPackets; |
+ config.loss_percent = kLossPercent; |
+ config.avg_burst_loss_length = kAvgBurstLength; |
+ std::unique_ptr<FakeNetworkPipe> pipe( |
+ new FakeNetworkPipe(&fake_clock_, config)); |
+ ReorderTestReceiver* receiver = new ReorderTestReceiver(); |
+ receiver_.reset(receiver); |
+ pipe->SetReceiver(receiver_.get()); |
+ |
+ SendPackets(pipe.get(), kNumPackets, kPacketSize); |
+ fake_clock_.AdvanceTimeMilliseconds(1000); |
+ pipe->Process(); |
+ |
+ // Check that the average loss is |kLossPercent| percent. |
+ double loss_percent = |
terelius
2016/05/30 15:40:23
nit: maybe call it loss_fraction to make it clear
philipel
2016/05/30 16:05:40
Done.
|
+ (kNumPackets - receiver->delivered_sequence_numbers_.size()) / |
+ static_cast<double>(kNumPackets); |
+ |
+ EXPECT_NEAR(kLossPercent / 100.0, loss_percent, 0.01); |
terelius
2016/05/30 15:40:23
nit: 0.01 is the relative error, right? Seems rath
philipel
2016/05/30 16:05:40
It's a bit tight, adjusted it to 0.05. Also tried
|
+ |
+ // Find the number of bursts that has occurred. |
+ size_t received_packets = receiver->delivered_sequence_numbers_.size(); |
+ int num_bursts = 0; |
+ for (size_t i = 0; i < received_packets - 1; ++i) { |
+ int diff = receiver->delivered_sequence_numbers_[i + 1] - |
+ receiver->delivered_sequence_numbers_[i]; |
+ if (diff > 1) |
+ ++num_bursts; |
+ } |
+ |
+ int lost_packets = kNumPackets - receiver->delivered_sequence_numbers_.size(); |
terelius
2016/05/30 15:40:23
Move this up and reuse in computation of loss_perc
philipel
2016/05/30 16:05:39
Done.
|
+ double average_burst_length = static_cast<double>(lost_packets) / num_bursts; |
+ |
+ EXPECT_NEAR(kAvgBurstLength, average_burst_length, 0.2); |
+} |
} // namespace webrtc |