Chromium Code Reviews| OLD | NEW |
|---|---|
| (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, public BweReceiver { | |
| 133 public: | |
| 134 BweReceiverTest() : BweReceiver(kFlowId) {} | |
| 135 ~BweReceiverTest() {} | |
| 136 }; | |
| 137 | |
| 138 TEST_F(BweReceiverTest, RecentKbps) { | |
| 139 EXPECT_EQ(RecentKbps(), 0U); | |
| 140 | |
| 141 const size_t kPacketSizeBytes = 1200; | |
| 142 const int kNumPackets = 100; | |
| 143 | |
| 144 double window_size_s = this->window_size_s(); | |
| 145 | |
| 146 // Receive packets at the same time. | |
| 147 for (int i = 0; i < kNumPackets; ++i) { | |
| 148 MediaPacket packet(kFlowId, 0L, kPacketSizeBytes, static_cast<uint16_t>(i)); | |
| 149 ReceivePacket(0, packet); | |
| 150 } | |
| 151 | |
| 152 EXPECT_NEAR( | |
| 153 RecentKbps(), | |
| 154 (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s), | |
| 155 (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s * 20)); | |
| 156 | |
| 157 int64_t time_gap_ms = | |
| 158 2 * 1000 * window_size_s; // Larger than rate_counter time window. | |
| 159 | |
| 160 MediaPacket packet(kFlowId, time_gap_ms * 1000, kPacketSizeBytes, | |
| 161 static_cast<uint16_t>(kNumPackets)); | |
| 162 ReceivePacket(time_gap_ms, packet); | |
| 163 | |
| 164 EXPECT_NEAR(RecentKbps(), (8 * kPacketSizeBytes) / (1000 * window_size_s), | |
| 165 (8 * kPacketSizeBytes) / (1000 * window_size_s * 10)); | |
|
stefan-webrtc
2015/07/09 09:55:00
Same here, make this error interval easier to unde
magalhaesc
2015/07/09 11:43:22
Right, I agree
| |
| 166 } | |
| 167 | |
| 168 TEST_F(BweReceiverTest, Loss) { | |
| 169 EXPECT_NEAR(GlobalReceiverPacketLossRatio(), 0.0f, 0.001f); | |
| 170 | |
| 171 LossAccount loss_account = LinkedSetPacketLossRatio(); | |
| 172 EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f); | |
| 173 | |
| 174 // Insert packets 1-50 and 151-200; | |
| 175 for (int i = 1; i <= 200; ++i) { | |
| 176 // Packet size and timestamp do not matter here. | |
| 177 MediaPacket packet(kFlowId, 0L, 0UL, static_cast<uint16_t>(i)); | |
| 178 ReceivePacket(0, packet); | |
| 179 if (i == 50) { | |
| 180 i += 100; | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 loss_account = LinkedSetPacketLossRatio(); | |
| 185 EXPECT_NEAR(loss_account.LossRatio(), 0.5f, 0.001f); | |
| 186 | |
| 187 RelieveSetAndUpdateLoss(); | |
| 188 EXPECT_EQ(received_packets_.size(), 100U / 10); | |
| 189 | |
| 190 // No packet loss within the preserved packets. | |
| 191 loss_account = LinkedSetPacketLossRatio(); | |
| 192 EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f); | |
| 193 | |
| 194 // RelieveSetAndUpdateLoss automatically updates loss account. | |
| 195 EXPECT_NEAR(GlobalReceiverPacketLossRatio(), 0.5f, 0.001f); | |
| 196 } | |
| 197 | |
| 198 } // namespace bwe | |
| 199 } // namespace testing | |
| 200 } // namespace webrtc | |
| OLD | NEW |