| Index: webrtc/modules/remote_bitrate_estimator/test/bwe_unittest.cc
|
| diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe_unittest.cc b/webrtc/modules/remote_bitrate_estimator/test/bwe_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fc6e3e20848dfce6e3606cf551310c714b215cf6
|
| --- /dev/null
|
| +++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_unittest.cc
|
| @@ -0,0 +1,202 @@
|
| +/*
|
| + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license
|
| + * that can be found in the LICENSE file in the root of the source
|
| + * tree. An additional intellectual property rights grant can be found
|
| + * in the file PATENTS. All contributing project authors may
|
| + * be found in the AUTHORS file in the root of the source tree.
|
| + */
|
| +
|
| +#include "webrtc/modules/remote_bitrate_estimator/test/bwe.h"
|
| +
|
| +#include <vector>
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace webrtc {
|
| +namespace testing {
|
| +namespace bwe {
|
| +
|
| +const int kSetCapacity = 10000;
|
| +
|
| +class LinkedSetTest : public ::testing::Test {
|
| + public:
|
| + LinkedSetTest() : linked_set_(kSetCapacity) {}
|
| +
|
| + ~LinkedSetTest() {}
|
| +
|
| + protected:
|
| + LinkedSet linked_set_;
|
| +};
|
| +
|
| +TEST_F(LinkedSetTest, EmptySet) {
|
| + EXPECT_EQ(linked_set_.OldestSeqNumber(), 0);
|
| + EXPECT_EQ(linked_set_.NewestSeqNumber(), 0);
|
| +}
|
| +
|
| +TEST_F(LinkedSetTest, SinglePacket) {
|
| + const uint16_t kSeqNumber = 1; // Arbitrary.
|
| + // Other parameters don't matter here.
|
| + linked_set_.Insert(kSeqNumber, 0, 0, 0);
|
| +
|
| + EXPECT_EQ(linked_set_.OldestSeqNumber(), kSeqNumber);
|
| + EXPECT_EQ(linked_set_.NewestSeqNumber(), kSeqNumber);
|
| +}
|
| +
|
| +TEST_F(LinkedSetTest, MultiplePackets) {
|
| + const uint16_t kNumberPackets = 100;
|
| +
|
| + std::vector<uint16_t> sequence_numbers;
|
| + for (size_t i = 0; i < kNumberPackets; ++i) {
|
| + sequence_numbers.push_back(static_cast<uint16_t>(i + 1));
|
| + }
|
| + random_shuffle(sequence_numbers.begin(), sequence_numbers.end());
|
| +
|
| + for (size_t i = 0; i < kNumberPackets; ++i) {
|
| + // Other parameters don't matter here.
|
| + linked_set_.Insert(static_cast<uint16_t>(i), 0, 0, 0);
|
| + }
|
| +
|
| + // Packets arriving out of order should not affect the following values:
|
| + EXPECT_EQ(linked_set_.OldestSeqNumber(), 0);
|
| + EXPECT_EQ(linked_set_.NewestSeqNumber(), kNumberPackets - 1);
|
| +}
|
| +
|
| +TEST_F(LinkedSetTest, Overflow) {
|
| + const int kFirstSeqNumber = -100;
|
| + const int kLastSeqNumber = 100;
|
| +
|
| + for (int i = kFirstSeqNumber; i <= kLastSeqNumber; ++i) {
|
| + // Other parameters don't matter here.
|
| + linked_set_.Insert(static_cast<uint16_t>(i), 0, 0, 0);
|
| + }
|
| +
|
| + // Packets arriving out of order should not affect the following values:
|
| + EXPECT_EQ(linked_set_.OldestSeqNumber(),
|
| + static_cast<uint16_t>(kFirstSeqNumber));
|
| + EXPECT_EQ(linked_set_.NewestSeqNumber(),
|
| + static_cast<uint16_t>(kLastSeqNumber));
|
| +}
|
| +
|
| +class SequenceNumberOlderThanTest : public ::testing::Test {
|
| + public:
|
| + SequenceNumberOlderThanTest() {}
|
| + ~SequenceNumberOlderThanTest() {}
|
| +
|
| + protected:
|
| + SequenceNumberOlderThan comparator_;
|
| +};
|
| +
|
| +TEST_F(SequenceNumberOlderThanTest, Operator) {
|
| + // Operator()(x, y) returns true <==> y is newer than x.
|
| + EXPECT_TRUE(comparator_.operator()(0x0000, 0x0001));
|
| + EXPECT_TRUE(comparator_.operator()(0x0001, 0x1000));
|
| + EXPECT_FALSE(comparator_.operator()(0x0001, 0x0000));
|
| + EXPECT_FALSE(comparator_.operator()(0x0002, 0x0002));
|
| + EXPECT_TRUE(comparator_.operator()(0xFFF6, 0x000A));
|
| + EXPECT_FALSE(comparator_.operator()(0x000A, 0xFFF6));
|
| + EXPECT_TRUE(comparator_.operator()(0x0000, 0x8000));
|
| + EXPECT_FALSE(comparator_.operator()(0x8000, 0x0000));
|
| +}
|
| +
|
| +class LossAccountTest : public ::testing::Test {
|
| + public:
|
| + LossAccountTest() {}
|
| + ~LossAccountTest() {}
|
| +
|
| + protected:
|
| + LossAccount loss_account_;
|
| +};
|
| +
|
| +TEST_F(LossAccountTest, Operations) {
|
| + const size_t kTotal = 100; // Arbitrary values.
|
| + const size_t kLost = 10;
|
| +
|
| + LossAccount rhs(kTotal, kLost);
|
| +
|
| + loss_account_.Add(rhs);
|
| + EXPECT_EQ(loss_account_.num_total, kTotal);
|
| + EXPECT_EQ(loss_account_.num_lost, kLost);
|
| + EXPECT_NEAR(loss_account_.LossRatio(), static_cast<float>(kLost) / kTotal,
|
| + 0.001f);
|
| +
|
| + loss_account_.Subtract(rhs);
|
| + EXPECT_EQ(loss_account_.num_total, 0UL);
|
| + EXPECT_EQ(loss_account_.num_lost, 0UL);
|
| + EXPECT_NEAR(loss_account_.LossRatio(), 0.0f, 0.001f);
|
| +}
|
| +
|
| +const int kFlowId = 1; // Arbitrary.
|
| +
|
| +class BweReceiverTest : public ::testing::Test {
|
| + public:
|
| + BweReceiverTest() : bwe_receiver_(kFlowId) {}
|
| + ~BweReceiverTest() {}
|
| +
|
| + protected:
|
| + BweReceiver bwe_receiver_;
|
| +};
|
| +
|
| +TEST_F(BweReceiverTest, RecentKbps) {
|
| + EXPECT_EQ(bwe_receiver_.RecentKbps(), 0U);
|
| +
|
| + const size_t kPacketSizeBytes = 1200;
|
| + const int kNumPackets = 100;
|
| +
|
| + double window_size_s = bwe_receiver_.BitrateWindowS();
|
| +
|
| + // Receive packets at the same time.
|
| + for (int i = 0; i < kNumPackets; ++i) {
|
| + MediaPacket packet(kFlowId, 0L, kPacketSizeBytes, static_cast<uint16_t>(i));
|
| + bwe_receiver_.ReceivePacket(0, packet);
|
| + }
|
| +
|
| + EXPECT_NEAR(bwe_receiver_.RecentKbps(),
|
| + (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s),
|
| + 10);
|
| +
|
| + int64_t time_gap_ms =
|
| + 2 * 1000 * window_size_s; // Larger than rate_counter time window.
|
| +
|
| + MediaPacket packet(kFlowId, time_gap_ms * 1000, kPacketSizeBytes,
|
| + static_cast<uint16_t>(kNumPackets));
|
| + bwe_receiver_.ReceivePacket(time_gap_ms, packet);
|
| +
|
| + EXPECT_NEAR(bwe_receiver_.RecentKbps(),
|
| + (8 * kPacketSizeBytes) / (1000 * window_size_s), 10);
|
| +}
|
| +
|
| +TEST_F(BweReceiverTest, Loss) {
|
| + EXPECT_NEAR(bwe_receiver_.GlobalReceiverPacketLossRatio(), 0.0f, 0.001f);
|
| +
|
| + LossAccount loss_account = bwe_receiver_.LinkedSetPacketLossRatio();
|
| + EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f);
|
| +
|
| + // Insert packets 1-50 and 151-200;
|
| + for (int i = 1; i <= 200; ++i) {
|
| + // Packet size and timestamp do not matter here.
|
| + MediaPacket packet(kFlowId, 0L, 0UL, static_cast<uint16_t>(i));
|
| + bwe_receiver_.ReceivePacket(0, packet);
|
| + if (i == 50) {
|
| + i += 100;
|
| + }
|
| + }
|
| +
|
| + loss_account = bwe_receiver_.LinkedSetPacketLossRatio();
|
| + EXPECT_NEAR(loss_account.LossRatio(), 0.5f, 0.001f);
|
| +
|
| + bwe_receiver_.RelieveSetAndUpdateLoss();
|
| + EXPECT_EQ(bwe_receiver_.received_packets_.size(), 100U / 10);
|
| +
|
| + // No packet loss within the preserved packets.
|
| + loss_account = bwe_receiver_.LinkedSetPacketLossRatio();
|
| + EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f);
|
| +
|
| + // RelieveSetAndUpdateLoss automatically updates loss account.
|
| + EXPECT_NEAR(bwe_receiver_.GlobalReceiverPacketLossRatio(), 0.5f, 0.001f);
|
| +}
|
| +
|
| +} // namespace bwe
|
| +} // namespace testing
|
| +} // namespace webrtc
|
|
|