webrtc/modules/congestion_controller/pcc/utility_function_unittest.cc
Jonas Olsson a4d873786f Format almost everything.
This CL was generated by running

git ls-files | grep -P "(\.h|\.cc)$" | grep -v 'sdk/' | grep -v 'rtc_base/ssl_' | \
grep -v 'fake_rtc_certificate_generator.h' | grep -v 'modules/audio_device/win/' | \
grep -v 'system_wrappers/source/clock.cc' | grep -v 'rtc_base/trace_event.h' | \
grep -v 'modules/audio_coding/codecs/ilbc/' | grep -v 'screen_capturer_mac.h' | \
grep -v 'spl_inl_mips.h' | grep -v 'data_size_unittest.cc' | grep -v 'timestamp_unittest.cc' \
| xargs clang-format -i ; git cl format

Most of these changes are clang-format grouping and reordering includes
differently.

Bug: webrtc:9340
Change-Id: Ic83ddbc169bfacd21883e381b5181c3dd4fe8a63
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144051
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28505}
2019-07-08 13:45:15 +00:00

113 lines
4.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/utility_function.h"
#include <stddef.h>
#include <cmath>
#include <type_traits>
#include <vector>
#include "api/transport/network_types.h"
#include "api/units/data_rate.h"
#include "api/units/data_size.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "test/gtest.h"
namespace webrtc {
namespace pcc {
namespace test {
namespace {
constexpr double kLossCoefficient = 11.35;
constexpr double kThroughputPower = 0.9;
constexpr double kThroughputCoefficient = 1;
constexpr double kDelayGradientNegativeBound = 10;
const Timestamp kStartTime = Timestamp::us(0);
const TimeDelta kPacketsDelta = TimeDelta::ms(1);
const TimeDelta kIntervalDuration = TimeDelta::ms(100);
const DataRate kSendingBitrate = DataRate::bps(1000);
const DataSize kDefaultDataSize = DataSize::bytes(100);
const TimeDelta kDefaultDelay = TimeDelta::ms(100);
std::vector<PacketResult> CreatePacketResults(
const std::vector<Timestamp>& packets_send_times,
const std::vector<Timestamp>& packets_received_times = {},
const std::vector<DataSize>& packets_sizes = {}) {
std::vector<PacketResult> packet_results;
PacketResult packet_result;
SentPacket sent_packet;
for (size_t i = 0; i < packets_send_times.size(); ++i) {
sent_packet.send_time = packets_send_times[i];
if (packets_sizes.empty()) {
sent_packet.size = kDefaultDataSize;
} else {
sent_packet.size = packets_sizes[i];
}
packet_result.sent_packet = sent_packet;
if (packets_received_times.empty()) {
packet_result.receive_time = packets_send_times[i] + kDefaultDelay;
} else {
packet_result.receive_time = packets_received_times[i];
}
packet_results.push_back(packet_result);
}
return packet_results;
}
} // namespace
TEST(PccVivaceUtilityFunctionTest,
UtilityIsThroughputTermIfAllRestCoefficientsAreZero) {
VivaceUtilityFunction utility_function(0, 0, kThroughputCoefficient,
kThroughputPower, 0,
kDelayGradientNegativeBound);
PccMonitorInterval monitor_interval(kSendingBitrate, kStartTime,
kIntervalDuration);
monitor_interval.OnPacketsFeedback(CreatePacketResults(
{kStartTime + kPacketsDelta, kStartTime + 2 * kPacketsDelta,
kStartTime + 3 * kPacketsDelta, kStartTime + 2 * kIntervalDuration},
{kStartTime + kPacketsDelta + kDefaultDelay, Timestamp::PlusInfinity(),
kStartTime + kDefaultDelay + 3 * kPacketsDelta,
Timestamp::PlusInfinity()},
{kDefaultDataSize, kDefaultDataSize, kDefaultDataSize,
kDefaultDataSize}));
EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
kThroughputCoefficient *
std::pow(kSendingBitrate.bps(), kThroughputPower));
}
TEST(PccVivaceUtilityFunctionTest,
LossTermIsNonZeroIfLossCoefficientIsNonZero) {
VivaceUtilityFunction utility_function(
0, kLossCoefficient, kThroughputCoefficient, kThroughputPower, 0,
kDelayGradientNegativeBound);
PccMonitorInterval monitor_interval(kSendingBitrate, kStartTime,
kIntervalDuration);
monitor_interval.OnPacketsFeedback(CreatePacketResults(
{kStartTime + kPacketsDelta, kStartTime + 2 * kPacketsDelta,
kStartTime + 5 * kPacketsDelta, kStartTime + 2 * kIntervalDuration},
{kStartTime + kDefaultDelay, Timestamp::PlusInfinity(),
kStartTime + kDefaultDelay, kStartTime + 3 * kIntervalDuration},
{}));
// The second packet was lost.
EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
kThroughputCoefficient *
std::pow(kSendingBitrate.bps(), kThroughputPower) -
kLossCoefficient * kSendingBitrate.bps() *
monitor_interval.GetLossRate());
}
} // namespace test
} // namespace pcc
} // namespace webrtc