1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
/*
* Copyright 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 "pc/rtc_stats_traversal.h"
#include <memory>
#include <string>
#include <vector>
#include "api/scoped_refptr.h"
#include "api/stats/rtc_stats.h"
#include "api/stats/rtc_stats_report.h"
#include "api/stats/rtcstats_objects.h"
#include "api/units/timestamp.h"
#include "test/gtest.h"
// This file contains tests for TakeReferencedStats().
// GetStatsNeighborIds() is tested in rtcstats_integrationtest.cc.
namespace webrtc {
class RTCStatsTraversalTest : public ::testing::Test {
public:
RTCStatsTraversalTest() {
transport_ = new RTCTransportStats("transport", Timestamp::Zero());
candidate_pair_ =
new RTCIceCandidatePairStats("candidate-pair", Timestamp::Zero());
local_candidate_ =
new RTCLocalIceCandidateStats("local-candidate", Timestamp::Zero());
remote_candidate_ =
new RTCRemoteIceCandidateStats("remote-candidate", Timestamp::Zero());
initial_report_ = RTCStatsReport::Create(Timestamp::Zero());
initial_report_->AddStats(std::unique_ptr<const RTCStats>(transport_));
initial_report_->AddStats(std::unique_ptr<const RTCStats>(candidate_pair_));
initial_report_->AddStats(
std::unique_ptr<const RTCStats>(local_candidate_));
initial_report_->AddStats(
std::unique_ptr<const RTCStats>(remote_candidate_));
result_ = RTCStatsReport::Create(Timestamp::Zero());
}
void TakeReferencedStats(std::vector<const RTCStats*> start_nodes) {
std::vector<std::string> start_ids;
start_ids.reserve(start_nodes.size());
for (const RTCStats* start_node : start_nodes) {
start_ids.push_back(start_node->id());
}
result_ = ::webrtc::TakeReferencedStats(initial_report_, start_ids);
}
void EXPECT_VISITED(const RTCStats* stats) {
EXPECT_FALSE(initial_report_->Get(stats->id()))
<< '"' << stats->id()
<< "\" should be visited but it was not removed from initial report.";
EXPECT_TRUE(result_->Get(stats->id()))
<< '"' << stats->id()
<< "\" should be visited but it was not added to the resulting report.";
}
void EXPECT_UNVISITED(const RTCStats* stats) {
EXPECT_TRUE(initial_report_->Get(stats->id()))
<< '"' << stats->id()
<< "\" should not be visited but it was removed from initial report.";
EXPECT_FALSE(result_->Get(stats->id()))
<< '"' << stats->id()
<< "\" should not be visited but it was added to the resulting report.";
}
protected:
scoped_refptr<RTCStatsReport> initial_report_;
scoped_refptr<RTCStatsReport> result_;
// Raw pointers to stats owned by the reports.
RTCTransportStats* transport_;
RTCIceCandidatePairStats* candidate_pair_;
RTCIceCandidateStats* local_candidate_;
RTCIceCandidateStats* remote_candidate_;
};
TEST_F(RTCStatsTraversalTest, NoReachableConnections) {
// Everything references transport but transport doesn't reference anything.
//
// candidate-pair
// | | |
// v | v
// local-candidate | remote-candidate
// | | |
// v v v
// start:transport
candidate_pair_->transport_id = "transport";
candidate_pair_->local_candidate_id = "local-candidate";
candidate_pair_->remote_candidate_id = "remote-candidate";
local_candidate_->transport_id = "transport";
remote_candidate_->transport_id = "transport";
TakeReferencedStats({transport_});
EXPECT_VISITED(transport_);
EXPECT_UNVISITED(candidate_pair_);
EXPECT_UNVISITED(local_candidate_);
EXPECT_UNVISITED(remote_candidate_);
}
TEST_F(RTCStatsTraversalTest, SelfReference) {
transport_->rtcp_transport_stats_id = "transport";
TakeReferencedStats({transport_});
EXPECT_VISITED(transport_);
EXPECT_UNVISITED(candidate_pair_);
EXPECT_UNVISITED(local_candidate_);
EXPECT_UNVISITED(remote_candidate_);
}
TEST_F(RTCStatsTraversalTest, BogusReference) {
transport_->rtcp_transport_stats_id = "bogus-reference";
TakeReferencedStats({transport_});
EXPECT_VISITED(transport_);
EXPECT_UNVISITED(candidate_pair_);
EXPECT_UNVISITED(local_candidate_);
EXPECT_UNVISITED(remote_candidate_);
}
TEST_F(RTCStatsTraversalTest, Tree) {
// start:candidate-pair
// | |
// v v
// local-candidate remote-candidate
// |
// v
// transport
candidate_pair_->local_candidate_id = "local-candidate";
candidate_pair_->remote_candidate_id = "remote-candidate";
local_candidate_->transport_id = "transport";
TakeReferencedStats({candidate_pair_});
EXPECT_VISITED(transport_);
EXPECT_VISITED(candidate_pair_);
EXPECT_VISITED(local_candidate_);
EXPECT_VISITED(remote_candidate_);
}
TEST_F(RTCStatsTraversalTest, MultiplePathsToSameNode) {
// start:candidate-pair
// | |
// v v
// local-candidate remote-candidate
// | |
// v v
// transport
candidate_pair_->local_candidate_id = "local-candidate";
candidate_pair_->remote_candidate_id = "remote-candidate";
local_candidate_->transport_id = "transport";
remote_candidate_->transport_id = "transport";
TakeReferencedStats({candidate_pair_});
EXPECT_VISITED(transport_);
EXPECT_VISITED(candidate_pair_);
EXPECT_VISITED(local_candidate_);
EXPECT_VISITED(remote_candidate_);
}
TEST_F(RTCStatsTraversalTest, CyclicGraph) {
// candidate-pair
// | ^
// v |
// start:local-candidate | remote-candidate
// | |
// v |
// transport
local_candidate_->transport_id = "transport";
transport_->selected_candidate_pair_id = "candidate-pair";
candidate_pair_->local_candidate_id = "local-candidate";
TakeReferencedStats({local_candidate_});
EXPECT_VISITED(transport_);
EXPECT_VISITED(candidate_pair_);
EXPECT_VISITED(local_candidate_);
EXPECT_UNVISITED(remote_candidate_);
}
TEST_F(RTCStatsTraversalTest, MultipleStarts) {
// start:candidate-pair
// |
// v
// local-candidate remote-candidate
// |
// v
// start:transport
candidate_pair_->remote_candidate_id = "remote-candidate";
local_candidate_->transport_id = "transport";
TakeReferencedStats({candidate_pair_, transport_});
EXPECT_VISITED(transport_);
EXPECT_VISITED(candidate_pair_);
EXPECT_UNVISITED(local_candidate_);
EXPECT_VISITED(remote_candidate_);
}
TEST_F(RTCStatsTraversalTest, MultipleStartsLeadingToSameNode) {
// candidate-pair
//
//
// start:local-candidate start:remote-candidate
// | |
// v v
// transport
local_candidate_->transport_id = "transport";
remote_candidate_->transport_id = "transport";
TakeReferencedStats({local_candidate_, remote_candidate_});
EXPECT_VISITED(transport_);
EXPECT_UNVISITED(candidate_pair_);
EXPECT_VISITED(local_candidate_);
EXPECT_VISITED(remote_candidate_);
}
} // namespace webrtc
|