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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/bwe_unittest.cc

Issue 1202253003: More Simulation Framework features (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed [6] Created 5 years, 5 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 "webrtc/modules/remote_bitrate_estimator/test/bwe.h"
12
13 #include <vector>
14
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace webrtc {
18 namespace testing {
19 namespace bwe {
20
21 const int kSetCapacity = 10000;
22
23 class LinkedSetTest : public ::testing::Test {
24 public:
25 LinkedSetTest() : linked_set_(kSetCapacity) {}
26
27 ~LinkedSetTest() {}
28
29 protected:
30 LinkedSet linked_set_;
31 };
32
33 TEST_F(LinkedSetTest, EmptySet) {
34 EXPECT_EQ(linked_set_.OldestSeqNumber(), 0);
35 EXPECT_EQ(linked_set_.NewestSeqNumber(), 0);
36 }
37
38 TEST_F(LinkedSetTest, SinglePacket) {
39 const uint16_t kSeqNumber = 1; // Arbitrary.
40 // Other parameters don't matter here.
41 linked_set_.Insert(kSeqNumber, 0, 0, 0);
42
43 EXPECT_EQ(linked_set_.OldestSeqNumber(), kSeqNumber);
44 EXPECT_EQ(linked_set_.NewestSeqNumber(), kSeqNumber);
45 }
46
47 TEST_F(LinkedSetTest, MultiplePackets) {
48 const uint16_t kNumberPackets = 100;
49
50 std::vector<uint16_t> sequence_numbers;
51 for (size_t i = 0; i < kNumberPackets; ++i) {
52 sequence_numbers.push_back(static_cast<uint16_t>(i + 1));
53 }
54 random_shuffle(sequence_numbers.begin(), sequence_numbers.end());
55
56 for (size_t i = 0; i < kNumberPackets; ++i) {
57 // Other parameters don't matter here.
58 linked_set_.Insert(static_cast<uint16_t>(i), 0, 0, 0);
59 }
60
61 // Packets arriving out of order should not affect the following values:
62 EXPECT_EQ(linked_set_.OldestSeqNumber(), 0);
63 EXPECT_EQ(linked_set_.NewestSeqNumber(), kNumberPackets - 1);
64 }
65
66 TEST_F(LinkedSetTest, Overflow) {
67 const int kFirstSeqNumber = -100;
68 const int kLastSeqNumber = 100;
69
70 for (int i = kFirstSeqNumber; i <= kLastSeqNumber; ++i) {
71 // Other parameters don't matter here.
72 linked_set_.Insert(static_cast<uint16_t>(i), 0, 0, 0);
73 }
74
75 // Packets arriving out of order should not affect the following values:
76 EXPECT_EQ(linked_set_.OldestSeqNumber(),
77 static_cast<uint16_t>(kFirstSeqNumber));
78 EXPECT_EQ(linked_set_.NewestSeqNumber(),
79 static_cast<uint16_t>(kLastSeqNumber));
80 }
81
82 class SequenceNumberOlderThanTest : public ::testing::Test {
83 public:
84 SequenceNumberOlderThanTest() {}
85 ~SequenceNumberOlderThanTest() {}
86
87 protected:
88 SequenceNumberOlderThan comparator_;
89 };
90
91 TEST_F(SequenceNumberOlderThanTest, Operator) {
92 // Operator()(x, y) returns true <==> y is newer than x.
93 EXPECT_TRUE(comparator_.operator()(0x0000, 0x0001));
94 EXPECT_TRUE(comparator_.operator()(0x0001, 0x1000));
95 EXPECT_FALSE(comparator_.operator()(0x0001, 0x0000));
96 EXPECT_FALSE(comparator_.operator()(0x0002, 0x0002));
97 EXPECT_TRUE(comparator_.operator()(0xFFF6, 0x000A));
98 EXPECT_FALSE(comparator_.operator()(0x000A, 0xFFF6));
99 EXPECT_TRUE(comparator_.operator()(0x0000, 0x8000));
100 EXPECT_FALSE(comparator_.operator()(0x8000, 0x0000));
101 }
102
103 class LossAccountTest : public ::testing::Test {
104 public:
105 LossAccountTest() {}
106 ~LossAccountTest() {}
107
108 protected:
109 LossAccount loss_account_;
110 };
111
112 TEST_F(LossAccountTest, Operations) {
113 const size_t kTotal = 100; // Arbitrary values.
114 const size_t kLost = 10;
115
116 LossAccount rhs(kTotal, kLost);
117
118 loss_account_.Add(rhs);
119 EXPECT_EQ(loss_account_.num_total, kTotal);
120 EXPECT_EQ(loss_account_.num_lost, kLost);
121 EXPECT_NEAR(loss_account_.LossRatio(), static_cast<float>(kLost) / kTotal,
122 0.001f);
123
124 loss_account_.Subtract(rhs);
125 EXPECT_EQ(loss_account_.num_total, 0UL);
126 EXPECT_EQ(loss_account_.num_lost, 0UL);
127 EXPECT_NEAR(loss_account_.LossRatio(), 0.0f, 0.001f);
128 }
129
130 const int kFlowId = 1; // Arbitrary.
131
132 class BweReceiverTest : public ::testing::Test {
133 public:
134 BweReceiverTest() : bwe_receiver_(kFlowId) {}
135 ~BweReceiverTest() {}
136
137 protected:
138 BweReceiver bwe_receiver_;
139 };
140
141 TEST_F(BweReceiverTest, RecentKbps) {
142 EXPECT_EQ(bwe_receiver_.RecentKbps(), 0U);
143
144 const size_t kPacketSizeBytes = 1200;
145 const int kNumPackets = 100;
146
147 double window_size_s = bwe_receiver_.BitrateWindowS();
148
149 // Receive packets at the same time.
150 for (int i = 0; i < kNumPackets; ++i) {
151 MediaPacket packet(kFlowId, 0L, kPacketSizeBytes, static_cast<uint16_t>(i));
152 bwe_receiver_.ReceivePacket(0, packet);
153 }
154
155 EXPECT_NEAR(bwe_receiver_.RecentKbps(),
156 (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s),
157 10);
158
159 int64_t time_gap_ms =
160 2 * 1000 * window_size_s; // Larger than rate_counter time window.
161
162 MediaPacket packet(kFlowId, time_gap_ms * 1000, kPacketSizeBytes,
163 static_cast<uint16_t>(kNumPackets));
164 bwe_receiver_.ReceivePacket(time_gap_ms, packet);
165
166 EXPECT_NEAR(bwe_receiver_.RecentKbps(),
167 (8 * kPacketSizeBytes) / (1000 * window_size_s), 10);
168 }
169
170 TEST_F(BweReceiverTest, Loss) {
171 EXPECT_NEAR(bwe_receiver_.GlobalReceiverPacketLossRatio(), 0.0f, 0.001f);
172
173 LossAccount loss_account = bwe_receiver_.LinkedSetPacketLossRatio();
174 EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f);
175
176 // Insert packets 1-50 and 151-200;
177 for (int i = 1; i <= 200; ++i) {
178 // Packet size and timestamp do not matter here.
179 MediaPacket packet(kFlowId, 0L, 0UL, static_cast<uint16_t>(i));
180 bwe_receiver_.ReceivePacket(0, packet);
181 if (i == 50) {
182 i += 100;
183 }
184 }
185
186 loss_account = bwe_receiver_.LinkedSetPacketLossRatio();
187 EXPECT_NEAR(loss_account.LossRatio(), 0.5f, 0.001f);
188
189 bwe_receiver_.RelieveSetAndUpdateLoss();
190 EXPECT_EQ(bwe_receiver_.received_packets_.size(), 100U / 10);
191
192 // No packet loss within the preserved packets.
193 loss_account = bwe_receiver_.LinkedSetPacketLossRatio();
194 EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f);
195
196 // RelieveSetAndUpdateLoss automatically updates loss account.
197 EXPECT_NEAR(bwe_receiver_.GlobalReceiverPacketLossRatio(), 0.5f, 0.001f);
198 }
199
200 } // namespace bwe
201 } // namespace testing
202 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698