webrtc/modules/congestion_controller/pcc/rtt_tracker_unittest.cc
Danil Chapovalov 5528402ef8 Use newer version of TimeDelta and TimeStamp factories in modules/
This change generated with following commands:
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::Micros<\(.*\)>()/TimeDelta::Micros(\1)/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::Millis<\(.*\)>()/TimeDelta::Millis(\1)/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::Seconds<\(.*\)>()/TimeDelta::Seconds(\1)/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::us/TimeDelta::Micros/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::ms/TimeDelta::Millis/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::seconds/TimeDelta::Seconds/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::Micros<\(.*\)>()/Timestamp::Micros(\1)/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::Millis<\(.*\)>()/Timestamp::Millis(\1)/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::Seconds<\(.*\)>()/Timestamp::Seconds(\1)/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::us/Timestamp::Micros/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::ms/Timestamp::Millis/g"
find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::seconds/Timestamp::Seconds/g"
git cl format

Bug: None
Change-Id: I117d64a54950be040d996035c54bc0043310943a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168340
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30489}
2020-02-10 11:49:57 +00:00

71 lines
2.3 KiB
C++

/*
* Copyright (c) 2018 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 "modules/congestion_controller/pcc/rtt_tracker.h"
#include "test/gtest.h"
namespace webrtc {
namespace pcc {
namespace test {
namespace {
const TimeDelta kInitialRtt = TimeDelta::Micros(10);
constexpr double kAlpha = 0.9;
const Timestamp kStartTime = Timestamp::Seconds(0);
PacketResult GetPacketWithRtt(TimeDelta rtt) {
SentPacket packet;
packet.send_time = kStartTime;
PacketResult packet_result;
packet_result.sent_packet = packet;
if (rtt.IsFinite()) {
packet_result.receive_time = kStartTime + rtt;
} else {
packet_result.receive_time = Timestamp::PlusInfinity();
}
return packet_result;
}
} // namespace
TEST(PccRttTrackerTest, InitialValue) {
RttTracker tracker{kInitialRtt, kAlpha};
EXPECT_EQ(kInitialRtt, tracker.GetRtt());
for (int i = 0; i < 100; ++i) {
tracker.OnPacketsFeedback({GetPacketWithRtt(kInitialRtt)},
kStartTime + kInitialRtt);
}
EXPECT_EQ(kInitialRtt, tracker.GetRtt());
}
TEST(PccRttTrackerTest, DoNothingWhenPacketIsLost) {
RttTracker tracker{kInitialRtt, kAlpha};
tracker.OnPacketsFeedback({GetPacketWithRtt(TimeDelta::PlusInfinity())},
kStartTime + kInitialRtt);
EXPECT_EQ(tracker.GetRtt(), kInitialRtt);
}
TEST(PccRttTrackerTest, ChangeInRtt) {
RttTracker tracker{kInitialRtt, kAlpha};
const TimeDelta kNewRtt = TimeDelta::Micros(100);
tracker.OnPacketsFeedback({GetPacketWithRtt(kNewRtt)}, kStartTime + kNewRtt);
EXPECT_GT(tracker.GetRtt(), kInitialRtt);
EXPECT_LE(tracker.GetRtt(), kNewRtt);
for (int i = 0; i < 100; ++i) {
tracker.OnPacketsFeedback({GetPacketWithRtt(kNewRtt)},
kStartTime + kNewRtt);
}
const TimeDelta absolute_error = TimeDelta::Micros(1);
EXPECT_NEAR(tracker.GetRtt().us(), kNewRtt.us(), absolute_error.us());
EXPECT_LE(tracker.GetRtt(), kNewRtt);
}
} // namespace test
} // namespace pcc
} // namespace webrtc