Generalize NetworkQualityMetricsReporter to support multiple peers in test

Bug: webrtc:11479
Change-Id: I80a6633b0edbb02274aff1f3a596908ee6a7497e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/177008
Reviewed-by: Andrey Logvin <landrey@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31506}
This commit is contained in:
Artem Titov
2020-06-11 17:01:39 +02:00
committed by Commit Bot
parent 4c1e7cc19b
commit 33c0c342f6
2 changed files with 32 additions and 16 deletions

View File

@ -28,15 +28,22 @@ constexpr int kStatsWaitTimeoutMs = 1000;
constexpr char kUseStandardBytesStats[] = "WebRTC-UseStandardBytesStats";
}
NetworkQualityMetricsReporter::NetworkQualityMetricsReporter(
EmulatedNetworkManagerInterface* alice_network,
EmulatedNetworkManagerInterface* bob_network)
: networks_by_peer_({{"alice", alice_network}, {"bob", bob_network}}) {}
void NetworkQualityMetricsReporter::Start(absl::string_view test_case_name) {
test_case_name_ = std::string(test_case_name);
// Check that network stats are clean before test execution.
EmulatedNetworkStats alice_stats = PopulateStats(alice_network_);
RTC_CHECK_EQ(alice_stats.packets_sent, 0);
RTC_CHECK_EQ(alice_stats.packets_received, 0);
EmulatedNetworkStats bob_stats = PopulateStats(bob_network_);
RTC_CHECK_EQ(bob_stats.packets_sent, 0);
RTC_CHECK_EQ(bob_stats.packets_received, 0);
for (const auto& entry : networks_by_peer_) {
EmulatedNetworkStats stats = PopulateStats(entry.second);
RTC_CHECK_EQ(stats.packets_sent, 0)
<< "|packets_sent| for " << entry.first << " have to be 0 before test";
RTC_CHECK_EQ(stats.packets_received, 0)
<< "|packets_received| for " << entry.first
<< " have to be 0 before test";
}
}
void NetworkQualityMetricsReporter::OnStatsReports(
@ -65,12 +72,11 @@ void NetworkQualityMetricsReporter::OnStatsReports(
}
void NetworkQualityMetricsReporter::StopAndReportResults() {
EmulatedNetworkStats alice_stats = PopulateStats(alice_network_);
EmulatedNetworkStats bob_stats = PopulateStats(bob_network_);
ReportStats("alice", alice_stats,
alice_stats.packets_sent - bob_stats.packets_received);
ReportStats("bob", bob_stats,
bob_stats.packets_sent - alice_stats.packets_received);
for (const auto& entry : networks_by_peer_) {
EmulatedNetworkStats stats = PopulateStats(entry.second);
ReportStats(entry.first, stats,
stats.packets_sent - stats.packets_received);
}
if (!webrtc::field_trial::IsEnabled(kUseStandardBytesStats)) {
RTC_LOG(LS_ERROR)

View File

@ -11,6 +11,7 @@
#ifndef TEST_PC_E2E_NETWORK_QUALITY_METRICS_REPORTER_H_
#define TEST_PC_E2E_NETWORK_QUALITY_METRICS_REPORTER_H_
#include <map>
#include <string>
#include "api/test/network_emulation_manager.h"
@ -23,9 +24,19 @@ namespace webrtc_pc_e2e {
class NetworkQualityMetricsReporter
: public PeerConnectionE2EQualityTestFixture::QualityMetricsReporter {
public:
// Creates a network quality metrics reporter on specified
// EmulatedNetworkManagerInterface instances index by the labels. These labels
// will be used as prefix for the metric name.
// Instances of |EmulatedNetworkManagerInterface*| have to outlive
// NetworkQualityMetricsReporter.
explicit NetworkQualityMetricsReporter(
std::map<std::string, EmulatedNetworkManagerInterface*> networks_by_peer)
: networks_by_peer_(std::move(networks_by_peer)) {}
// Creates a network quality metrics reporter on specified for two network
// which will be labeled "alice" and "bob" respectively. Bot |alice_network|
// and |bob_network| have to outlive NetworkQualityMetricsReporter.
NetworkQualityMetricsReporter(EmulatedNetworkManagerInterface* alice_network,
EmulatedNetworkManagerInterface* bob_network)
: alice_network_(alice_network), bob_network_(bob_network) {}
EmulatedNetworkManagerInterface* bob_network);
~NetworkQualityMetricsReporter() override = default;
// Network stats must be empty when this method will be invoked.
@ -56,8 +67,7 @@ class NetworkQualityMetricsReporter
std::string test_case_name_;
EmulatedNetworkManagerInterface* alice_network_;
EmulatedNetworkManagerInterface* bob_network_;
std::map<std::string, EmulatedNetworkManagerInterface*> networks_by_peer_;
rtc::CriticalSection lock_;
std::map<std::string, PCStats> pc_stats_ RTC_GUARDED_BY(lock_);
};