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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/packet_loss_stats_unittest.cc

Issue 1198853004: Add statistics gathering for packet loss. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/modules/rtp_rtcp/source/packet_loss_stats.h"
13
14 namespace webrtc {
15
16 class PacketLossStatsTest : public ::testing::Test {
17 protected:
18 PacketLossStats stats_;
19 };
20
21 // Add a lost packet as every other packet, they should all count as single
22 // losses.
23 TEST_F(PacketLossStatsTest, EveryOtherPacket) {
24 for (int i = 0; i < 1000; i += 2) {
25 stats_.AddLostPacket(i);
26 }
27 EXPECT_EQ(500, stats_.GetSingleLossCount());
28 EXPECT_EQ(0, stats_.GetMultipleLossEventCount());
29 EXPECT_EQ(0, stats_.GetMultipleLossPacketCount());
30 }
31
32 // Add a lost packet as every other packet, but such that the sequence numbers
33 // will wrap around while they are being added.
34 TEST_F(PacketLossStatsTest, EveryOtherPacketWrapped) {
35 for (int i = 65500; i < 66500; i += 2) {
36 stats_.AddLostPacket(i & 0xFFFF);
noahric 2015/06/26 00:21:19 Consider adding a CHECK or DCHECK in AddLostPacket
bcornell 2015/06/30 19:47:45 AddLostPacket takes a uint16_t, I just like to be
37 }
38 EXPECT_EQ(500, stats_.GetSingleLossCount());
39 EXPECT_EQ(0, stats_.GetMultipleLossEventCount());
40 EXPECT_EQ(0, stats_.GetMultipleLossPacketCount());
41 }
42
43 // Add a lost packet as every other packet, but such that the sequence numbers
44 // will wrap around close to the very end, such that the buffer contains packets
45 // on either side of the wrapping.
46 TEST_F(PacketLossStatsTest, EveryOtherPacketWrappedAtEnd) {
47 for (int i = 64600; i < 65600; i += 2) {
48 stats_.AddLostPacket(i & 0xFFFF);
49 }
50 EXPECT_EQ(500, stats_.GetSingleLossCount());
51 EXPECT_EQ(0, stats_.GetMultipleLossEventCount());
52 EXPECT_EQ(0, stats_.GetMultipleLossPacketCount());
53 }
54
55 // Add a lost packet as the first three of every eight packets. Each set of
56 // three should count as a multiple loss event and three multiple loss packets.
57 TEST_F(PacketLossStatsTest, FirstThreeOfEight) {
58 for (int i = 0; i < 1000; ++i) {
59 if ((i & 7) < 3) {
60 stats_.AddLostPacket(i);
61 }
62 }
63 EXPECT_EQ(0, stats_.GetSingleLossCount());
64 EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
65 EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
66 }
67
68 // Add a lost packet as the first three of every eight packets such that the
69 // sequence numbers wrap in the middle of adding them.
70 TEST_F(PacketLossStatsTest, FirstThreeOfEightWrapped) {
71 for (int i = 65500; i < 66500; ++i) {
72 if ((i & 7) < 3) {
73 stats_.AddLostPacket(i & 0xFFFF);
74 }
75 }
76 EXPECT_EQ(0, stats_.GetSingleLossCount());
77 EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
78 EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
79 }
80
81 // Add a lost packet as the first three of every eight packets such that the
82 // sequence numbers wrap near the end of adding them and there are still numbers
83 // in the buffer from before the wrapping.
84 TEST_F(PacketLossStatsTest, FirstThreeOfEightWrappedAtEnd) {
85 for (int i = 64600; i < 65600; ++i) {
86 if ((i & 7) < 3) {
87 stats_.AddLostPacket(i & 0xFFFF);
88 }
89 }
90 EXPECT_EQ(0, stats_.GetSingleLossCount());
91 EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
92 EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
93 }
94
95 // Add loss packets as the first three and the fifth of every eight packets. The
96 // set of three should be multiple loss and the fifth should be single loss.
97 TEST_F(PacketLossStatsTest, FirstThreeAndFifthOfEight) {
98 for (int i = 0; i < 1000; ++i) {
99 if ((i & 7) < 3 || (i & 7) == 4) {
100 stats_.AddLostPacket(i);
101 }
102 }
103 EXPECT_EQ(125, stats_.GetSingleLossCount());
104 EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
105 EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
106 }
107
108 // Add loss packets as the first three and the fifth of every eight packets such
109 // that the sequence numbers wrap in the middle of adding them.
110 TEST_F(PacketLossStatsTest, FirstThreeAndFifthOfEightWrapped) {
111 for (int i = 65500; i < 66500; ++i) {
112 if ((i & 7) < 3 || (i & 7) == 4) {
113 stats_.AddLostPacket(i & 0xFFFF);
114 }
115 }
116 EXPECT_EQ(125, stats_.GetSingleLossCount());
117 EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
118 EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
119 }
120
121 // Add loss packets as the first three and the fifth of every eight packets such
122 // that the sequence numbers wrap near the end of adding them and there are
123 // packets from before the wrapping still in the buffer.
124 TEST_F(PacketLossStatsTest, FirstThreeAndFifthOfEightWrappedAtEnd) {
125 for (int i = 64600; i < 65600; ++i) {
126 if ((i & 7) < 3 || (i & 7) == 4) {
127 stats_.AddLostPacket(i & 0xFFFF);
128 }
129 }
130 EXPECT_EQ(125, stats_.GetSingleLossCount());
131 EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
132 EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
133 }
134
135 // Add loss packets such that there is a multiple loss event that continues
136 // around the wrapping of sequence numbers.
137 TEST_F(PacketLossStatsTest, MultipleLossEventWrapped) {
138 for (int i = 60000; i < 60500; i += 2) {
139 stats_.AddLostPacket(i);
140 }
141 for (int i = 65530; i < 65540; ++i) {
142 stats_.AddLostPacket(i & 0xFFFF);
143 }
144 EXPECT_EQ(250, stats_.GetSingleLossCount());
145 EXPECT_EQ(1, stats_.GetMultipleLossEventCount());
146 EXPECT_EQ(10, stats_.GetMultipleLossPacketCount());
147 }
148
149 // Add loss packets such that there is a multiple loss event that continues
150 // around the wrapping of sequence numbers and then is pushed out of the buffer.
151 TEST_F(PacketLossStatsTest, MultipleLossEventWrappedPushedOut) {
152 for (int i = 60000; i < 60500; i += 2) {
153 stats_.AddLostPacket(i);
154 }
155 for (int i = 65530; i < 65540; ++i) {
156 stats_.AddLostPacket(i & 0xFFFF);
157 }
158 for (int i = 1000; i < 1500; i += 2) {
159 stats_.AddLostPacket(i);
160 }
161 EXPECT_EQ(500, stats_.GetSingleLossCount());
162 EXPECT_EQ(1, stats_.GetMultipleLossEventCount());
163 EXPECT_EQ(10, stats_.GetMultipleLossPacketCount());
164 }
165
166 // Add loss packets out of order and ensure that they still get counted
167 // correctly as single or multiple loss events.
168 TEST_F(PacketLossStatsTest, OutOfOrder) {
169 for (int i = 0; i < 1000; i += 10) {
170 stats_.AddLostPacket(i + 5);
171 stats_.AddLostPacket(i + 7);
172 stats_.AddLostPacket(i + 4);
173 stats_.AddLostPacket(i + 1);
174 stats_.AddLostPacket(i + 2);
175 }
176 EXPECT_EQ(100, stats_.GetSingleLossCount());
177 EXPECT_EQ(200, stats_.GetMultipleLossEventCount());
178 EXPECT_EQ(400, stats_.GetMultipleLossPacketCount());
179 }
180
181 // Add loss packets out of order and ensure that they still get counted
182 // correctly as single or multiple loss events, and wrap in the middle of
183 // adding.
184 TEST_F(PacketLossStatsTest, OutOfOrderWrapped) {
185 for (int i = 65000; i < 66000; i += 10) {
186 stats_.AddLostPacket((i + 5) & 0xFFFF);
187 stats_.AddLostPacket((i + 7) & 0xFFFF);
188 stats_.AddLostPacket((i + 4) & 0xFFFF);
189 stats_.AddLostPacket((i + 1) & 0xFFFF);
190 stats_.AddLostPacket((i + 2) & 0xFFFF);
191 }
192 EXPECT_EQ(100, stats_.GetSingleLossCount());
193 EXPECT_EQ(200, stats_.GetMultipleLossEventCount());
194 EXPECT_EQ(400, stats_.GetMultipleLossPacketCount());
195 }
196
197 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698