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

Unified 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: Removed unused code 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 side-by-side diff with in-line comments
Download patch
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..1b553331747ae67c538411d14f318b3a3127df76
--- /dev/null
+++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_unittest.cc
@@ -0,0 +1,200 @@
+/*
+ * 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 BweReceiver {
+ public:
+ BweReceiverTest() : BweReceiver(kFlowId) {}
+ ~BweReceiverTest() {}
+};
+
+TEST_F(BweReceiverTest, RecentKbps) {
+ EXPECT_EQ(RecentKbps(), 0U);
+
+ const size_t kPacketSizeBytes = 1200;
+ const int kNumPackets = 100;
+
+ double window_size_s = this->window_size_s();
+
+ // Receive packets at the same time.
+ for (int i = 0; i < kNumPackets; ++i) {
+ MediaPacket packet(kFlowId, 0L, kPacketSizeBytes, static_cast<uint16_t>(i));
+ ReceivePacket(0, packet);
+ }
+
+ EXPECT_NEAR(
+ RecentKbps(),
+ (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s),
+ (8 * kNumPackets * kPacketSizeBytes) / (1000 * window_size_s * 20));
+
+ 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));
+ ReceivePacket(time_gap_ms, packet);
+
+ EXPECT_NEAR(RecentKbps(), (8 * kPacketSizeBytes) / (1000 * window_size_s),
+ (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
+}
+
+TEST_F(BweReceiverTest, Loss) {
+ EXPECT_NEAR(GlobalReceiverPacketLossRatio(), 0.0f, 0.001f);
+
+ LossAccount loss_account = 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));
+ ReceivePacket(0, packet);
+ if (i == 50) {
+ i += 100;
+ }
+ }
+
+ loss_account = LinkedSetPacketLossRatio();
+ EXPECT_NEAR(loss_account.LossRatio(), 0.5f, 0.001f);
+
+ RelieveSetAndUpdateLoss();
+ EXPECT_EQ(received_packets_.size(), 100U / 10);
+
+ // No packet loss within the preserved packets.
+ loss_account = LinkedSetPacketLossRatio();
+ EXPECT_NEAR(loss_account.LossRatio(), 0.0f, 0.001f);
+
+ // RelieveSetAndUpdateLoss automatically updates loss account.
+ EXPECT_NEAR(GlobalReceiverPacketLossRatio(), 0.5f, 0.001f);
+}
+
+} // namespace bwe
+} // namespace testing
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698