• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2018 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 "modules/congestion_controller/pcc/rtt_tracker.h"
12 
13 #include "test/gtest.h"
14 
15 namespace webrtc {
16 namespace pcc {
17 namespace test {
18 namespace {
19 const TimeDelta kInitialRtt = TimeDelta::Micros(10);
20 constexpr double kAlpha = 0.9;
21 const Timestamp kStartTime = Timestamp::Seconds(0);
22 
GetPacketWithRtt(TimeDelta rtt)23 PacketResult GetPacketWithRtt(TimeDelta rtt) {
24   SentPacket packet;
25   packet.send_time = kStartTime;
26   PacketResult packet_result;
27   packet_result.sent_packet = packet;
28   if (rtt.IsFinite()) {
29     packet_result.receive_time = kStartTime + rtt;
30   } else {
31     packet_result.receive_time = Timestamp::PlusInfinity();
32   }
33   return packet_result;
34 }
35 }  // namespace
36 
TEST(PccRttTrackerTest,InitialValue)37 TEST(PccRttTrackerTest, InitialValue) {
38   RttTracker tracker{kInitialRtt, kAlpha};
39   EXPECT_EQ(kInitialRtt, tracker.GetRtt());
40   for (int i = 0; i < 100; ++i) {
41     tracker.OnPacketsFeedback({GetPacketWithRtt(kInitialRtt)},
42                               kStartTime + kInitialRtt);
43   }
44   EXPECT_EQ(kInitialRtt, tracker.GetRtt());
45 }
46 
TEST(PccRttTrackerTest,DoNothingWhenPacketIsLost)47 TEST(PccRttTrackerTest, DoNothingWhenPacketIsLost) {
48   RttTracker tracker{kInitialRtt, kAlpha};
49   tracker.OnPacketsFeedback({GetPacketWithRtt(TimeDelta::PlusInfinity())},
50                             kStartTime + kInitialRtt);
51   EXPECT_EQ(tracker.GetRtt(), kInitialRtt);
52 }
53 
TEST(PccRttTrackerTest,ChangeInRtt)54 TEST(PccRttTrackerTest, ChangeInRtt) {
55   RttTracker tracker{kInitialRtt, kAlpha};
56   const TimeDelta kNewRtt = TimeDelta::Micros(100);
57   tracker.OnPacketsFeedback({GetPacketWithRtt(kNewRtt)}, kStartTime + kNewRtt);
58   EXPECT_GT(tracker.GetRtt(), kInitialRtt);
59   EXPECT_LE(tracker.GetRtt(), kNewRtt);
60   for (int i = 0; i < 100; ++i) {
61     tracker.OnPacketsFeedback({GetPacketWithRtt(kNewRtt)},
62                               kStartTime + kNewRtt);
63   }
64   const TimeDelta absolute_error = TimeDelta::Micros(1);
65   EXPECT_NEAR(tracker.GetRtt().us(), kNewRtt.us(), absolute_error.us());
66   EXPECT_LE(tracker.GetRtt(), kNewRtt);
67 }
68 
69 }  // namespace test
70 }  // namespace pcc
71 }  // namespace webrtc
72