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

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: Added unittests 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 ~LinkedSetTest() {}
27
28 protected:
29 LinkedSet linked_set_;
30 };
31
32 TEST_F(LinkedSetTest, EmptySet) {
33 EXPECT_EQ(linked_set_.OldestSeqNumber(), 0);
34 EXPECT_EQ(linked_set_.NewestSeqNumber(), 0);
35 }
36
37 TEST_F(LinkedSetTest, SinglePacket) {
38 const uint16_t kSeqNumber = 1; // Arbitrary.
39 // Other parameters don't matter here.
40 linked_set_.Insert(kSeqNumber, 0, 0, 0);
41 EXPECT_EQ(linked_set_.OldestSeqNumber(), kSeqNumber);
42 EXPECT_EQ(linked_set_.NewestSeqNumber(), kSeqNumber);
43 }
44
45 TEST_F(LinkedSetTest, MultiplePackets) {
46 const uint16_t kNumberPackets = 100;
47
48 std::vector<uint16_t> sequence_numbers;
49 for (size_t i = 0; i < kNumberPackets; ++i) {
50 sequence_numbers.push_back(static_cast<uint16_t>(i + 1));
51 }
52 random_shuffle(sequence_numbers.begin(), sequence_numbers.end());
53
54 for (size_t i = 0; i < kNumberPackets; ++i) {
55 // Other parameters don't matter here.
56 linked_set_.Insert(static_cast<uint16_t>(i), 0, 0, 0);
57 }
58
59 // Packets arriving out of order should not affect the following values:
60 EXPECT_EQ(linked_set_.OldestSeqNumber(), 0);
61 EXPECT_EQ(linked_set_.NewestSeqNumber(), kNumberPackets - 1);
62 }
63
64 TEST_F(LinkedSetTest, Overflow) {
65 const int kFirstSeqNumber = -100;
66 const int kLastSeqNumber = 100;
67
68 for (int i = kFirstSeqNumber; i <= kLastSeqNumber; ++i) {
69 // Other parameters don't matter here.
70 linked_set_.Insert(static_cast<uint16_t>(i), 0, 0, 0);
71 }
72
73 // Packets arriving out of order should not affect the following values:
74 EXPECT_EQ(linked_set_.OldestSeqNumber(),
75 static_cast<uint16_t>(kFirstSeqNumber));
76 EXPECT_EQ(linked_set_.NewestSeqNumber(),
77 static_cast<uint16_t>(kLastSeqNumber));
78 }
79
80 class SequenceNumberOlderThanTest : public ::testing::Test {
81 public:
82 SequenceNumberOlderThanTest() {}
83 ~SequenceNumberOlderThanTest() {}
84
85 protected:
86 SequenceNumberOlderThan comparator_;
87 };
88
89 TEST_F(SequenceNumberOlderThanTest, Operator) {
90 // Operator()(x, y) returns true <==> y is newer than x.
91 EXPECT_TRUE(comparator_.operator()(0, 1));
92 EXPECT_TRUE(comparator_.operator()(1, 1000));
93 EXPECT_FALSE(comparator_.operator()(1, 0));
94 EXPECT_FALSE(comparator_.operator()(2, 2));
95 EXPECT_TRUE(comparator_.operator()(-10, 10));
96 EXPECT_FALSE(comparator_.operator()(10, -10));
97 EXPECT_TRUE(comparator_.operator()(0, 0x8000));
98 EXPECT_FALSE(comparator_.operator()(0x8000, 0));
99 }
100
101 class LossAccountTest : public ::testing::Test {
102 public:
103 LossAccountTest() {}
104 ~LossAccountTest() {}
105
106 protected:
107 LossAccount loss_account_;
108 };
109
110 TEST_F(LossAccountTest, Operations) {
111 const size_t kTotal = 100; // Arbitrary values.
112 const size_t kLost = 10;
113
114 LossAccount rhs(kTotal, kLost);
115
116 loss_account_.Add(rhs);
117 EXPECT_EQ(loss_account_.num_total, kTotal);
118 EXPECT_EQ(loss_account_.num_lost, kLost);
119 EXPECT_NEAR(loss_account_.LossRatio(), static_cast<float>(kLost) / kTotal,
120 0.001f);
121
122 loss_account_.Subtract(rhs);
123 EXPECT_EQ(loss_account_.num_total, 0UL);
124 EXPECT_EQ(loss_account_.num_lost, 0UL);
125 EXPECT_NEAR(loss_account_.LossRatio(), 0.0f, 0.001f);
126 }
127
128 const int kFlowId = 1; // Arbitrary.
129
130 class BweReceiverTest : public ::testing::Test, public BweReceiver {
stefan-webrtc 2015/07/09 09:55:00 I would prefer to make BweReceiver a member of thi
magalhaesc 2015/07/09 11:20:07 Right, some methods will become public then.
131 public:
132 BweReceiverTest() : BweReceiver(kFlowId) {}
133 ~BweReceiverTest() {}
134 };
135
136 TEST_F(BweReceiverTest, RecentKbps) {
137 EXPECT_EQ(RecentKbps(), 0U);
138
139 const size_t kPacketSizeBytes = 1200;
140 const int kNumPackets = 100;
141
142 double window_size_s = this->window_size_s();
143
144 // Receive packets at the same time.
145 for (int i = 0; i < kNumPackets; ++i) {
146 MediaPacket packet(kFlowId, 0, kPacketSizeBytes, i);
147 ReceivePacket(0, packet);
148 }
149
150 EXPECT_NEAR(
151 RecentKbps(),
152 (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s),
153 (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s * 20));
154
155 int64_t time_gap_ms =
156 2 * 1000 * window_size_s; // Larger than rate_counter time window.
157
158 MediaPacket packet(kFlowId, time_gap_ms, kPacketSizeBytes, kNumPackets);
159 ReceivePacket(time_gap_ms, packet);
160
161 EXPECT_EQ(RecentKbps(),
162 (8 * kPacketSizeBytes) / (1000 * window_size_s));
163 }
164
165 TEST_F(BweReceiverTest, Loss) {
166
167 EXPECT_NEAR(GlobalReceiverPacketLossRatio(), 0.0f, 0.001f);
168
169 LossAccount loss_account = LinkedSetPacketLossRatio();
170 EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f);
171
172 // Insert packets 1-50 and 151-200;
173 for (int i=1; i<=200; ++i){
174 // Packet size and timestamp do not matter here.
175 MediaPacket packet(kFlowId, 0, 0, i);
176 ReceivePacket(0, packet);
177 if (i==50){
178 i += 100;
179 }
180 }
181
182 loss_account = LinkedSetPacketLossRatio();
183 EXPECT_NEAR(loss_account.LossRatio(), 0.5f, 0.001f);
184
185 RelieveSetAndUpdateLoss();
186 EXPECT_EQ(received_packets_.size(), 100U/10);
187
188 // No packet loss within the preserved packets.
189 loss_account = LinkedSetPacketLossRatio();
190 EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f);
191
192 // RelieveSetAndUpdateLoss automatically updates loss account.
193 EXPECT_NEAR(GlobalReceiverPacketLossRatio(), 0.5f, 0.001f);
194 }
195
196 } // namespace bwe
197 } // namespace testing
198 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698